diff --git a/crates/ui-egui/src/edit_toolbar.rs b/crates/ui-egui/src/edit_toolbar.rs index b28d341a57..93218a35b6 100644 --- a/crates/ui-egui/src/edit_toolbar.rs +++ b/crates/ui-egui/src/edit_toolbar.rs @@ -23,6 +23,7 @@ use craft::behavior::IconId; use craft::behavior::overlay::Side; use craft::ui::buttons::ToggleButton; use craft::ui::contract::{Bind, Outcome as _, Show as _, ShowContainer as _}; +use craft::ui::form::Field; use craft::ui::layout_components::Row; use craft::ui::menu::PanelRow; use craft::ui::primitives::IconSpec; @@ -462,14 +463,17 @@ pub(crate) fn drawer(app: &mut VectorcraftApp, ui: &mut Ui, rail_out: &ToolRailO if target.is_some() { return; } - Row::new().show(ui, |ui, _| { - for (name, label, icon) in crate::state::ToolbarShow::CONTROLS { - let on = shown.get(name); - let button = ToggleButton::new(tl!(label), Bind::given(on)).icon(IconSpec::svg(IconId::new(icon))).icon_only(); - if button.show(ui).response().clicked() { - toggled = Some(name); + // The toggles are labeled "Show:", as production's were, so the row says what its icons turn on and off. + Field::new(tl!("Show:")).show(ui, |ui, _| { + Row::new().show(ui, |ui, _| { + for (name, label, icon) in crate::state::ToolbarShow::CONTROLS { + let on = shown.get(name); + let button = ToggleButton::new(tl!(label), Bind::given(on)).icon(IconSpec::svg(IconId::new(icon))).icon_only(); + if button.show(ui).response().clicked() { + toggled = Some(name); + } } - } + }); }); }); diff --git a/crates/ui-egui/src/edit_toolbar/tests.rs b/crates/ui-egui/src/edit_toolbar/tests.rs index b01ac1a4bb..38bced56ed 100644 --- a/crates/ui-egui/src/edit_toolbar/tests.rs +++ b/crates/ui-egui/src/edit_toolbar/tests.rs @@ -142,6 +142,25 @@ fn toolbar_show_turns_the_controls_under_the_tools_on_and_off() { assert_eq!(serde_json::from_value::(old).unwrap().toolbar_show, crate::state::ToolbarShow::default()); } +/// The drawer's Show toggles are labeled: they sit in a field named "Show" whose label comes before them. +#[test] +fn the_drawer_labels_its_show_toggles() { + let mut app = app(); + let ctx = ctx(); + settle(&mut app, &ctx, 0.0); + app.run("window.editToolbar", json!({"open": true})).unwrap(); + let nodes = settle(&mut app, &ctx, 1.0); + let open = drawer(&nodes); + let first = inside(&nodes, "Fill and Stroke Controls", open); + let label = named(&nodes, "Show") + .into_iter() + .chain(named(&nodes, "Show:")) + .find(|r| open.contains(r.center())) + .unwrap_or_else(|| panic!("the drawer shows a Show label: {:?}", nodes.iter().filter(|(_, r)| open.contains(r.center())).collect::>())); + assert!(label.expand(0.5).contains_rect(first), "the Show field {label:?} holds the toggles {first:?}"); + assert!(label.left() < first.left(), "the Show label in {label:?} comes before the toggles {first:?}"); +} + /// Every tool is listed once, under a heading; the Basic toolbar's groups come first, in its order. #[test] fn every_tool_is_listed_once_under_a_heading() { diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index d90dbd96c0..12816cead4 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -718,10 +718,11 @@ fn quad_bounds(quad: &[Point; 4]) -> vectorcraft_geom::Rect { /// The Fill/Stroke proxy, Color/Gradient/None, the drawing modes and screen mode under the rail's /// tools: in two columns the three drawing modes show, in one only the current one, which cycles /// them. A row the rail is too narrow for goes on in the next line. The All Tools drawer's Show -/// section hides any of them. +/// section hides any of them. A rule above them parts them from the tools, which scroll above it in a short rail. fn bottom_controls(app: &mut VectorcraftApp, ui: &mut Ui, footer: RailFooter) { let two = footer.columns > 1; let show = app.ui.toolbar_show; + Divider::horizontal().show(ui); if show.fill_stroke { crate::panels::proxy(app, ui); } @@ -734,7 +735,8 @@ fn bottom_controls(app: &mut VectorcraftApp, ui: &mut Ui, footer: RailFooter) { ]; let fallback = crate::panels::srgba(&app.session.last_solid); let mut clicked = None; - Row::new().wrap(true).show(ui, |ui, _| { + // A tight gap apart, as the drawing modes, so the three share one line in a one-column rail. + Row::new().gap(Gap::Tight).wrap(true).show(ui, |ui, _| { for (label, cmd, paint) in &chips { let shown = Mixed::Same(well_paint(paint, &|_| None)); let out = diff --git a/crates/ui-egui/src/toolbar/tests.rs b/crates/ui-egui/src/toolbar/tests.rs index 6e2eeea570..0fce71aecf 100644 --- a/crates/ui-egui/src/toolbar/tests.rs +++ b/crates/ui-egui/src/toolbar/tests.rs @@ -306,6 +306,40 @@ fn the_paint_and_drawing_mode_buttons_fit_the_toolbar_width() { assert_eq!(app.session.draw_mode, vectorcraft_engine::DrawMode::Behind); } +/// In one column the Color, Gradient and None chips share one line, and a rule across the rail parts the controls under +/// the tools from the tools, which scroll above them in a short rail: it lies between the last tool and Fill and +/// Stroke. +#[test] +fn the_controls_under_the_tools_share_a_line_under_a_rule() { + let mut app = app_with(200, 200); + let ctx = reader(); + app.run("window.toolbarColumns", json!({ "double": false })).unwrap(); + let nodes = settled(&mut app, &ctx, 0.0, 2000.0); + let chips = ["Color (, or Shift+,)", "Gradient (. or Shift+.)", "None (/)"].map(|label| named_rect(&nodes, label)); + assert!(chips.iter().all(|r| (r.top() - chips[0].top()).abs() < 0.5), "one line: {chips:?}"); + let last = cells(&app, &nodes).into_iter().max_by(|a, b| a.bottom().total_cmp(&b.bottom())).expect("the rail shows tools"); + let proxy = named_rect(&nodes, "Fill and Stroke"); + let screen_rect = Some(egui::Rect::from_min_size(Pos2::ZERO, egui::vec2(1200.0, 2000.0))); + let out = crate::testing::app_frame(&mut app, &ctx, egui::RawInput { time: Some(1.0), screen_rect, ..Default::default() }); + let mut flat = Vec::new(); + let mut stack: Vec = out.shapes.into_iter().map(|clipped| clipped.shape).collect(); + while let Some(shape) = stack.pop() { + match shape { + egui::Shape::Vec(inner) => stack.extend(inner), + shape => flat.push(shape), + } + } + // A rule is a thin horizontal line or bar across most of the rail's width, between the tools and the controls. + let between = |y: f32| y > last.bottom() && y < proxy.top(); + let across = |left: f32, right: f32| right - left >= last.width() * 0.75 && left < last.right() && right > last.left(); + let ruled = flat.iter().any(|shape| match shape { + egui::Shape::LineSegment { points: [a, b], .. } => (a.y - b.y).abs() < 0.5 && between(a.y) && across(a.x.min(b.x), a.x.max(b.x)), + egui::Shape::Rect(r) => r.rect.height() <= 2.0 && between(r.rect.center().y) && across(r.rect.left(), r.rect.right()), + _ => false, + }); + assert!(ruled, "a rule lies between the last tool {last:?} and Fill and Stroke {proxy:?}"); +} + /// A screen reader reads the drawing-mode buttons' state as the rail shows it, in every mode: in two columns the /// current mode's button reads pressed and the other two not pressed; in one column the single button is named for the /// current mode and cycles the modes, so it reads as a plain button with no pressed state.