Files
soundcraft/crates/ui-egui/tests/shortcuts.rs
T
grovebit 840939faf7 Cmd+= only switches Mix/Edit; the scale slider drags smoothly
Fixes #144. Unless Options::zoom_with_keyboard is off, egui zooms the
whole interface on Cmd+= (or Cmd+Plus), Cmd+- and Cmd+0. It checks for
those keys at the end of every frame, after SoundCraft's shortcuts have
read them without consuming them. So every Cmd+= that switched between
the Mix and Edit windows also zoomed in by another 10 %, and Cmd+0
(Quantize to Grid) reset the interface scale. Ctrl did the same on
Windows and Linux.

Turn egui's keyboard zoom off. The Interface scale slider in Setup >
Appearance is now the only thing that sizes the interface, so it always
shows the real scale. Before, keyboard zoom changed the scale without
moving the slider, and could go past its 75-150 % range.

Dragging that slider rescaled the whole interface on every frame of the
drag. Each rescale moved the slider relative to the pointer, which
stays put on screen, so the next frame read another value under the
pointer. The scale jumped back and forth (105, 110, 105 ... 145, 120,
150, 90 % in one drag) and the slider would not stay where it was
dragged. Apply the scale once the mouse button is released. It is now
applied after the window has drawn, too, so a click, Reset or an arrow
key takes effect in the same frame instead of waiting for the next
input.
2026-10-10 13:37:19 +01:00

47 lines
2.4 KiB
Rust

use egui::os::OperatingSystem;
use egui::{Key, Modifiers};
use serde_json::json;
use soundcraft_ui_egui::{MainWindow, Services, SoundApp, shortcuts};
fn press(ctx: &egui::Context, app: &mut SoundApp, key: Key, modifiers: Modifiers) {
let events = [true, false].map(|pressed| egui::Event::Key { key, physical_key: None, pressed, repeat: false, modifiers }).to_vec();
ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| shortcuts::handle(app, ui.ctx())).textures_delta.clear();
}
#[test]
fn ctrl_shift_arrows_nudge_the_selected_clip_gain() {
let pc_ctrl = Modifiers { ctrl: true, command: true, ..Modifiers::NONE };
for (os, ctrl) in [(OperatingSystem::Mac, Modifiers::CTRL), (OperatingSystem::Windows, pc_ctrl), (OperatingSystem::Nix, pc_ctrl)] {
let mut app = SoundApp::new(soundcraft_engine::demo::demo_engine(), None, Services::default());
let kick = app.engine.session().track_by_name("Kick").unwrap().clips()[0].id;
app.engine.execute("edit.select", &json!({"clips": [kick.0]})).unwrap();
let ctx = egui::Context::default();
ctx.set_os(os);
let ctrl_shift = Modifiers { shift: true, ..ctrl };
press(&ctx, &mut app, Key::ArrowUp, ctrl_shift);
press(&ctx, &mut app, Key::ArrowUp, ctrl_shift);
press(&ctx, &mut app, Key::ArrowDown, ctrl_shift);
assert_eq!(app.engine.session().find_clip(kick).unwrap().1.gain_db, 1.0, "{os:?}");
}
}
#[test]
fn cmd_equals_toggles_mix_and_edit_without_zooming() {
let mac_cmd = Modifiers { mac_cmd: true, command: true, ..Modifiers::NONE };
let pc_ctrl = Modifiers { ctrl: true, command: true, ..Modifiers::NONE };
for (os, cmd) in [(OperatingSystem::Mac, mac_cmd), (OperatingSystem::Windows, pc_ctrl), (OperatingSystem::Nix, pc_ctrl)] {
let mut app = SoundApp::new(soundcraft_engine::demo::demo_engine(), None, Services::default());
let ctx = egui::Context::default();
ctx.set_os(os);
ctx.set_zoom_factor(1.25);
press(&ctx, &mut app, Key::Equals, cmd);
assert_eq!(app.ui.window, MainWindow::Mix, "{os:?}");
press(&ctx, &mut app, Key::Equals, cmd);
press(&ctx, &mut app, Key::Num0, cmd);
press(&ctx, &mut app, Key::Minus, cmd);
ctx.run_ui(egui::RawInput::default(), |_| {}).textures_delta.clear();
assert_eq!(app.ui.window, MainWindow::Edit, "{os:?}");
assert_eq!(ctx.zoom_factor(), 1.25, "{os:?}");
}
}