From f1decbad01f4d2eb5259e2a62594c5e06a5a2404 Mon Sep 17 00:00:00 2001 From: batistalucasv Date: Sun, 22 Nov 2026 12:38:58 -0300 Subject: [PATCH] Mini toolbar: stack formatting controls into two rows inside floating TaskBar (#7375) (#7378) --- crates/ui-egui/src/mini_toolbar.rs | 142 ++++++++++++----------- crates/ui-egui/src/mini_toolbar/tests.rs | 23 ++++ 2 files changed, 96 insertions(+), 69 deletions(-) diff --git a/crates/ui-egui/src/mini_toolbar.rs b/crates/ui-egui/src/mini_toolbar.rs index 533d7a5cb0..92658dd2aa 100644 --- a/crates/ui-egui/src/mini_toolbar.rs +++ b/crates/ui-egui/src/mini_toolbar.rs @@ -7,8 +7,9 @@ use craft::keymap::CommandRef; use craft::pages::ui::PageBody; use craft::ui::buttons::{IconButton, ToggleButton}; use craft::ui::canvas_controls::TaskBar; -use craft::ui::contract::{Bind, Entry, Hover, Props, Show as _}; +use craft::ui::contract::{Bind, Entry, Gap, Hover, Props, Show as _, ShowContainer as _}; use craft::ui::display::Divider; +use craft::ui::layout_components::{Row, Stack}; use craft::ui::pickers::ComboBox; use craft::ui::runtime::env::Label; use egui::{Rect, Ui}; @@ -149,78 +150,81 @@ pub(crate) fn members(app: &mut WordApp, ui: &mut Ui, preview: bool) { if preview && let Some(held) = app.canvas.list_preview.clone() { app.canvas.command_preview = Some(held); } - ui.horizontal(|ui| { - let mut family = st.get("font").and_then(Value::as_str).unwrap_or("").to_string(); - let picked = crate::widgets::font_box::font_box(ui, app, tl!("Font").to_string(), &mut family); - follow_list(app, preview, &picked.preview, |f| Some(("format.font".to_string(), json!({"name": f})))); - if let Some(f) = &picked.picked { - let _ = app.run("format.font", json!({"name": f})); - } + Stack::new().gap(Gap::Tight).show(ui, |ui, _| { + Row::new().gap(Gap::Tight).show(ui, |ui, _| { + let mut family = st.get("font").and_then(Value::as_str).unwrap_or("").to_string(); + let picked = crate::widgets::font_box::font_box(ui, app, tl!("Font").to_string(), &mut family); + follow_list(app, preview, &picked.preview, |f| Some(("format.font".to_string(), json!({"name": f})))); + if let Some(f) = &picked.picked { + let _ = app.run("format.font", json!({"name": f})); + } - let size = st.get("size").and_then(Value::as_f64).map(number_text).unwrap_or_default(); - let sizes: Vec> = - wordcraft_engine::cmd::format::SIZES.iter().map(|s| Entry::new(number_text(f64::from(*s)), number_text(f64::from(*s)))).collect(); - let mut text = size.clone(); - let combo = ComboBox::new(tl!("Font Size").to_string(), Bind::bound(&mut text), &sizes).show(ui); - follow_list(app, preview, &combo.preview, |v| v.trim().parse::().ok().map(|x| ("format.size".to_string(), json!({"size": x})))); - // Only a pick or Enter applies the size: typing alone is an edit of the box's draft. - let committed = combo.edit.submitted || combo.edit.events.iter().any(|e| matches!(e, EditEvent::Set { .. } | EditEvent::Commit { .. })); - if committed - && text != size - && let Ok(x) = text.trim().parse::() - { - let _ = app.run("format.size", json!({"size": x})); - } + let size = st.get("size").and_then(Value::as_f64).map(number_text).unwrap_or_default(); + let sizes: Vec> = + wordcraft_engine::cmd::format::SIZES.iter().map(|s| Entry::new(number_text(f64::from(*s)), number_text(f64::from(*s)))).collect(); + let mut text = size.clone(); + let combo = ComboBox::new(tl!("Font Size").to_string(), Bind::bound(&mut text), &sizes).show(ui); + follow_list(app, preview, &combo.preview, |v| v.trim().parse::().ok().map(|x| ("format.size".to_string(), json!({"size": x})))); + // Only a pick or Enter applies the size: typing alone is an edit of the box's draft. + let committed = combo.edit.submitted || combo.edit.events.iter().any(|e| matches!(e, EditEvent::Set { .. } | EditEvent::Commit { .. })); + if committed + && text != size + && let Ok(x) = text.trim().parse::() + { + let _ = app.run("format.size", json!({"size": x})); + } - for (id, icon) in [("format.growFont", "grow"), ("format.shrinkFont", "shrink")] { - let b = IconButton::command(crate::icons::id(icon), CommandRef::new(id)).show(ui); - preview_on_hover(app, b.hover, b.response.enabled(), id, json!({}), preview); - } - }); - - ui.horizontal(|ui| { - for (id, key, icon) in [ - ("format.bold", "bold", "bold"), - ("format.italic", "italic", "italic"), - ("format.underline", "underline", "underline"), - ("format.strikethrough", "strike", "strike"), - ] { - toggle(ui, app, id, icon, flag(key), preview); - } - let _ = Divider::vertical().show(ui); - - let hl = crate::colors::highlight_split(ui, app, tl!("Text Highlight Color").to_string()); - follow_list(app, preview, &hl.preview, |c| { - wordcraft_doc::props::Highlight::ALL - .iter() - .find(|h| h.rgb().as_ref() == Some(c)) - .map(|h| ("format.highlight".to_string(), json!({"color": h.ooxml()}))) + for (id, icon) in [("format.growFont", "grow"), ("format.shrinkFont", "shrink")] { + let b = IconButton::command(crate::icons::id(icon), CommandRef::new(id)).show(ui); + preview_on_hover(app, b.hover, b.response.enabled(), id, json!({}), preview); + } }); - // PLAN: assumed ColorPick::hover (ribbon-w11, S-L413) - let color = app.canvas.last_highlight.clone(); - preview_on_hover(app, hl.hover, hl.response.enabled(), "format.highlight", json!({"color": color}), preview); - if hl.picked.is_some() { - app.canvas.focus_page(ui.ctx()); - } - let fc = crate::colors::font_color_split(ui, app, tl!("Font Color").to_string(), Target::cmd("format.color").remember(Remember::FontColor)); - follow_list(app, preview, &fc.preview, |c| Some(("format.color".to_string(), json!({"color": c.hex()})))); - // PLAN: assumed ColorPick::hover (ribbon-w11, S-L413) - let color = app.canvas.last_font_color.clone(); - preview_on_hover(app, fc.hover, fc.response.enabled(), "format.color", json!({"color": color}), preview); - if fc.picked.is_some() { - app.canvas.focus_page(ui.ctx()); - } - let _ = Divider::vertical().show(ui); - use wordcraft_doc::Align as A; - for (id, icon, a) in [ - ("para.alignLeft", "alignLeft", A::Left), - ("para.alignCenter", "alignCenter", A::Center), - ("para.alignRight", "alignRight", A::Right), - ("para.justify", "justify", A::Justify), - ] { - toggle(ui, app, id, icon, align == a, preview); - } + Row::new().gap(Gap::Tight).show(ui, |ui, _| { + for (id, key, icon) in [ + ("format.bold", "bold", "bold"), + ("format.italic", "italic", "italic"), + ("format.underline", "underline", "underline"), + ("format.strikethrough", "strike", "strike"), + ] { + toggle(ui, app, id, icon, flag(key), preview); + } + let _ = Divider::vertical().show(ui); + + let hl = crate::colors::highlight_split(ui, app, tl!("Text Highlight Color").to_string()); + follow_list(app, preview, &hl.preview, |c| { + wordcraft_doc::props::Highlight::ALL + .iter() + .find(|h| h.rgb().as_ref() == Some(c)) + .map(|h| ("format.highlight".to_string(), json!({"color": h.ooxml()}))) + }); + // PLAN: assumed ColorPick::hover (ribbon-w11, S-L413) + let color = app.canvas.last_highlight.clone(); + preview_on_hover(app, hl.hover, hl.response.enabled(), "format.highlight", json!({"color": color}), preview); + if hl.picked.is_some() { + app.canvas.focus_page(ui.ctx()); + } + let fc = + crate::colors::font_color_split(ui, app, tl!("Font Color").to_string(), Target::cmd("format.color").remember(Remember::FontColor)); + follow_list(app, preview, &fc.preview, |c| Some(("format.color".to_string(), json!({"color": c.hex()})))); + // PLAN: assumed ColorPick::hover (ribbon-w11, S-L413) + let color = app.canvas.last_font_color.clone(); + preview_on_hover(app, fc.hover, fc.response.enabled(), "format.color", json!({"color": color}), preview); + if fc.picked.is_some() { + app.canvas.focus_page(ui.ctx()); + } + let _ = Divider::vertical().show(ui); + + use wordcraft_doc::Align as A; + for (id, icon, a) in [ + ("para.alignLeft", "alignLeft", A::Left), + ("para.alignCenter", "alignCenter", A::Center), + ("para.alignRight", "alignRight", A::Right), + ("para.justify", "justify", A::Justify), + ] { + toggle(ui, app, id, icon, align == a, preview); + } + }); }); } diff --git a/crates/ui-egui/src/mini_toolbar/tests.rs b/crates/ui-egui/src/mini_toolbar/tests.rs index 1e14efbc59..a4480e83df 100644 --- a/crates/ui-egui/src/mini_toolbar/tests.rs +++ b/crates/ui-egui/src/mini_toolbar/tests.rs @@ -214,6 +214,29 @@ fn every_control_fits_inside_the_bar() { } } +/// #7375: the bar's formatting controls are stacked into two rows: Row 2 controls (Bold, +/// Align Left) sit strictly below Row 1 controls (Font, Font Size) rather than side-by-side. +#[test] +fn formatting_controls_stack_into_two_rows() { + let h = bar_over("brown fox"); + let font = font_box(&h); + let size = size_box(&h); + let bold = member(&h, "Bold").expect("the bar has Bold"); + let align_left = member(&h, "Align Left").expect("the bar has Align Left"); + + // Row 1 controls sit on the top row together. + assert!((font.min.y - size.min.y).abs() < 1.0, "Font and Font Size must share Row 1: font {font:?}, size {size:?}"); + + // Row 2 controls sit on the second row together. + assert!((bold.min.y - align_left.min.y).abs() < 1.0, "Bold and Align Left must share Row 2: bold {bold:?}, align_left {align_left:?}"); + + // Row 2 controls sit strictly below Row 1 controls. + assert!(bold.min.y >= font.max.y, "Bold ({bold:?}) must sit strictly below Font ({font:?})"); + assert!(bold.min.y >= size.max.y, "Bold ({bold:?}) must sit strictly below Font Size ({size:?})"); + assert!(align_left.min.y >= font.max.y, "Align Left ({align_left:?}) must sit strictly below Font ({font:?})"); + assert!(align_left.min.y >= size.max.y, "Align Left ({align_left:?}) must sit strictly below Font Size ({size:?})"); +} + /// Hovering any member of the bar previews its command on the selection; the pick is not made. #[test] fn hovering_a_bar_member_previews_its_command() {