diff --git a/crates/ui-egui/src/panels/appearance.rs b/crates/ui-egui/src/panels/appearance.rs index c4470a4f92..0591631dff 100644 --- a/crates/ui-egui/src/panels/appearance.rs +++ b/crates/ui-egui/src/panels/appearance.rs @@ -44,7 +44,7 @@ use craft::ui::primitives::IconSpec; use craft::ui::runtime::commands::{CommandRef, CommandState, CommandStates}; use craft::ui::runtime::env::Label; use craft::ui::sections::{FooterAction, FooterBar}; -use craft::ui::text::NumberOutput; +use craft::ui::text::{NumberField, NumberOutput}; use egui::{Rect, Ui, vec2}; use serde_json::{Value, json}; use vectorcraft_color::{BlendMode, Paint}; @@ -860,11 +860,9 @@ fn item_row<'r>(cx: &'r RowCx<'_>, key: RowKey, i: usize) -> ListRow<'r> { if let Some(st) = stroke_layer { let target = if new_art { WeightTarget::Shown } else { WeightTarget::Item(i) }; let pass = cx.pass; - row = row.trailing_field(stroke::weight_number(cx.app, Some(st.width)), move |out| { - pass.borrow_mut().acts.push(Act::Weight(target, Box::new(out))) - }); + row = row.trailing_field(row_weight(cx.app, Some(st.width)), move |out| pass.borrow_mut().acts.push(Act::Weight(target, Box::new(out)))); } else { - row = row.trailing_space(stroke::weight_number(cx.app, None)); + row = row.trailing_space(row_weight(cx.app, None)); } let painted = if new_art { Painted::NewArt { fill } } else { Painted::Item(i) }; let pass = cx.pass; @@ -892,6 +890,13 @@ fn paint_swatch(fill: bool, paint: &Paint) -> Swatch { .tooltip(tl!("Click to choose a swatch, Shift-click to mix a colour")) } +/// The weight field of a stroke row, or the room it takes in a fill row: the Stroke panel's field as a small control, +/// as the row's swatch is, without the presets list (a step still stops at each preset), so the row's label shows +/// whole in the narrowest group. +fn row_weight(app: &VectorcraftApp, weight: Option) -> NumberField<'static> { + stroke::steps_weight(app, weight).size(ControlSize::Sm) +} + /// A stroke row's notes after the weight: its brush and "Dashed". fn stroke_notes(st: &vectorcraft_doc::StrokeLayer) -> Option { let dashed = st.dash.as_ref().is_some_and(|d| d.is_dashed()).then_some(tl!("Dashed")); diff --git a/crates/ui-egui/src/panels/appearance/tests.rs b/crates/ui-egui/src/panels/appearance/tests.rs index 97a76b420f..5e5a4fc5b4 100644 --- a/crates/ui-egui/src/panels/appearance/tests.rs +++ b/crates/ui-egui/src/panels/appearance/tests.rs @@ -677,6 +677,34 @@ fn an_appearance_row_held_across_file_revert_is_not_dropped_on_the_footer() { assert_eq!(items(&panel), before + 1, "a drag started after the revert still duplicates the row"); } +/// A floating group at the narrowest panel width shows the "Stroke:" and "Fill:" links whole, as wide as a wide group +/// shows them: the stroke weight beside them is a small field inside the panel, and the stroke and fill swatches still +/// stand in one column. +#[test] +fn the_narrowest_group_shows_the_stroke_and_fill_labels_whole() { + use crate::panel_docking::PANEL_MIN_WIDTH; + use crate::tests::panel_harness::{Place, floated}; + let one = |shown: &crate::tests::panel_harness::Shown, name: &str, width: f32| { + let rects = shown.rects(name); + assert_eq!(rects.len(), 1, "one {name:?} at {width} pt: {rects:?}"); + rects[0] + }; + let links = |width: f32| { + let shown = floated(app_with_a_selected_rectangle(), "appearance", "en", Place::Floating(width), &["Stroke:", "Fill:"]); + let [stroke, fill] = ["Stroke:", "Fill:"].map(|name| one(&shown, name, width).width()); + let [stroke_well, fill_well] = ["Stroke swatch", "Fill swatch"].map(|name| one(&shown, name, width).left()); + assert!((stroke_well - fill_well).abs() < 0.5, "the swatches stand at {stroke_well} and {fill_well} pt at {width} pt"); + let weight = one(&shown, "Weight", width); + assert!(shown.body.contains_rect(weight), "the weight field {weight:?} stands inside the panel {:?} at {width} pt", shown.body); + ([stroke, fill], format!("stroke swatch at {stroke_well} pt, weight {weight:?}")) + }; + let (wide, _) = links(400.0); + let (narrow, row) = links(PANEL_MIN_WIDTH); + for (at, name) in ["Stroke:", "Fill:"].iter().enumerate() { + assert!(narrow[at] >= wide[at] - 0.5, "{name:?} is {} pt wide at {PANEL_MIN_WIDTH} pt and {} pt at 400 pt ({row})", narrow[at], wide[at]); + } +} + /// The panel's subject is the `Arc` the document holds for the selected object, a targeted group /// or a targeted layer, not a copy of it; nothing with nothing selected. #[test] diff --git a/crates/ui-egui/src/panels/stroke.rs b/crates/ui-egui/src/panels/stroke.rs index 15b3e438cc..7ea1db6e49 100644 --- a/crates/ui-egui/src/panels/stroke.rs +++ b/crates/ui-egui/src/panels/stroke.rs @@ -301,10 +301,19 @@ static BLANK_WEIGHT_STOPS: [f64; 2] = [0.25, 0.5]; /// 0 pt); Shift or Page steps the grid by ten. // PLAN: the sheet names `NumberField<'static, f64>`; `NumberField::length` takes `Option`. pub(crate) fn weight_number(app: &VectorcraftApp, weight: Option) -> NumberField<'static> { + let field = steps_weight(app, weight); + match weight_ladder(app) { + Some(l) => field.presets(&l.rows), + None => field, + } +} + +/// [`weight_number`] without the presets list: a plain step still stops at each preset. +pub(crate) fn steps_weight(app: &VectorcraftApp, weight: Option) -> NumberField<'static> { let unit = app.session.stroke_unit(); let lengths = crate::fields::bare_points(LengthUnits::new(UnitKind::Points, shown_kind(unit), 72.0), app.session.prefs.numbers_without_units_are_points); - let ladder = LADDERS.iter().find(|(u, _)| *u == unit).or_else(|| LADDERS.iter().find(|(u, _)| *u == Unit::Points)).map(|(_, l)| l); + let ladder = weight_ladder(app); let field = NumberField::length(tl!("Weight"), Bind::given(weight), lengths).range(0.0..=1000.0).step_arrows(StepArrows::Leading).scrub_by_label(); // The stepper steps the number the field shows; the ladders are in points. @@ -315,12 +324,18 @@ pub(crate) fn weight_number(app: &VectorcraftApp, weight: Option) -> Number match ladder { // A blank weight (the selected objects differ) steps in points from 0.25 pt, whatever the unit's ladder: up // gives 0.5 pt, down 0 pt (#5349). - Some(l) if weight.is_none() => field.presets(&l.rows).stepper(in_points(&BLANK_WEIGHT_STOPS, true)), - Some(l) => field.presets(&l.rows).stepper(in_points(&l.stops, false)), + Some(_) if weight.is_none() => field.stepper(in_points(&BLANK_WEIGHT_STOPS, true)), + Some(l) => field.stepper(in_points(&l.stops, false)), None => field, } } +/// The ladder of the stroke unit the session shows, or of points. +fn weight_ladder(app: &VectorcraftApp) -> Option<&'static Ladder> { + let unit = app.session.stroke_unit(); + LADDERS.iter().find(|(u, _)| *u == unit).or_else(|| LADDERS.iter().find(|(u, _)| *u == Unit::Points)).map(|(_, l)| l) +} + /// Sends a weight edit of `out` to `target`: a scrub or slider drag is one undo step, a typed, stepped or picked /// value commits at once, and while the Type tool edits text the weight goes to the selected characters. pub(crate) fn apply_weight(app: &mut VectorcraftApp, out: &NumberOutput, target: WeightTarget) {