ConnectorBar stories paint the cap choices, so the pictures show in the list and on the faces

This commit is contained in:
aiongg
2026-11-12 14:32:46 +00:00
parent 12208bee3a
commit cfaf7074cf
3 changed files with 14 additions and 8 deletions
+11 -5
View File
@@ -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<StrokeChoice> {
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
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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;