feat(engine): UI scale setting — 90/100/115/130% (Phase K)
Settings -> Accessibility gains a UI Scale row cycling four steps, applied live through bevy::ui::UiScale: every menu, modal, and HUD element scales while the table itself stays window-fit via compute_layout. New Settings::ui_scale (serde default 1.0, sanitized clamp to [0.9, 1.3]). Safe-area anchors and modal scrim padding pre-divide physical insets by the UI scale so post-multiplication lands exactly on the system bars — without this, 90% would sink the bottom action bar into the Android gesture zone. The anchor systems also re-run on UiScale changes, not just inset changes. Deferred from Phase K (noted in the doc): seeding the setting from the Android system font scale on first run (needs JNI), and the 44px touch-target audit (on-device). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -515,6 +515,58 @@ pub(super) fn touch_input_mode_label(mode: &solitaire_data::settings::TouchInput
|
||||
}
|
||||
}
|
||||
|
||||
/// The four UI-scale steps the settings row cycles through (Phase K).
|
||||
pub(super) const UI_SCALE_STEPS: [f32; 4] = [0.9, 1.0, 1.15, 1.3];
|
||||
|
||||
/// The next UI-scale step after `current`, wrapping 130 % → 90 %. A
|
||||
/// hand-edited value between steps advances to the first step larger
|
||||
/// than it, so the cycle always makes visible progress.
|
||||
pub(super) fn next_ui_scale(current: f32) -> f32 {
|
||||
for step in UI_SCALE_STEPS {
|
||||
if step > current + 0.001 {
|
||||
return step;
|
||||
}
|
||||
}
|
||||
UI_SCALE_STEPS[0]
|
||||
}
|
||||
|
||||
/// Display string for the UI-scale row, e.g. `"115%"`.
|
||||
pub(super) fn ui_scale_label(scale: f32) -> String {
|
||||
format!("{:.0}%", scale * 100.0)
|
||||
}
|
||||
|
||||
/// Refreshes the live UI-scale value text whenever settings change.
|
||||
pub(super) fn update_ui_scale_text(
|
||||
settings: Res<SettingsResource>,
|
||||
mut text_nodes: Query<&mut Text, With<UiScaleText>>,
|
||||
) {
|
||||
if !settings.is_changed() {
|
||||
return;
|
||||
}
|
||||
for mut text in &mut text_nodes {
|
||||
**text = ui_scale_label(settings.0.ui_scale);
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies `Settings::ui_scale` to the live [`bevy::ui::UiScale`]
|
||||
/// resource — at startup (first change tick) and whenever the setting
|
||||
/// changes. Absent under `MinimalPlugins` (no `bevy_ui`), hence the
|
||||
/// `Option`; the table is unaffected either way (`compute_layout`
|
||||
/// owns world-space sizing, not UI scale).
|
||||
pub(super) fn sync_ui_scale_resource(
|
||||
settings: Res<SettingsResource>,
|
||||
ui_scale: Option<ResMut<UiScale>>,
|
||||
) {
|
||||
let Some(mut ui_scale) = ui_scale else { return };
|
||||
if !settings.is_changed() {
|
||||
return;
|
||||
}
|
||||
let target = settings.0.ui_scale;
|
||||
if (ui_scale.0 - target).abs() > f32::EPSILON {
|
||||
ui_scale.0 = target;
|
||||
}
|
||||
}
|
||||
|
||||
/// Display string for the "Smart window size" toggle. The argument
|
||||
/// is the *enabled* state (i.e. the inverse of the underlying
|
||||
/// `disable_smart_default_size` field) so reading the label gives
|
||||
|
||||
Reference in New Issue
Block a user