diff --git a/crates/draw/src/ui/connector/stories.rs b/crates/draw/src/ui/connector/stories.rs index 206149b57..1da818ca3 100644 --- a/crates/draw/src/ui/connector/stories.rs +++ b/crates/draw/src/ui/connector/stories.rs @@ -16,7 +16,8 @@ use super::{ ConnectionSite, ConnectionTarget, ConnectorBar, ConnectorEnd, ConnectorEvent, ConnectorHandles, ConnectorItem, ConnectorLine, ConnectorTool, }; use crate::geometry::connector::{ConnectionSide, RouteEnd, Routing, route, route_along}; -use crate::ui::stroke::{StrokeChoice, StrokeChoiceRow}; +use crate::ui::stroke::stories::paint_head; +use crate::ui::stroke::{ChoicePainter, StrokeChoice, StrokeChoiceRow}; craft_ui::words! { /// The status line of the Connector tool story. @@ -83,6 +84,11 @@ fn connector_glued_at_both_ends(ui: &mut Ui, data: &mut StoryData) -> StoryOutpu on_canvas(ui, &targets, |ui, at| ConnectorHandles::new("Connector", Bind::bound(&mut *item), &targets).show_at(ui, at)) } +/// The arrowhead previews of the cap choices, at the line's start or end. +fn heads(at_end: bool) -> ChoicePainter<'static> { + ChoicePainter::new(move |cx, rect, choice| paint_head(cx, rect, if choice.id == "dot" { "circle" } else { &choice.id }, at_end)) +} + fn caps() -> Vec { vec![StrokeChoice::new("none", "None"), StrokeChoice::new("arrow", "Arrow"), StrokeChoice::new("dot", "Dot")] } @@ -92,8 +98,8 @@ fn connector_bar_for_one_connector(ui: &mut Ui, _: &mut StoryData) -> StoryOutpu let choices = caps(); Bar::new("Options", BarKind::Options) .show(ui, |ui, _| { - let start = StrokeChoiceRow::new("start", "Start", &choices).selected(Mixed::Same("none")); - let end = StrokeChoiceRow::new("end", "End", &choices).selected(Mixed::Same("arrow")); + let start = StrokeChoiceRow::new("start", "Start", &choices).paint(heads(false)).selected(Mixed::Same("none")); + let end = StrokeChoiceRow::new("end", "End", &choices).paint(heads(true)).selected(Mixed::Same("arrow")); let _ = ConnectorBar::new(Mixed::Same(Routing::Elbow), Mixed::Same(ConnectorLine::default())).caps(start, end).show(ui); }) .output @@ -105,8 +111,8 @@ fn connector_bar_for_a_mixed_selection(ui: &mut Ui, _: &mut StoryData) -> StoryO let choices = caps(); Bar::new("Options", BarKind::Options) .show(ui, |ui, _| { - let start = StrokeChoiceRow::new("start", "Start", &choices).selected(Mixed::Mixed); - let end = StrokeChoiceRow::new("end", "End", &choices).selected(Mixed::Same("arrow")); + let start = StrokeChoiceRow::new("start", "Start", &choices).paint(heads(false)).selected(Mixed::Mixed); + let end = StrokeChoiceRow::new("end", "End", &choices).paint(heads(true)).selected(Mixed::Same("arrow")); let _ = ConnectorBar::new(Mixed::Mixed, Mixed::Mixed).caps(start, end).show(ui); }) .output diff --git a/crates/draw/src/ui/stroke/mod.rs b/crates/draw/src/ui/stroke/mod.rs index 752b79053..36ee64af3 100644 --- a/crates/draw/src/ui/stroke/mod.rs +++ b/crates/draw/src/ui/stroke/mod.rs @@ -9,7 +9,7 @@ mod button; mod editor; mod preview; #[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod stories; mod words; use std::ops::BitOr; @@ -205,7 +205,7 @@ impl<'a> StrokeChoiceRow<'a> { self } - /// Paints each choice's preview beside its name, in the select's list. + /// Paints each choice's preview: in the select's list beside its name, and on its closed face. pub fn paint(mut self, paint: ChoicePainter<'a>) -> Self { self.paint = Some(paint); self diff --git a/crates/draw/src/ui/stroke/stories.rs b/crates/draw/src/ui/stroke/stories.rs index 85a4332bc..b58821a3e 100644 --- a/crates/draw/src/ui/stroke/stories.rs +++ b/crates/draw/src/ui/stroke/stories.rs @@ -95,7 +95,7 @@ fn stroke_editor_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { } /// The arrowhead `id` at one end of the line through `rect`. -fn paint_head(cx: &ContentPainterCx, rect: Rect, id: &str, at_end: bool) { +pub(crate) fn paint_head(cx: &ContentPainterCx, rect: Rect, id: &str, at_end: bool) { let ink = cx.ink(); let line = rect.height() * HEAD_LINE_SHARE; let y = rect.center().y;