Merge pull request #705 from tylerjenningsw/enhance/custom-ui-scale
Settings: allow custom UI scale percentages (#682)
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
//! registers its automation ids; the Footage panel's buttons edit into the comp; the Progress
|
||||
//! panel lists and cancels a job; Lumetri Scopes switch scope through their dropdown.
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use std::sync::Arc;
|
||||
|
||||
use effectcraft_engine::{Session, config::MemoryConfig};
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use effectcraft_ui_egui::dock::PanelKind;
|
||||
use egui::{Event, Pos2, pos2};
|
||||
@@ -237,46 +239,147 @@ fn leaving_the_learn_workspace_closes_its_tutorials() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #284: Settings ▸ Appearance ▸ UI Scale sizes the whole interface as soon as it is chosen,
|
||||
/// Cancel puts it back, OK keeps it; Ctrl+0 (Window ▸ Project) doesn't reset it.
|
||||
fn open_settings(h: &mut Harness<'_, EffectcraftApp>) {
|
||||
let ctx = h.ctx.clone();
|
||||
effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "app.settings", json!({"page": "appearance"})).unwrap();
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn key(h: &mut Harness<'_, EffectcraftApp>, key: egui::Key, modifiers: egui::Modifiers) {
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(Event::Key { key, physical_key: None, pressed, repeat: false, modifiers });
|
||||
h.step();
|
||||
}
|
||||
}
|
||||
|
||||
/// The UI Scale setting and the zoom it gives.
|
||||
fn scale(h: &Harness<'_, EffectcraftApp>) -> (u32, f32) {
|
||||
(h.state().session.prefs.appearance.ui_scale, h.ctx.zoom_factor())
|
||||
}
|
||||
|
||||
/// Types `text` into Settings' UI Scale a key at a time: nothing applies (and the field keeps
|
||||
/// the keyboard) until Enter.
|
||||
fn type_scale(h: &mut Harness<'_, EffectcraftApp>, text: &str) {
|
||||
let before = scale(h);
|
||||
click(h, "settings.appearance.uiScale");
|
||||
for c in text.chars() {
|
||||
h.input_mut().events.push(Event::Text(c.to_string()));
|
||||
h.run_steps(2);
|
||||
assert_eq!(scale(h), before, "{text}: not while typing");
|
||||
assert!(h.ctx.memory(|m| m.focused().is_some()), "{text}: the field keeps the keyboard");
|
||||
}
|
||||
key(h, egui::Key::Enter, egui::Modifiers::NONE);
|
||||
// (Settings re-centres a frame after the zoom changes.)
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
/// #284, #682: Settings ▸ Appearance ▸ UI Scale takes any typed percentage from 75 to 200 and
|
||||
/// sizes the whole interface once it is entered, Cancel puts it back, OK keeps it and later
|
||||
/// sessions start with it; Ctrl+0 (Window ▸ Project) doesn't reset it.
|
||||
#[test]
|
||||
fn ui_scale_setting_sizes_the_interface() {
|
||||
let mut h = harness();
|
||||
let ctx = h.ctx.clone();
|
||||
let choose = |h: &mut Harness<'_, EffectcraftApp>, label: &str| {
|
||||
let ctx = h.ctx.clone();
|
||||
effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "app.settings", json!({"page": "appearance"})).unwrap();
|
||||
h.run_steps(3);
|
||||
click(h, "settings.appearance.uiScale");
|
||||
let option = h.query_by_label(label).unwrap_or_else(|| panic!("the {label} choice")).rect().center();
|
||||
click_at(h, option);
|
||||
h.run_steps(2);
|
||||
};
|
||||
assert_eq!(ctx.zoom_factor(), 1.0);
|
||||
choose(&mut h, "150%");
|
||||
assert_eq!(h.state().session.prefs.appearance.ui_scale, 150);
|
||||
assert_eq!(ctx.zoom_factor(), 1.5, "live");
|
||||
open_settings(&mut h);
|
||||
type_scale(&mut h, "85");
|
||||
assert_eq!(scale(&h), (85, 0.85), "live");
|
||||
click(&mut h, "settings.cancel");
|
||||
h.run_steps(2);
|
||||
assert_eq!((h.state().session.prefs.appearance.ui_scale, ctx.zoom_factor()), (100, 1.0), "Cancel put it back");
|
||||
choose(&mut h, "125%");
|
||||
assert_eq!(scale(&h), (100, 1.0), "Cancel put it back");
|
||||
open_settings(&mut h);
|
||||
type_scale(&mut h, "300");
|
||||
assert_eq!(scale(&h), (200, 2.0), "at most 200");
|
||||
click(&mut h, "settings.cancel");
|
||||
h.run_steps(2);
|
||||
assert_eq!(scale(&h), (100, 1.0), "Cancel put it back from 200 %");
|
||||
open_settings(&mut h);
|
||||
type_scale(&mut h, "50");
|
||||
assert_eq!(scale(&h), (75, 0.75), "at least 75");
|
||||
type_scale(&mut h, "90");
|
||||
click(&mut h, "settings.ok");
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog, None);
|
||||
assert_eq!((h.state().session.prefs.appearance.ui_scale, ctx.zoom_factor()), (125, 1.25), "OK kept it");
|
||||
assert_eq!(scale(&h), (90, 0.9), "OK kept it");
|
||||
// Ctrl+0 opens the Project panel; egui's own Ctrl+0 zoom reset stays out of it.
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(Event::Key { key: egui::Key::Num0, physical_key: None, pressed, repeat: false, modifiers: egui::Modifiers::COMMAND });
|
||||
h.step();
|
||||
}
|
||||
key(&mut h, egui::Key::Num0, egui::Modifiers::COMMAND);
|
||||
h.run_steps(2);
|
||||
assert_eq!(ctx.zoom_factor(), 1.25);
|
||||
assert_eq!(ctx.zoom_factor(), 0.9);
|
||||
// A saved scale applies from the first frame.
|
||||
let mut s = Session::default();
|
||||
s.prefs.set("appearance.uiScale", json!(175)).unwrap();
|
||||
let s = Session { prefs: effectcraft_engine::prefs::Prefs::from_json(&h.state().session.prefs.to_json()), ..Default::default() };
|
||||
let mut h2 = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h2.run_steps(3);
|
||||
assert_eq!(h2.ctx.zoom_factor(), 1.75);
|
||||
assert_eq!(h2.ctx.zoom_factor(), 0.9);
|
||||
}
|
||||
|
||||
/// Settings' Previous / Next / Cancel / OK stay whole and in view at 200 % in a 1600×1000
|
||||
/// window (they scrolled out of the dialog with its pages): the page scrolls under them, Cancel
|
||||
/// restores the settings and OK saves them.
|
||||
#[test]
|
||||
fn settings_buttons_stay_in_view_at_200_percent() {
|
||||
let store = Arc::new(MemoryConfig::default());
|
||||
let saved = || {
|
||||
let mut s = Session { config: Some(store.clone()), ..Default::default() };
|
||||
s.prefs.disk.disk_cache_enabled = false;
|
||||
s.load_settings();
|
||||
s.prefs.appearance.ui_scale
|
||||
};
|
||||
let mut s = Session { config: Some(store.clone()), ..Default::default() };
|
||||
s.prefs.disk.disk_cache_enabled = false;
|
||||
s.prefs.set("appearance.uiScale", json!(200)).unwrap();
|
||||
s.save_prefs();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
assert_eq!(scale(&h), (200, 2.0));
|
||||
let rect = |h: &Harness<'_, EffectcraftApp>, id: &str| {
|
||||
let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}"));
|
||||
egui::Rect::from_min_size(pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3]))
|
||||
};
|
||||
// Whole: inside the window, and painted with none of them clipped away.
|
||||
let buttons = |h: &Harness<'_, EffectcraftApp>| {
|
||||
["previous", "next", "cancel", "ok"].map(|b| {
|
||||
let r = rect(h, &format!("settings.{b}"));
|
||||
let clip = h
|
||||
.output()
|
||||
.shapes
|
||||
.iter()
|
||||
.find(|c| matches!(&c.shape, egui::Shape::Rect(s) if (s.rect.center() - r.center()).length() < 0.5))
|
||||
.map(|c| c.clip_rect);
|
||||
assert!(h.ctx.content_rect().contains_rect(r) && clip.is_some_and(|c| c.contains_rect(r)), "{b} is cut off: {r:?} in {clip:?}");
|
||||
r
|
||||
})
|
||||
};
|
||||
let scroll_page = |h: &mut Harness<'_, EffectcraftApp>| {
|
||||
let at = rect(h, "settings.appearance.appearanceMode").center();
|
||||
h.input_mut().events.push(Event::PointerMoved(at));
|
||||
h.input_mut().events.push(Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: egui::vec2(0.0, -1000.0),
|
||||
modifiers: Default::default(),
|
||||
phase: egui::TouchPhase::Move,
|
||||
});
|
||||
h.run_steps(5);
|
||||
};
|
||||
open_settings(&mut h);
|
||||
let footer = buttons(&h);
|
||||
let field = rect(&h, "settings.appearance.uiScale");
|
||||
scroll_page(&mut h);
|
||||
assert_eq!(buttons(&h), footer, "the buttons don't scroll with the page");
|
||||
let scrolled = rect(&h, "settings.appearance.uiScale");
|
||||
assert!(scrolled.top() < field.top() && scrolled.bottom() < footer[2].top(), "the page scrolled to UI Scale: {field:?} -> {scrolled:?}");
|
||||
for (button, kept) in [("settings.cancel", 200), ("settings.ok", 150)] {
|
||||
if h.state().dialog.is_none() {
|
||||
open_settings(&mut h);
|
||||
scroll_page(&mut h);
|
||||
}
|
||||
type_scale(&mut h, "150");
|
||||
assert_eq!(scale(&h), (150, 1.5));
|
||||
buttons(&h);
|
||||
click(&mut h, button);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().dialog, None, "{button} closed Settings");
|
||||
assert_eq!((scale(&h), saved()), ((kept, kept as f32 / 100.0), kept), "{button}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Headless look at the panels (wgpu offscreen; needs a GPU adapter). Run with
|
||||
|
||||
@@ -47,11 +47,15 @@ fn check_info_transaction(via_escape: bool) {
|
||||
let edited_brightness = h.state().session.prefs.appearance.brightness;
|
||||
assert!((edited_brightness - original_brightness).abs() > 0.01, "real brightness slider changed");
|
||||
assert_eq!(saved(&store).prefs.appearance.brightness, original_brightness, "unconfirmed edit is not saved");
|
||||
// Use the upstream percent-valued Scale choice; keyboard zoom is deliberately disabled.
|
||||
// Type a UI Scale; keyboard zoom is deliberately disabled.
|
||||
let at = rect(&h, "settings.appearance.uiScale").center();
|
||||
click(&mut h, at);
|
||||
let at = h.get_by_label("125%").rect().center();
|
||||
click(&mut h, at);
|
||||
h.event(Event::Text("125".into()));
|
||||
for pressed in [true, false] {
|
||||
h.event(Event::Key { key: Key::Enter, physical_key: Some(Key::Enter), pressed, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().session.prefs.appearance.ui_scale, 125);
|
||||
assert_eq!(saved(&store).prefs.appearance.ui_scale, 100, "unconfirmed scale edit is not saved");
|
||||
// Let UI Scale settle the centered dialog before reading its next hit target.
|
||||
|
||||
Reference in New Issue
Block a user