mirror of
https://github.com/storytold/soundcraft.git
synced 2026-12-02 20:22:27 -05:00
Merge pull request #1490 from istefp/fix/long-menu-scroll
Main menu: a menu taller than the window scrolls
This commit is contained in:
3 files changed
+101
-26
No files matched your search
+36
-26
@@ -298,32 +298,34 @@ pub fn menu_bar(app: &mut SoundApp, ui: &mut egui::Ui) {
|
||||
let extra = ui_aliases();
|
||||
for root in tree() {
|
||||
ui.menu_button(&root.label, |ui| {
|
||||
ui.add_enabled_ui(menu_entries_enabled, |ui| {
|
||||
for c in &root.children {
|
||||
menu_node(app, ui, c, &extra);
|
||||
if c.path == "File > Open" {
|
||||
crate::recent::menu(app, ui);
|
||||
scrolling(ui, |ui| {
|
||||
ui.add_enabled_ui(menu_entries_enabled, |ui| {
|
||||
for c in &root.children {
|
||||
menu_node(app, ui, c, &extra);
|
||||
if c.path == "File > Open" {
|
||||
crate::recent::menu(app, ui);
|
||||
}
|
||||
if c.path == "Track > New..." {
|
||||
instrument_menu(app, ui);
|
||||
}
|
||||
}
|
||||
if c.path == "Track > New..." {
|
||||
instrument_menu(app, ui);
|
||||
if root.path == "AudioSuite" {
|
||||
ui.separator();
|
||||
ui.label(egui::RichText::new("Processes selected clips offline").small().color(t.text_dim));
|
||||
}
|
||||
}
|
||||
if root.path == "AudioSuite" {
|
||||
ui.separator();
|
||||
ui.label(egui::RichText::new("Processes selected clips offline").small().color(t.text_dim));
|
||||
}
|
||||
if root.path == "Window" {
|
||||
ui.separator();
|
||||
let mut separate = app.ui.mix_separate;
|
||||
if ui
|
||||
.checkbox(&mut separate, "Mix in Separate Window")
|
||||
.on_hover_text("Show Edit and Mix at once, e.g. one per monitor")
|
||||
.changed()
|
||||
{
|
||||
let _ = run_ui_command(app, "window.mix_separate", &json!({"value": separate}));
|
||||
ui.close();
|
||||
if root.path == "Window" {
|
||||
ui.separator();
|
||||
let mut separate = app.ui.mix_separate;
|
||||
if ui
|
||||
.checkbox(&mut separate, "Mix in Separate Window")
|
||||
.on_hover_text("Show Edit and Mix at once, e.g. one per monitor")
|
||||
.changed()
|
||||
{
|
||||
let _ = run_ui_command(app, "window.mix_separate", &json!({"value": separate}));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -341,6 +343,12 @@ pub fn menu_bar(app: &mut SoundApp, ui: &mut egui::Ui) {
|
||||
);
|
||||
}
|
||||
|
||||
/// A menu taller than the window scrolls instead of running off its bottom edge (#1482).
|
||||
fn scrolling<R>(ui: &mut egui::Ui, add: impl FnOnce(&mut egui::Ui) -> R) -> R {
|
||||
let max_h = (ui.ctx().content_rect().height() - 40.0).max(120.0);
|
||||
egui::ScrollArea::vertical().max_height(max_h).show(ui, add).inner
|
||||
}
|
||||
|
||||
/// Track › Instrument: the instrument picker for the selected instrument track (#374).
|
||||
fn instrument_menu(app: &mut SoundApp, ui: &mut egui::Ui) {
|
||||
match instrument_track(app.engine.session()) {
|
||||
@@ -361,9 +369,11 @@ fn instrument_track(s: &soundcraft_model::Session) -> Option<soundcraft_model::T
|
||||
fn menu_node(app: &mut SoundApp, ui: &mut egui::Ui, n: &MenuNode, extra: &[(&str, &str)]) {
|
||||
if !n.children.is_empty() {
|
||||
ui.menu_button(&n.label, |ui| {
|
||||
for c in &n.children {
|
||||
menu_node(app, ui, c, extra);
|
||||
}
|
||||
scrolling(ui, |ui| {
|
||||
for c in &n.children {
|
||||
menu_node(app, ui, c, extra);
|
||||
}
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
//! A main menu taller than the window scrolls, so its last items can be reached (#1482).
|
||||
|
||||
use egui::{Event, Modifiers, MouseWheelUnit, PointerButton, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use soundcraft_ui_egui::{Services, SoundApp, menus};
|
||||
|
||||
const SIZE: egui::Vec2 = vec2(1200.0, 420.0);
|
||||
|
||||
fn step(h: &mut Harness<'_, SoundApp>) {
|
||||
let mut raw = std::mem::take(h.input_mut());
|
||||
let ctx = h.ctx.clone();
|
||||
h.state_mut().raw_input_hook(&ctx, &mut raw);
|
||||
*h.input_mut() = raw;
|
||||
h.step();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_long_main_menu_scrolls_to_its_last_item() {
|
||||
let app = SoundApp::new(soundcraft_engine::demo::demo_engine(), None, Services::default());
|
||||
let mut h = Harness::builder().with_size(SIZE).build_ui_state(
|
||||
|ui, app: &mut SoundApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
app.ui(ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
for _ in 0..4 {
|
||||
step(&mut h);
|
||||
}
|
||||
let options = menus::tree().into_iter().find(|r| r.path == "Options").unwrap();
|
||||
// The menu must scroll all the way to its last entry, a leaf like "Low Latency Monitoring".
|
||||
let last = options.children.last().unwrap().label.clone();
|
||||
|
||||
let at = h.get_by_label("Options").rect().center();
|
||||
let s = &mut h.state_mut().synthetic;
|
||||
s.push(Event::PointerMoved(at));
|
||||
s.push(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
s.push(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
for _ in 0..6 {
|
||||
step(&mut h);
|
||||
}
|
||||
let bottom = |h: &Harness<'_, SoundApp>| h.get_by_label_contains(&last).rect().bottom();
|
||||
assert!(bottom(&h) > SIZE.y, "the Options menu is taller than the window, so `{last}` starts out of view");
|
||||
|
||||
// Over the top of the open menu, which drops down below its title.
|
||||
h.state_mut().synthetic.push(Event::PointerMoved(at + vec2(80.0, 120.0)));
|
||||
step(&mut h);
|
||||
for _ in 0..40 {
|
||||
h.state_mut().synthetic.push(Event::MouseWheel {
|
||||
unit: MouseWheelUnit::Line,
|
||||
delta: vec2(0.0, -3.0),
|
||||
modifiers: Modifiers::NONE,
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Wheel,
|
||||
});
|
||||
step(&mut h);
|
||||
}
|
||||
for _ in 0..10 {
|
||||
step(&mut h);
|
||||
}
|
||||
assert!(bottom(&h) <= SIZE.y, "scrolling the menu brings `{last}` into view (bottom at {})", bottom(&h));
|
||||
}
|
||||
@@ -22,6 +22,7 @@ mod group_dialog;
|
||||
mod hide_floating;
|
||||
mod idle;
|
||||
mod key_families;
|
||||
mod long_menu_scroll;
|
||||
mod marker_rename;
|
||||
mod menu_search;
|
||||
mod midi_double_click;
|
||||
|
||||
Reference in new issue
Block a user