Skip to content

feat: add UI size slider to settings#3524

Open
IgnazioDS wants to merge 1 commit intoopenfrontio:mainfrom
IgnazioDS:feat/ui-size-slider
Open

feat: add UI size slider to settings#3524
IgnazioDS wants to merge 1 commit intoopenfrontio:mainfrom
IgnazioDS:feat/ui-size-slider

Conversation

@IgnazioDS
Copy link
Copy Markdown

Summary

Adds a UI scale slider (50%-200%) to the in-game settings panel, allowing players to adjust the interface size. Addresses the issue where UI looks bad with OS scaling at 125% or on mobile/ultrawide screens.

How It Works

  • CSS zoom on document.documentElement — reflows layout correctly (unlike transform: scale)
  • Persisted in localStorage — setting survives page refresh
  • Applied on page load — no flash of wrong-size UI
  • Clamped 50-200% with 10% steps — prevents unusable extremes

Files Changed

File Change
UserSettings.ts uiScale(), setUiScale(), applyUiScale() methods
SettingsModal.ts Range slider UI (follows existing volume slider pattern)
Main.ts Apply saved scale on initialization
en.json "UI Scale" translation key

Screenshots

The slider follows the exact same pattern as the existing Music/SFX volume sliders — consistent UX, no new dependencies.

Test Plan

  • Default scale is 100% (no visual change for existing players)
  • Moving slider updates UI immediately
  • Setting persists across page refresh
  • Extremes (50%, 200%) are usable
  • Game canvas rendering is unaffected (PixiJS uses its own transform)
  • Works on mobile and desktop

Closes #3067

Add a UI scale slider (50%-200%) to the in-game settings panel,
allowing players to adjust the interface size regardless of their
OS scaling, browser zoom, or screen type (mobile, ultrawide, etc.).

Implementation:
- UserSettings: uiScale()/setUiScale()/applyUiScale() with
  localStorage persistence and clamping to 50-200 range
- SettingsModal: range input slider following the existing volume
  slider pattern, placed after the audio settings
- Main.ts: apply saved scale on page load
- en.json: translation key for the label

Uses CSS zoom on the root element for proper layout reflow.

Closes openfrontio#3067
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 27, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

Walkthrough

A UI scaling feature is introduced, allowing users to adjust interface size from 50% to 200% via a settings slider. The implementation includes persistent storage, localized UI labels, initialization during app startup, and DOM zoom manipulation to scale the entire interface.

Changes

Cohort / File(s) Summary
Translation Support
resources/lang/en.json
Added English translation key user_setting.ui_scale_label for the UI scale settings label.
Core UI Scaling Logic
src/core/game/UserSettings.ts
Implemented uiScale() getter, setUiScale(scale) setter with clamping to [50, 200], and applyUiScale(scale?) method that updates document.documentElement.style.zoom for browser environments.
Settings UI Component
src/client/graphics/layers/SettingsModal.ts
Added range input slider (min 50, max 200, step 10) with onUiScaleChange() event handler to update and persist UI scale, plus percentage display.
Application Initialization
src/client/Main.ts
Integrated userSettings.applyUiScale() call during client initialization, positioning it after SDK init and before token prefetch.

Sequence Diagrams

sequenceDiagram
    participant Client
    participant UserSettings
    participant Browser
    
    Client->>UserSettings: applyUiScale()
    activate UserSettings
    UserSettings->>UserSettings: read uiScale (default 100)
    UserSettings->>Browser: document.documentElement.style.zoom = "1.0"
    deactivate UserSettings
    Note over Browser: UI renders at 100% scale
Loading
sequenceDiagram
    participant User
    participant SettingsModal
    participant UserSettings
    participant Storage
    participant Browser
    
    User->>SettingsModal: adjust range slider
    SettingsModal->>SettingsModal: onUiScaleChange()
    SettingsModal->>UserSettings: setUiScale(75)
    activate UserSettings
    UserSettings->>UserSettings: clamp to [50, 200]
    UserSettings->>Storage: persist value
    UserSettings->>Browser: apply zoom = "0.75"
    deactivate UserSettings
    Note over Browser: UI scales to 75%
    SettingsModal->>SettingsModal: requestUpdate()
    SettingsModal->>User: display "75%"
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🔍 A slider tames the giant pixels,
Fifty percent or double bright,
No more squinting at the crystals—
Users zoom to their delight! 📏✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add UI size slider to settings' directly and clearly describes the main feature addition across all changed files.
Description check ✅ Passed The description provides comprehensive context about the UI scale feature, implementation approach, files changed, and test plan, all directly related to the changeset.
Linked Issues check ✅ Passed The PR successfully implements all requirements from #3067: adds a UI size slider (50%-200%) to settings with persistence, clamping, and support for desktop/mobile platforms.
Out of Scope Changes check ✅ Passed All changes are focused on implementing the UI scale slider feature; no unrelated modifications to other functionality are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/core/game/UserSettings.ts`:
- Around line 269-284: Normalize UI scale in one place and ensure both setting
and applying use it: create or use a single normalization step (e.g.,
normalizeUiScale(value?: number)) that ensures the value is finite, defaults to
the stored uiScale(), clamps to [50,200], and snaps to 10% steps (round to
nearest 10), then use that normalized value in setUiScale (before
setFloat/applyUiScale) and in applyUiScale (call normalizeUiScale() instead of
using raw scale or uiScale()), and ensure getFloat/setFloat still receive only
the normalized number for "settings.uiScale".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dc210491-5b9a-462b-8791-f52c1212e273

📥 Commits

Reviewing files that changed from the base of the PR and between 217a2c4 and e9bc7e0.

📒 Files selected for processing (4)
  • resources/lang/en.json
  • src/client/Main.ts
  • src/client/graphics/layers/SettingsModal.ts
  • src/core/game/UserSettings.ts

Comment on lines +269 to +284
uiScale(): number {
return this.getFloat("settings.uiScale", 100);
}

setUiScale(scale: number): void {
const clamped = Math.max(50, Math.min(200, scale));
this.setFloat("settings.uiScale", clamped);
this.applyUiScale(clamped);
}

applyUiScale(scale?: number): void {
const value = scale ?? this.uiScale();
if (typeof document !== "undefined") {
document.documentElement.style.zoom = (value / 100).toString();
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Enforce UI scale normalization in one place (finite + step + clamp).

At Line 274, Math.max/Math.min does not protect against NaN, and step normalization (10%) is not enforced. At Line 280-283, unnormalized values are applied directly to zoom. This can persist/apply invalid values and break scaling state.

💡 Proposed fix
+  private normalizeUiScale(scale: number): number {
+    if (!Number.isFinite(scale)) return 100;
+    const stepped = Math.round(scale / 10) * 10;
+    return Math.max(50, Math.min(200, stepped));
+  }
+
   uiScale(): number {
-    return this.getFloat("settings.uiScale", 100);
+    return this.normalizeUiScale(this.getFloat("settings.uiScale", 100));
   }
 
   setUiScale(scale: number): void {
-    const clamped = Math.max(50, Math.min(200, scale));
-    this.setFloat("settings.uiScale", clamped);
-    this.applyUiScale(clamped);
+    const normalized = this.normalizeUiScale(scale);
+    this.setFloat("settings.uiScale", normalized);
+    this.applyUiScale(normalized);
   }
 
   applyUiScale(scale?: number): void {
-    const value = scale ?? this.uiScale();
+    const value = this.normalizeUiScale(scale ?? this.uiScale());
     if (typeof document !== "undefined") {
       document.documentElement.style.zoom = (value / 100).toString();
     }
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/core/game/UserSettings.ts` around lines 269 - 284, Normalize UI scale in
one place and ensure both setting and applying use it: create or use a single
normalization step (e.g., normalizeUiScale(value?: number)) that ensures the
value is finite, defaults to the stored uiScale(), clamps to [50,200], and snaps
to 10% steps (round to nearest 10), then use that normalized value in setUiScale
(before setFloat/applyUiScale) and in applyUiScale (call normalizeUiScale()
instead of using raw scale or uiScale()), and ensure getFloat/setFloat still
receive only the normalized number for "settings.uiScale".

@github-project-automation github-project-automation bot moved this from Triage to Development in OpenFront Release Management Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Development

Development

Successfully merging this pull request may close these issues.

Feature: UI size slider

2 participants