Panels: rows of side-by-side controls are Row and Stack, and stay inside the panel

The rows of controls that sat in raw horizontal layouts inside framework
containers are the framework's Row, Stack and Grid.

- Stroke: the Arrowheads row fills the field. The two heads share the
  width Swap leaves, and Swap moves to a new line when all three do not
  fit. Before, the row ran past the panel's right edge. The Profile row
  is a Row.
- Color Themes: the Create tab's hex row is a Row, so its two buttons
  stay inside a panel at its least width.
- Color Wheel: the rows are a Stack, and the top row is a Grid with the
  proxy at its content width and the wheel or the box beside it. When the
  box and its strip do not fit beside the proxy, they go under it. Before,
  the strip ran past the panel and was as tall as the room.
- Align panel, Properties panel's Align row, Control bar's Align strip and
  paragraph row, Paragraph panel's lists row, and the gradient stop
  editor's two rows are a Row. They lay out as before.
This commit is contained in:
dotCooCoo
2026-11-24 16:00:20 -08:00
parent 8e7a6142fc
commit 9fe7bd19c5
8 changed files with 90 additions and 35 deletions
+3 -3
View File
@@ -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);
+2
View File
@@ -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;
+7 -6
View File
@@ -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<Item = Button>) -> 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<Value
/// from the command layer ([`button_enabled`], [`run_button`]).
pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
crate::panels::subheading(tl!("Align Objects:")).show(ui, |ui, _| {
ui.horizontal(|ui| {
Row::new().show(ui, |ui, _| {
for (icon, b) in align_icons() {
command_button(ui, icon, b);
}
});
});
crate::panels::subheading(tl!("Distribute Objects:")).show(ui, |ui, _| {
ui.horizontal(|ui| {
Row::new().show(ui, |ui, _| {
for (icon, b) in distribute_icons() {
command_button(ui, icon, b);
}
@@ -524,7 +525,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let min_spacing = spacing_min(app);
let mut edited = None;
crate::panels::subheading(tl!("Distribute Spacing:")).show(ui, |ui, _| {
ui.horizontal(|ui| {
Row::new().show(ui, |ui, _| {
command_button(ui, "dc-dist-vspace", Button::Spacing("vertical"));
command_button(ui, "dc-dist-hspace", Button::Spacing("horizontal"));
// The value is UI state, not a document edit: a landed value is assigned.
@@ -541,7 +542,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
crate::panels::subheading(tl!("Align To:")).show(ui, |ui, _| {
// With one object selected the buttons align it to the artboard, and Align To shows Artboard.
let anchor = key_is_anchor(app);
ui.horizontal(|ui| {
Row::new().show(ui, |ui, _| {
for (id, v) in ALIGN_TO_COMMANDS {
let (icon, _) = align_to_icon_name(v, anchor);
ToggleButton::command(CommandRef::new(id)).icon(IconId::new(icon)).icon_only().show(ui);
+3 -2
View File
@@ -16,7 +16,8 @@ use craft::theme::variant::Tone;
use craft::theme::{ModelValues, Rgba, Srgba};
use craft::ui::buttons::IconButton;
use craft::ui::choice::{SwatchSpacing, SwatchTable};
use craft::ui::contract::{Bind, CollectionEvent, Entry, Props as _, Show as _, ShowCollection as _};
use craft::ui::contract::{Bind, CollectionEvent, Entry, Props as _, Show as _, ShowCollection as _, ShowContainer as _};
use craft::ui::layout_components::Row;
use craft::ui::list::{List, ListRow, ThumbSize};
use craft::ui::menu::PanelRow;
use craft::ui::notices::Notice;
@@ -518,7 +519,7 @@ fn create(app: &mut VectorcraftApp, ui: &mut Ui) {
d.sel = i;
}
sliders(ui, &mut d, &mut mode, &mut held);
ui.horizontal(|ui| {
Row::new().show(ui, |ui, _| {
let hex = d.colors.get(d.sel).map(hex_rgba).unwrap_or(Rgba::rgb(0, 0, 0));
let mut edited = hex;
HexField::hex(tl!("Color"), Bind::bound(&mut edited)).show(ui);
+26 -18
View File
@@ -48,6 +48,7 @@ use std::sync::Arc;
// PLAN: assumed `craft-color-ui`, `craft-theme`, `craft-behavior` and `craft-keymap` are dependencies of
// vectorcraft-ui-egui (Cargo.toml is not in this set's table); `craft_ui` does not re-export them at the base.
use craft::behavior::ColumnWidth;
use craft::behavior::Mixed;
use craft::behavior::Selection;
use craft::color_ui::AreaMode;
@@ -57,7 +58,8 @@ use craft::theme::{ColorModel, HsbModel, ModelValues, RgbModel, Srgba};
use craft::ui::choice::{SwatchSpacing, SwatchTable};
use craft::ui::contract::{ActivateOn, Bind, EditResponse, Props as _, Show as _, ShowContainer as _};
use craft::ui::display::{Shade, Text};
use craft::ui::layout_components::Stack;
use craft::ui::layout::CellAlign;
use craft::ui::layout_components::{Grid, Row, Stack};
use craft::ui::menu::PanelRow;
use craft::ui::runtime::commands::{CommandState, CommandStates};
use craft::ui::runtime::env::Label;
@@ -78,6 +80,10 @@ use crate::edits::{EditPath, apply_edits};
pub const ID: &str = "colorWheel";
/// The columns of the panel's top row: the proxy as wide as its content, and the wheel or the box beside it in the
/// rest of the width.
const BESIDE: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::fill(1.0)];
/// What the panel shows right of the proxy: the wheel, or the box (a color field and a channel
/// strip).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
@@ -1107,29 +1113,32 @@ fn show_with(app: &mut VectorcraftApp, panel: &mut WheelUi, ui: &mut Ui) {
let cx = Pick { tgt: &tgt, color, cms: &cms, behind, cmyk_doc, shown: hsb };
let set = app.ui.color_wheel.clone();
let now = ui.input(|i| i.time);
ui.horizontal_top(|ui| {
ui.vertical(|ui| super::proxy(app, ui));
// The stack's gap separates the rows.
Stack::new().show(ui, |ui, _| show_rows(app, panel, ui, &cx, &set, now));
}
/// The panel's rows: the Fill/Stroke proxy beside the box or the wheel, level with its top, then the slider rows,
/// the color vision row and the document colors row that `set` turns on.
fn show_rows(app: &mut VectorcraftApp, panel: &mut WheelUi, ui: &mut Ui, cx: &Pick, set: &Settings, now: f64) {
Grid::new(&BESIDE).cells(CellAlign::Top).show(ui, |ui, _| {
super::proxy(app, ui);
match set.view {
View::Box => 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);
}
}
+4 -3
View File
@@ -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<u32
/// turns the list off, and the one every paragraph has is checked. More Options after them opens
/// Bullets and Numbering on the kind's tab.
fn lists_row(app: &mut VectorcraftApp, ui: &mut Ui) {
ui.horizontal(|ui| {
Row::new().show(ui, |ui, _| {
let shown = bullets_shown(app);
match list_control(ui, ListKind::Bullets, matches!(shown, Some(Some(_))), &bullet_entries(shown)) {
Some(ListEvent::Toggle) => toggle_list(app, ListKind::Bullets),
+7 -3
View File
@@ -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() {
@@ -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");
}