Dialogs: New Workspace and New Toolbar fit their contents instead of opening 420 pt tall

New Workspace, Manage Workspaces, New Toolbar and Manage Toolbars put
their OK and Cancel row in a right-to-left layout directly in the modal
window. That layout took all the height left in the window's default
420 pt content area and centered the buttons in it, so each dialog
opened 420 pt tall with the buttons floating in an empty band.

The button row is now as wide as the fields above it and as tall as the
buttons, as the shared dialog shell already does (dialogs.rs), so each
window ends just below its buttons.
This commit is contained in:
dotCooCoo
2026-11-08 13:23:14 +07:00
committed by bflatastic
parent 960bc64197
commit b0ef9d610d
3 changed files with 43 additions and 3 deletions
+6 -2
View File
@@ -343,7 +343,10 @@ pub(crate) fn show_dialog(app: &mut VectorcraftApp, ctx: &egui::Context) {
}
});
ui.add_space(16.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
// As wide as the field and as tall as the buttons, as in `dialogs::show`: a right-to-left
// layout would take all the height left in the window and center the buttons in it.
let row = egui::vec2(ui.min_rect().width(), ui.spacing().interact_size.y);
ui.allocate_ui_with_layout(row, egui::Layout::right_to_left(egui::Align::Center), |ui| {
if widgets::primary_button(ui, tl!("OK")).clicked() {
ok = true;
}
@@ -445,7 +448,8 @@ pub(crate) fn show_manage(app: &mut VectorcraftApp, ctx: &egui::Context) {
}
});
ui.add_space(16.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let row = egui::vec2(ui.min_rect().width(), ui.spacing().interact_size.y);
ui.allocate_ui_with_layout(row, egui::Layout::right_to_left(egui::Align::Center), |ui| {
if widgets::primary_button(ui, tl!("OK")).clicked() {
ok = true;
}
+33
View File
@@ -463,6 +463,39 @@ fn dialogs_do_not_stretch_to_the_screen() {
assert!(checked >= 10, "only {checked} dialogs drew in the shared frame");
}
#[test]
fn workspace_and_toolbar_dialogs_end_at_their_buttons() {
// New Workspace, Manage Workspaces, New Toolbar and Manage Toolbars draw their own windows: each
// ends just below its OK button, with no empty band above or below the buttons.
for (kind, fields, window) in [
("newWorkspace", json!({"name": "Mine"}), "dialog-workspace"),
("manageWorkspaces", json!({"selected": "", "name": ""}), "dialog-workspace"),
(crate::custom_toolbars::KIND, json!({"name": "Toolbar 1"}), "dialog-new-toolbar"),
(crate::custom_toolbars::MANAGE, json!({"selected": "", "name": ""}), "dialog-manage-toolbars"),
] {
let mut app = app();
open(&mut app, kind, fields);
let ctx = egui::Context::default();
theme::install_fonts(&ctx);
theme::apply(&ctx, Default::default());
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 1000.0));
let mut ok = None;
for _ in 0..4 {
let input = egui::RawInput { screen_rect: Some(screen), ..Default::default() };
let mut out = ctx.run_ui(input, |ui| show(&mut app, ui.ctx()));
out.textures_delta.clear();
ok = out.shapes.iter().find_map(|c| match &c.shape {
egui::Shape::Text(t) if t.galley.text() == "OK" => Some(t.visual_bounding_rect()),
_ => None,
});
}
let ok = ok.unwrap_or_else(|| panic!("{kind} draws no OK button"));
let outer = ctx.memory(|m| m.area_rect(egui::Id::unique(window))).unwrap();
let below = outer.bottom() - ok.bottom();
assert!(below < 40.0, "{kind}: {below} pt between OK and the bottom of its {} pt window", outer.height());
}
}
/// The dialog window of `app`'s open dialog after a few frames in a `w` × 900 window.
fn dialog_rect(app: &mut VectorcraftApp, w: f32) -> egui::Rect {
let ctx = egui::Context::default();
+4 -1
View File
@@ -519,7 +519,10 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
ui.label(egui::RichText::new(tl!("Saves the current bars, toolbar and panel layout.")).color(t.text_dim).size(11.0));
}
ui.add_space(16.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
// As wide as the fields and as tall as the buttons, as in `dialogs::show`: a right-to-left
// layout would take all the height left in the window and center the buttons in it.
let row = egui::vec2(ui.min_rect().width(), ui.spacing().interact_size.y);
ui.allocate_ui_with_layout(row, egui::Layout::right_to_left(egui::Align::Center), |ui| {
if widgets::primary_button(ui, tl!("OK")).clicked() {
ok = true;
}