diff --git a/crates/ui-egui/src/dialogs/gradient_stop.rs b/crates/ui-egui/src/dialogs/gradient_stop.rs index 1cab75f7bd..d38eae5bb0 100644 --- a/crates/ui-egui/src/dialogs/gradient_stop.rs +++ b/crates/ui-egui/src/dialogs/gradient_stop.rs @@ -21,7 +21,7 @@ use craft::ui::choice::Segmented; use craft::ui::contract::{Bind, Entry, Show as _, ShowContainer as _}; use craft::ui::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, StackDialog, dialog_id}; use craft::ui::form::Field; -use craft::ui::layout_components::Stack; +use craft::ui::layout_components::{Row, Stack}; use craft::ui::notices::Notice; use craft::ui::popover::Popover; use craft::ui::runtime::env::{Label, UnitKind}; @@ -264,7 +264,7 @@ impl StackDialog for GradientStopPopover { /// point: spread). What the user edits is filed in `filed`. fn body(ui: &mut Ui, feed: &Feed, tab: &mut Tab, panel: &mut ColorPanelState, filed: &mut Filed) { Stack::new().show(ui, |ui, _| { - ui.horizontal(|ui| { + Row::new().show(ui, |ui, _| { let tabs = [ Entry::new(Tab::Color, tl!("Color").to_owned()).icon(IconId::new("palette")), Entry::new(Tab::Swatches, tl!("Swatches").to_owned()).icon(IconId::new("swatch-book")), @@ -288,7 +288,7 @@ fn body(ui: &mut Ui, feed: &Feed, tab: &mut Tab, panel: &mut ColorPanelState, fi } Tab::Swatches => swatches(ui, feed, filed), } - ui.horizontal(|ui| { + Row::new().show(ui, |ui, _| { filed.fields.opacity = percent_field(ui, tl!("Opacity").to_owned(), feed.opacity).or(filed.fields.opacity); let (label, amount) = if feed.point { (tl!("Spread"), &mut filed.fields.spread) } else { (tl!("Location"), &mut filed.fields.location) }; *amount = percent_field(ui, label.to_owned(), feed.amount).or(*amount); diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 489eee6f61..8ee0a7c13f 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -1003,6 +1003,8 @@ mod tests_links; #[cfg(test)] mod tests_maskview; #[cfg(test)] +mod tests_panel_rows; +#[cfg(test)] mod tests_script_console; #[cfg(test)] mod tests_stroke; diff --git a/crates/ui-egui/src/panels/align.rs b/crates/ui-egui/src/panels/align.rs index 5cff5f4aed..9b8d94a31b 100644 --- a/crates/ui-egui/src/panels/align.rs +++ b/crates/ui-egui/src/panels/align.rs @@ -9,6 +9,7 @@ use craft::ui::bars::{BarItem, BarItems}; use craft::ui::buttons::{IconButton, PopupMark, ToggleButton}; use craft::ui::contract::{Bind, PopupKind, Props as _, Show as _, ShowContainer as _, Trigger}; use craft::ui::display::Divider; +use craft::ui::layout_components::Row; use craft::ui::menu::{Menu, MenuItem, PanelRow}; use craft::ui::runtime::commands::{CommandState, CommandStates}; use craft::ui::text::NumberField; @@ -305,7 +306,7 @@ fn bar_items(buttons: impl Iterator) -> BarItems { /// Align panel's Align To says (the key object while there is one), as its own buttons do (#789), /// and the selected artboards with the Artboard tool chosen. pub(crate) fn align_buttons(_app: &mut VectorcraftApp, ui: &mut Ui) { - ui.horizontal(|ui| { + Row::new().show(ui, |ui, _| { for (icon, b) in align_icons() { command_button(ui, bar_glyph(b).unwrap_or(icon), b); } @@ -333,7 +334,7 @@ pub(crate) fn button_enabled(app: &VectorcraftApp, b: &Button) -> bool { pub(crate) fn control_bar_strip(app: &mut VectorcraftApp, ui: &mut Ui) { let (icon, name) = align_to_icon_name(shown_align_to(app), key_is_anchor(app)); let distributes = if on_artboards(app) { artboards_distribute(app) } else { objects_aligned(app) > 1 }; - ui.horizontal(|ui| { + Row::new().show(ui, |ui, _| { bar_items(align_icons().map(|(_, b)| b)).show(ui); let button = IconButton::new(IconId::new(icon)) .label(tl!("Align To:")) @@ -498,14 +499,14 @@ pub(crate) fn run_align_to(app: &mut VectorcraftApp, v: AlignTo) -> Result show_box(app, panel, ui, &cx, &set), - View::Wheel => show_wheel(app, panel, ui, &cx, &set), + View::Box => { + Row::new().fill_width().show(ui, |ui, _| show_box(app, panel, ui, cx, set)); + } + View::Wheel => show_wheel(app, panel, ui, cx, set), } }); match set.sliders { Sliders::None => {} - Sliders::Oklch => { - ui.add_space(4.0); - oklch_rows(app, panel, ui, &cx); - } - Sliders::Hsl => { - ui.add_space(4.0); - hsl_rows(app, panel, ui, &cx); - } + Sliders::Oklch => oklch_rows(app, panel, ui, cx), + Sliders::Hsl => hsl_rows(app, panel, ui, cx), } // A row drag whose rows were hidden or replaced (`ui.colorWheel {sliders}`), or turned gray // (OKLCH rows after the working RGB space stops being sRGB), reports no release: its preview is // kept as one undo step and the interaction ends. let sliders = app.ui.color_wheel.sliders; - if panel.rows_live.is_some_and(|rows| rows != sliders || (rows == Sliders::Oklch && !cms.rgb_is_srgb())) { + if panel.rows_live.is_some_and(|rows| rows != sliders || (rows == Sliders::Oklch && !cx.cms.rgb_is_srgb())) { if app.session.in_interaction() && let Err(e) = app.session.commit_interaction() { @@ -1139,12 +1148,11 @@ fn show_with(app: &mut VectorcraftApp, panel: &mut WheelUi, ui: &mut Ui) { panel.rows_live = None; } if set.vision { - ui.add_space(4.0); - vision_row(ui, &cms, color.as_ref()); + vision_row(ui, cx.cms, cx.color.as_ref()); } if set.document_colors - && let Some(u) = document_colors_row(app, panel, ui, &cms, now) + && let Some(u) = document_colors_row(app, panel, ui, cx.cms, now) { - apply_used(app, &tgt, &u, behind); + apply_used(app, cx.tgt, &u, cx.behind); } } diff --git a/crates/ui-egui/src/panels/paragraph.rs b/crates/ui-egui/src/panels/paragraph.rs index b7d5fdc67d..2dd7f1f39f 100644 --- a/crates/ui-egui/src/panels/paragraph.rs +++ b/crates/ui-egui/src/panels/paragraph.rs @@ -14,6 +14,7 @@ use craft::ui::buttons::{IconButton, PopupMark, ToggleButton}; use craft::ui::choice::Checkbox; use craft::ui::contract::{Bind, Entry, MemoProps, Props as _, Show as _, ShowContainer as _, Trigger}; use craft::ui::form::Field; +use craft::ui::layout_components::Row; use craft::ui::menu::{Menu, PanelRow}; use craft::ui::pickers::Select; use craft::ui::popover::Popover; @@ -438,8 +439,8 @@ pub(crate) fn control_bar(app: &mut VectorcraftApp, ui: &mut Ui) -> bool { if text_style(app).is_none() { return true; } - // PLAN: the members' `Row::fit_rank` (ch.K30: toggles out before the link) belongs to chrome-w16's row; `horizontal` stands in until it lands. - ui.horizontal(|ui| { + // PLAN: the members' `Row::fit_rank` (ch.K30: toggles out before the link) belongs to chrome-w16's row. + Row::new().show(ui, |ui, _| { let link = crate::panels::option_link(tl!("Paragraph:")).tooltip(tl!("Paragraph options")).show(ui); Popover::new(tl!("Paragraph"), Bind::kept()) .overlay(|overlay| overlay.opened_by(&link.response, Trigger::Click)) @@ -660,7 +661,7 @@ fn list_control(ui: &mut Ui, kind: ListKind, pressed: bool, entries: &[Entry toggle_list(app, ListKind::Bullets), diff --git a/crates/ui-egui/src/panels/stroke.rs b/crates/ui-egui/src/panels/stroke.rs index c339c73b6e..c4a5b91318 100644 --- a/crates/ui-egui/src/panels/stroke.rs +++ b/crates/ui-egui/src/panels/stroke.rs @@ -10,8 +10,9 @@ use craft::draw::ui::stroke::{self as draw, StrokeEditor, StrokeField, StrokeSec use craft::keymap::CommandRef; use craft::ui::buttons::IconButton; use craft::ui::choice::Segmented; -use craft::ui::contract::{Bind, Entry, FieldLabelRole, Props as _, Show as _, ShowContainer as _, SideLabel, TooltipSpec}; +use craft::ui::contract::{Bind, Entry, FieldLabelRole, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, TooltipSpec}; use craft::ui::form::Field; +use craft::ui::layout_components::Row; use craft::ui::menu::PanelRow; use craft::ui::pickers::Select; use craft::ui::popover::Popover; @@ -390,7 +391,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { arrow_rows(app, ui, st.as_ref()); ui.separator(); Field::new(tl!("Profile")).show(ui, |ui, _| { - ui.horizontal(|ui| { + Row::new().show(ui, |ui, _| { profile_select(app, ui); flip_buttons(app, ui, st.as_ref()); }); @@ -410,11 +411,14 @@ fn arrow_rows(app: &mut VectorcraftApp, ui: &mut Ui, st: Option<&StrokeLayer>) { (st.and_then(|s| s.end_arrow.clone()), false, tl!("End arrowhead"), "endArrow"), ]; Field::new(tl!("Arrowheads")).show(ui, |ui, _| { - ui.horizontal(|ui| { + // The two heads share the width the Swap button leaves; a field too narrow for all three puts Swap on a + // new line. + Row::new().fill_width().wrap(true).show(ui, |ui, _| { for (head, start, label, key) in &heads { let (start, key) = (*start, *key); let out = Select::new(*label, Bind::given(head.clone()), &entries) .picture(move |a, cx, rect| arrow_thumb(cx, rect, a.as_ref(), start)) + .sizing(Sizing::FillWidth) .show(ui); // A custom head goes with its art, as document.inspect reports it. if let Some(a) = out.events.landed() { diff --git a/crates/ui-egui/src/panels/tests_panel_rows.rs b/crates/ui-egui/src/panels/tests_panel_rows.rs new file mode 100644 index 0000000000..51a22a4d2b --- /dev/null +++ b/crates/ui-egui/src/panels/tests_panel_rows.rs @@ -0,0 +1,38 @@ +//! Headless frames of panel rows that the framework lays out: controls side by side stay inside the panel's width. + +use super::tests_appearance::app_with_rect; +use super::*; +use crate::panel_docking::PANEL_MIN_WIDTH; +use crate::tests::panel_harness::{Panel, ROOM}; + +#[test] +fn the_arrowhead_row_stays_inside_the_stroke_panel() { + let panel = Panel::new(app_with_rect(), stroke::show); + // The Arrowheads field spans the panel's width. + let row = panel.rect("Arrowheads"); + for name in ["Start arrowhead", "End arrowhead", "Swap start and end arrowheads"] { + assert!(row.contains_rect(panel.rect(name)), "{name} at {:?} is outside the row {row:?}", panel.rect(name)); + } +} + +#[test] +fn the_color_themes_hex_row_stays_inside_a_narrow_panel() { + let mut panel = Panel::new(app_with_rect(), color_themes::show); + panel.room(egui::vec2(PANEL_MIN_WIDTH, ROOM.y)).frame(); + // The tab strip spans the panel's width. + let width = panel.rect("Color Themes"); + for name in ["Color", "Set the current fill or stroke to the selected color", "Set the selected color to the current color"] { + let at = panel.rect(name); + assert!(at.left() >= width.left() && at.right() <= width.right(), "{name} at {at:?} is outside the panel {width:?}"); + } +} + +#[test] +fn the_color_wheel_box_and_its_strip_stay_inside_the_panel() { + let mut app = app_with_rect(); + app.ui.color_wheel.view = color_wheel::View::Box; + let panel = Panel::new(app, color_wheel::show); + let (field, strip) = (panel.rect("Color box"), panel.rect("Hue")); + assert!(strip.height() <= field.height(), "the strip {strip:?} is taller than the box {field:?}"); + assert!(field.right() <= ROOM.x && strip.right() <= ROOM.x, "the box {field:?} or its strip {strip:?} runs past the panel"); +}