Settings: keep action buttons visible at high UI scales
At 200 % in a 1600x1000 window, Previous / Next / Cancel / OK were cut off. Settings sized its pages from the window height less a fixed 170, and the shared modal put everything, buttons included, in one more scroll area, so a footer that didn't fit scrolled out of the dialog. The modal helper gets a modal_fit variant without that scroll area: it hands its body the height left under the title. Settings lays out its buttons first, from the bottom up, and gives the page list and the page what they leave; both scroll on their own and the buttons stay put. The pages are a clipped child, so a wide page can't widen the dialog under the buttons. Other dialogs keep modal as it was. Tests: settings_buttons_stay_in_view_at_200_percent opens Settings at 200 % in 1600x1000 and checks that each button is inside the window and painted unclipped (fails before this change: the scroll area clipped them at the bottom). It scrolls the page to UI Scale without moving them, then types 150 and clicks Cancel (200 % again, nothing saved) and OK (150 % saved). The UI Scale test no longer needs a larger window and clicks Cancel at 200 %.
This commit is contained in:
@@ -149,9 +149,23 @@ pub fn route_layer_settings(app: &mut EffectcraftApp, id: &str, params: &Value)
|
||||
}
|
||||
}
|
||||
|
||||
/// The room a modal dialog may take: the window less a margin.
|
||||
fn modal_space(ctx: &egui::Context) -> egui::Vec2 {
|
||||
(ctx.content_rect().size() - vec2(48.0, 48.0)).max(vec2(120.0, 80.0))
|
||||
}
|
||||
|
||||
pub(crate) fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) {
|
||||
let available = (ctx.content_rect().size() - vec2(48.0, 48.0)).max(vec2(120.0, 80.0));
|
||||
let size = size.min(available);
|
||||
let max_height = (modal_space(ctx).y - 84.0).max(40.0);
|
||||
modal_fit(ctx, title, size, t, |ui, _| {
|
||||
egui::ScrollArea::both().max_height(max_height).auto_shrink([false, true]).show(ui, body);
|
||||
});
|
||||
}
|
||||
|
||||
/// [`modal`] without its scroll area, for a dialog that keeps its buttons in view and scrolls
|
||||
/// only its content: `body` gets the height left under the title, with `size` kept within the
|
||||
/// window.
|
||||
pub(crate) fn modal_fit(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui, f32)) {
|
||||
let size = size.min(modal_space(ctx));
|
||||
egui::Modal::new(egui::Id::new(("modal", title)))
|
||||
.backdrop_color(Color32::from_black_alpha(120))
|
||||
.frame(egui::Frame::window(&ctx.style_of(ctx.theme())).fill(t.panel_bg).inner_margin(egui::Margin::same(18)))
|
||||
@@ -161,7 +175,8 @@ pub(crate) fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Toke
|
||||
// The id stays keyed on the untranslated source, so switching language cannot move it.
|
||||
ui.label(egui::RichText::new(tr(title)).font(Tokens::semibold(15.0)).color(t.tab_text_active));
|
||||
ui.add_space(10.0);
|
||||
egui::ScrollArea::both().max_height((available.y - 84.0).max(40.0)).auto_shrink([false, true]).show(ui, body);
|
||||
let title_h = ui.cursor().top() - ui.min_rect().top();
|
||||
body(ui, (size.y - 36.0 - title_h).max(40.0));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user