Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

PR-1285: the TOC title field narrows in a small dialog so its style selector stays in view

moppeeer31e4c346f196
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index ab4070568..1abf914a3 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -6334,10 +6334,15 @@ fn toc_dialog(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {
let mut sel = d.n("selected").map_or(0, |n| n.max(0.0) as usize);
let mut other = d.s("other");
let mut title_style = d.s("titleStyle");
+ // The dialog body's width, less the two labels and the style selector (200 pt) beside the title.
+ let title_room = ui.available_width() - 300.0;
egui::Grid::new("toc_title").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {
crate::rtl::label(ui, tr("Title:"));
let mut title = d.s("title");
- if ui.add_sized([200.0, ui.spacing().interact_size.y], egui::TextEdit::singleline(&mut title).horizontal_align(egui::Align::Min)).changed() {
+ // 200 pt, reserved: a desired width alone is squeezed by the grid to a few characters.
+ // Narrower when the dialog is, so the style selector beside it stays in view.
+ let w = 200.0_f32.min(title_room.max(80.0));
+ if ui.add_sized([w, ui.spacing().interact_size.y], egui::TextEdit::singleline(&mut title).horizontal_align(egui::Align::Min)).changed() {
d.fields.insert("title".into(), json!(title));
}
crate::rtl::label(ui, tr("Style:"));
@@ -7993,6 +7998,18 @@ mod tests {
app.ui.dialog.as_mut().unwrap().fields.insert("title".into(), json!("Table of Contents"));
let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
visible_label(&title_row(&labels), screen, "Table of Contents");
+ // A small window: the title narrows and the style selector beside it stays in view.
+ let small = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(450.0, 280.0));
+ for _ in 0..3 {
+ dialog_frame(&mut app, &ctx, small, vec![]);
+ }
+ let labels = dialog_frame(&mut app, &ctx, small, vec![]);
+ let y = visible_label(&labels, small, "Title:").center().y;
+ let row: Vec<_> = labels.iter().filter(|(_, rect, _)| (rect.center().y - y).abs() < 2.0).cloned().collect();
+ let style = visible_label(&row, small, "TOC Title");
+ // The selector is 200 pt wide from just before its text: all of it is in the dialog body.
+ let (_, _, body) = row.iter().find(|(text, _, _)| text == "Style:").unwrap();
+ assert!(style.min.x - 4.0 + 200.0 <= body.max.x, "the style selector fits the dialog: {style:?} in {body:?}");
}
#[test]
@@ -8931,7 +8948,7 @@ mod tests {
#[test]
fn dialog_title_and_actions_fit_scaled_viewports() {
for language in ["en", "ar"] {
- for size in [egui::vec2(1178.0, 814.0), egui::vec2(589.0, 407.0), egui::vec2(392.0, 271.0), egui::vec2(450.0, 280.0)] {
+ for size in [egui::vec2(1178.0, 814.0), egui::vec2(589.0, 407.0), egui::vec2(392.0, 271.0), egui::vec2(360.0, 280.0)] {
for (command, title, ok, cancel) in
[("app.preferences", "Preferences", "OK", "Cancel"), ("app.newDocumentDialog", "New Document", "Create", "Close")]
{
@@ -9047,7 +9064,7 @@ mod tests {
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
app.run("app.preferences", json!({})).unwrap();
let ctx = dialog_context("en");
- let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(450.0, 280.0));
+ let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(360.0, 280.0));
for _ in 0..3 {
dialog_frame(&mut app, &ctx, screen, vec![]);
}
@@ -9107,7 +9124,7 @@ mod tests {
#[test]
fn arabic_new_document_fields_remain_reachable_and_editable() {
- for size in [egui::vec2(392.0, 271.0), egui::vec2(450.0, 280.0), egui::vec2(1178.0, 814.0)] {
+ for size in [egui::vec2(392.0, 271.0), egui::vec2(360.0, 280.0), egui::vec2(1178.0, 814.0)] {
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
app.ui.language = "ar".into();
app.run("app.newDocumentDialog", json!({})).unwrap();