widgets-w6: net change of 1 commits

- widgets-w6: written from its sheet
This commit is contained in:
bflatastic
2026-11-21 21:26:53 +07:00
parent aff9ce717f
commit 73aa434890
6 changed files with 447 additions and 128 deletions
+168 -58
View File
@@ -6,17 +6,19 @@ use craft_ui::buttons::IconButton;
use craft_ui::choice::{ChoiceWords, Swatch, SwatchMetrics, SwatchStyle};
use craft_ui::contract::{
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Focus as _, MeasureCx, Meta as _, Outcome, Overlay, OverlayUi,
Overlays as _, PaintUi, PartsCx, Pointer as _, Props as _, Remember as _, Role, WordSetCx as _,
DragPreview, DropMark, DropOperation, DropTarget, Overlays as _, PaintUi, PartsCx, Pointer as _, Props as _, Remember as _, Role,
WordSetCx as _,
};
use craft_ui::primitives::{DataWidth, Draw, Glyph, IconSpec, PaintShape, StrokeWidth};
use craft_ui::primitives::{Glyph, IconSpec, PaintShape, StrokeWidth};
use craft_ui::runtime::commands::FireSource;
use craft_ui::runtime::env::Label;
use craft_ui::style::{ComponentStyle, DataColor, Flags, FocusLook, GlyphRole, StyleColor, StyleCx, SurfaceEdge, SurfaceStyle, UiTokens};
use craft_ui::style::{ComponentStyle, Flags, FocusLook, GlyphRole, StyleColor, StyleCx, SurfaceEdge, SurfaceStyle, UiTokens};
use egui::emath::GuiRounding as _;
use egui::{Color32, CornerRadius, Painter, Pos2, Rect, Response, Shape, Stroke, StrokeKind, Vec2, pos2, vec2};
use super::paint_chip::{WellLook, paint_well};
use super::popover::compact_picker;
use super::{ColorPicker, Paint, PickedColor, ScreenPickGesture};
use super::{ColorPicker, Paint, PaintWords, PickedColor, ScreenPickGesture};
#[cfg(feature = "screen-testing")]
mod stories;
@@ -27,8 +29,6 @@ const WELL: PartKey = PartKey::new("well");
const DEFAULT: PartKey = PartKey::new("default");
/// The Swap Colours button.
const SWAP: PartKey = PartKey::new("swap");
/// A ring well's band, as a share of the well's side.
const RING_SHARE: f32 = 0.3;
/// One of a [`SwatchPair`]'s wells. The primary one is at the start, top, the secondary one is
/// offset towards the end and down: foreground and background, or fill and stroke.
@@ -86,17 +86,7 @@ impl PairWell {
/// A well named `label` showing any paint through `paint_well`; `Mixed::Mixed` for a selection whose paints differ.
/// A ring well clips the face to its band; the popover picker starts from the solid colour or the first stop.
pub fn paint(label: impl Into<Label>, paint: impl Into<Mixed<Paint>>) -> Self {
let _ = (label, paint);
todo!("wg.W48")
}
/// The well's solid colour; `Mixed` for a paint that is not solid.
// P3(widgets-w6): wg.W48
fn color(&self) -> Mixed<Srgba> {
match &self.paint {
Mixed::Same(Paint::Solid(color)) => Mixed::Same(*color),
_ => Mixed::Mixed,
}
Self { label: label.into(), paint: paint.into(), ring: false }
}
/// Draws the well as a ring (a stroke, as DesignCraft's stroke well) instead of a filled square. The middle shows
@@ -138,10 +128,14 @@ pub struct SwatchPairStyle {
mark: StyleColor,
/// A swatch's look, for the lines that stand out from a ring well's colour.
swatch: SwatchStyle,
/// The No Color well's fill: the paint chip's.
none_fill: StyleColor,
/// The No Color well's diagonal: the paint chip's.
none_mark: StyleColor,
}
/// What a [`SwatchPair`]'s wells take of a dragged payload: `SwatchPair::accepts`.
pub struct DropAccepts<'a, P>(#[allow(dead_code)] Box<dyn Fn(Well, &P) -> bool + 'a>); // P3(widgets-w6): wg.W49
pub struct DropAccepts<'a, P>(Box<dyn Fn(Well, &P) -> bool + 'a>);
impl<'a, P> DropAccepts<'a, P> {
/// A test that runs `accepts` on the well and the payload.
@@ -231,7 +225,7 @@ impl<P> Outcome for SwatchPairOutput<P> {
/// - The wells are one roving group: Tab arrives at the active well; Left and Up go to the primary one, Right and
/// Down to the secondary one (mirrored right to left).
#[derive(craft_ui::contract::Component, craft_ui::contract::Props)]
#[component(overlay, probe(SwatchPair<'static, u8>))]
#[component(overlay, content_painter, probe(SwatchPair<'static, u8>))]
pub struct SwatchPair<'a, P: Clone + Send + Sync + 'static = ()> {
#[common]
common: Common,
@@ -260,11 +254,12 @@ pub struct SwatchPair<'a, P: Clone + Send + Sync + 'static = ()> {
#[prop(func = "Fn(ColorPicker<'a>) -> ColorPicker<'a>")]
picker: Option<PickerSetup<'a>>,
/// The payload each well drags past the slop (`None`: that well drags nothing).
#[prop]
drags: Option<[Option<P>; 2]>,
/// What each well accepts of a dragged payload: the well is a drop target for the payloads this allows.
#[prop(func = "Fn(Well, &P) -> bool")]
accepts: Option<DropAccepts<'a, P>>,
dropped: Option<(Well, P)>,
over: Option<Well>,
clicked: Option<Well>,
double_clicked: Option<Well>,
activated: bool,
@@ -275,7 +270,7 @@ pub struct SwatchPair<'a, P: Clone + Send + Sync + 'static = ()> {
screen_pick: Option<ScreenPickGesture>,
}
impl<'a, P: Clone + Send + Sync + 'static> SwatchPair<'a, P> {
impl<'a> SwatchPair<'a, ()> {
/// A pair named `label` of `wells`, primary first; `active` is the well in front.
pub fn new(label: impl Into<Label>, wells: [PairWell; 2], active: Bind<'a, Well>) -> Self {
SwatchPair {
@@ -291,6 +286,8 @@ impl<'a, P: Clone + Send + Sync + 'static> SwatchPair<'a, P> {
picker: None,
drags: None,
accepts: None,
dropped: None,
over: None,
clicked: None,
double_clicked: None,
activated: false,
@@ -303,6 +300,42 @@ impl<'a, P: Clone + Send + Sync + 'static> SwatchPair<'a, P> {
.label(label)
}
/// The payload each well drags past the slop, primary first (`None`: that well drags nothing); a mixed well drags
/// nothing whatever it is given. Set before `accepts`, which is typed by the payload.
pub fn drags<Q: Clone + Send + Sync + 'static>(self, payloads: [Option<Q>; 2]) -> SwatchPair<'a, Q> {
SwatchPair {
common: self.common,
wells: self.wells,
active: self.active,
swap_button: self.swap_button,
default_button: self.default_button,
popover: self.popover,
click_activates: self.click_activates,
frame_active: self.frame_active,
sampled: self.sampled,
picker: self.picker,
drags: Some(payloads),
accepts: None,
dropped: None,
over: None,
clicked: self.clicked,
double_clicked: self.double_clicked,
activated: self.activated,
swap: self.swap,
defaults: self.defaults,
edit: self.edit,
edited: self.edited,
screen_pick: self.screen_pick,
}
}
}
impl<'a, P: Clone + Send + Sync + 'static> SwatchPair<'a, P> {
/// The payload well `i` drags: none for a well without one or a mixed one.
fn payload(&self, i: usize) -> Option<&P> {
self.drags.as_ref()?[i].as_ref().filter(|_| self.wells[i].paint.same().is_some())
}
fn has_buttons(&self) -> bool {
self.swap_button.is_some() || self.default_button.is_some()
}
@@ -340,6 +373,12 @@ impl<'a, P: Clone + Send + Sync + 'static> SwatchPair<'a, P> {
let secondary = Rect::from_min_size(pos2(end - style.well, top + style.step), square);
[primary, secondary]
}
/// The wells' rects inside `rect` on screen, primary first.
fn placed(&self, style: &SwatchPairStyle, rect: Rect, rtl: bool) -> [Rect; 2] {
let flow = Flow::new(rect, rtl);
self.well_rects(style, rect.size()).map(|logical| flow.to_physical(logical.translate(rect.min.to_vec2())))
}
}
impl<P: Clone + Send + Sync + 'static> Component for SwatchPair<'_, P> {
@@ -366,6 +405,8 @@ impl<P: Clone + Send + Sync + 'static> Component for SwatchPair<'_, P> {
outline: cx.tokens.stroke.thin,
frame: cx.color(colors.text.muted),
mark: cx.color(colors.text.normal),
none_fill: cx.color(colors.surface.sunken),
none_mark: cx.color(colors.status.bad.solid),
swatch: Swatch::style(cx, Swatch::new(Label::default(), Srgba::BLACK).style_key()),
}
}
@@ -386,20 +427,20 @@ impl<P: Clone + Send + Sync + 'static> Component for SwatchPair<'_, P> {
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
let flow = Flow::new(rect, cx.flow.is_rtl());
let rects = self.well_rects(cx.style, rect.size());
let rects = self.placed(cx.style, rect, cx.flow.is_rtl());
let active = cx.value().copied().unwrap_or_default();
let on_top = self.front(active);
for (i, logical) in rects.into_iter().enumerate() {
for (i, at) in rects.into_iter().enumerate() {
let well = Well::of(i as u64);
let front = well == on_top;
let at = flow.to_physical(logical.translate(rect.min.to_vec2()));
let sense = if self.payload(i).is_some() { Sense::CLICK | Sense::FOCUS | Sense::DRAG } else { Sense::CLICK | Sense::FOCUS };
let mut flags = Flags::empty();
flags.set(Flags::MIXED, self.wells[i].color().same().is_none());
flags.set(Flags::MIXED, self.wells[i].paint.same().is_none());
flags.set(Flags::CHECKED, well == active);
let shape = if cx.style.round { HitShape::circle(at.center(), at.width() / 2.0) } else { HitShape::Rect(at) };
let part = cx
.part(WELL.at(i as u64), shape)
.sense(Sense::CLICK | Sense::FOCUS)
.sense(sense)
.priority(HitPriority::new(HitLevel::Body, u8::from(front)))
.flags(flags)
.focusable();
@@ -427,6 +468,11 @@ impl<P: Clone + Send + Sync + 'static> Component for SwatchPair<'_, P> {
for i in 0..2u64 {
let well = Well::of(i);
let press = cx.part(WELL.at(i)).press;
if matches!(press.phase, PressPhase::DragStart { .. })
&& let Some(payload) = self.payload(i as usize)
{
cx.start_drag(payload.clone(), DragPreview::None);
}
if let PressPhase::Release { start, click: true, .. } = press.phase {
self.clicked = Some(well);
if start.clicks >= 2 {
@@ -472,6 +518,19 @@ impl<P: Clone + Send + Sync + 'static> Component for SwatchPair<'_, P> {
cx.set(well);
self.activated = true;
}
if cx.resolved.enabled
&& let Some(DropAccepts(accepts)) = &self.accepts
{
let target = WellsTarget {
rects: self.placed(cx.style, cx.rect, cx.flow.is_rtl()),
front: self.front(active),
round: cx.style.round,
mixed: [0, 1].map(|i| self.wells[i].paint.same().is_none()),
accepts: &**accepts,
};
self.over = cx.dragging::<P>().and_then(|(payload, at)| target.takes(&payload, at));
self.dropped = cx.drop_target(&target);
}
}
fn overlay(&mut self, ui: &mut OverlayUi<'_>, cx: &mut Cx<'_, Self>) {
@@ -482,7 +541,7 @@ impl<P: Clone + Send + Sync + 'static> Component for SwatchPair<'_, P> {
let popup = cx.popup("picker");
let opened = cx.memory::<Opened>().0.map_or(Well::Primary, Well::of);
let well = &self.wells[opened.index() as usize];
let (color, name) = (*well.color().or(&Srgba::BLACK), well.label.clone());
let (color, name) = (solid_of(&well.paint), well.label.clone());
let setup = self.picker.as_ref();
let sampled = self.sampled;
let shown = ui.show(popup, Overlay::popover(), |ui, _| {
@@ -501,8 +560,8 @@ impl<P: Clone + Send + Sync + 'static> Component for SwatchPair<'_, P> {
fn access(&self, access: &mut Access, cx: &Cx<'_, Self>) {
for (i, well) in self.wells.iter().enumerate() {
let value = match well.color().same() {
Some(color) => color.to_hex(),
let value = match well.paint.same() {
Some(paint) => paint_value(&cx.words::<PaintWords>(), paint),
None => cx.words::<ChoiceWords>().swatch_mixed.as_str().to_owned(),
};
// The two wells are a choice of the active colour: radios, the front one checked, with the colour as value.
@@ -512,10 +571,8 @@ impl<P: Clone + Send + Sync + 'static> Component for SwatchPair<'_, P> {
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
let style = cx.style;
let flow = Flow::new(cx.rect, cx.flow.is_rtl());
let rects = self.well_rects(style, cx.rect.size());
let rects = self.placed(style, cx.rect, cx.flow.is_rtl());
let active = cx.value().copied().unwrap_or_default();
let place = |logical: Rect| flow.to_physical(logical.translate(cx.rect.min.to_vec2()));
// The back well first, then the front one with a gap round it: being in front, or the frame, shows the active well.
// The gap is a patch of the surface the pair sits on (a panel, a tool rail's chrome), fill only. The back well's
// frame is painted before the front well, which covers it where they overlap.
@@ -527,24 +584,36 @@ impl<P: Clone + Send + Sync + 'static> Component for SwatchPair<'_, P> {
shadow: None,
..scope.surface(cx.env.surface())
});
let draw = ui.draw();
let front = self.front(active);
for well in [front.other(), front] {
let at = place(rects[well.index() as usize]);
let at = rects[well.index() as usize];
let shown = &self.wells[well.index() as usize];
if well == front {
draw.surface_styled(at.expand(style.gap), &ground);
ui.draw().surface_styled(at.expand(style.gap), &ground);
}
match shown.color().same() {
Some(color) if shown.ring => paint_ring(&draw, at, *color, style),
color => {
draw.swatch_well(at, style.radius, color.copied());
draw.stroke(&PaintShape::Rect(at, style.radius), StrokeWidth::Thin, style.mark);
draw.stroke(&outline(at, style), StrokeWidth::Thin, style.edge);
match shown.paint.same() {
Some(paint) => {
let look = WellLook {
none_fill: style.none_fill,
none_mark: style.none_mark,
edge: style.edge,
height: style.well,
radius: style.radius,
ring: shown.ring,
swatch: style.swatch.clone(),
};
paint_well(ui, cx, at, paint, &look);
}
None => ui.draw().swatch_well(at, style.radius, None),
}
// A ring well draws its own outlines.
if shown.paint.same().is_none() || !shown.ring {
let draw = ui.draw();
draw.stroke(&PaintShape::Rect(at, style.radius), StrokeWidth::Thin, style.mark);
draw.stroke(&outline(at, style), StrokeWidth::Thin, style.edge);
}
if self.frame_active && well == active {
draw.stroke(&frame(at, style), StrokeWidth::Thin, style.frame);
ui.draw().stroke(&frame(at, style), StrokeWidth::Thin, style.frame);
}
}
}
@@ -573,26 +642,67 @@ impl<P: Clone + Send + Sync + 'static> Component for SwatchPair<'_, P> {
screen_pick: self.screen_pick,
open,
choice: cx.edit_response(),
dropped: None,
over: None,
dropped: self.dropped,
over: self.over,
}
}
}
/// A ring well: a band of the colour round the edge, the middle open to what is behind. Each side of the band has the
/// outline and, inside it, a line that stands out from the colour.
fn paint_ring(draw: &Draw<'_>, at: Rect, color: Srgba, style: &SwatchPairStyle) {
let band = at.width() * RING_SHARE;
let line = style.outline;
let contrast = style.swatch.inner_edge(Some(color));
draw.stroke(&PaintShape::Rect(at, style.radius), DataWidth::points(band), DataColor::new(Color32::from(color)));
draw.stroke(&PaintShape::Rect(at, style.radius), StrokeWidth::Thin, contrast);
draw.stroke(&outline(at, style), StrokeWidth::Thin, style.edge);
let hole = at.shrink(band);
// The hole's corners are concentric with the well's: square for a square well, round for a round one.
let corner = |grow: f32| UiTokens::corner((f32::from(style.radius.nw) - band + grow).max(0.0));
draw.stroke(&PaintShape::Rect(hole.expand(2.0 * line), corner(2.0 * line)), StrokeWidth::Thin, contrast);
draw.stroke(&PaintShape::Rect(hole.expand(line), corner(line)), StrokeWidth::Thin, style.edge);
/// The one drop target of a pair: it takes a payload on the well under the pointer, the front well first where they
/// overlap, unless that well is mixed or `accepts` refuses the payload.
struct WellsTarget<'t, P> {
rects: [Rect; 2],
front: Well,
round: bool,
mixed: [bool; 2],
accepts: &'t dyn Fn(Well, &P) -> bool,
}
impl<P> WellsTarget<'_, P> {
fn well_at(&self, at: Pos2) -> Option<Well> {
[self.front, self.front.other()].into_iter().find(|well| {
let rect = self.rects[well.index() as usize];
if self.round { at.distance(rect.center()) <= rect.width() / 2.0 } else { rect.contains(at) }
})
}
/// The well that takes `payload` dropped at `at`.
fn takes(&self, payload: &P, at: Pos2) -> Option<Well> {
let well = self.well_at(at)?;
(!self.mixed[well.index() as usize] && (self.accepts)(well, payload)).then_some(well)
}
}
impl<P: Clone + Send + Sync + 'static> DropTarget<P> for WellsTarget<'_, P> {
type Drop = (Well, P);
fn accept(&self, payload: &P, at: Pos2, _: DropOperation) -> Option<(Well, P)> {
self.takes(payload, at).map(|well| (well, payload.clone()))
}
fn mark(&self, drop: &(Well, P)) -> DropMark {
DropMark::Into(self.rects[drop.0.index() as usize])
}
}
/// The colour a picker starts from for `paint`: a solid's colour, a gradient's first stop, else black.
fn solid_of(paint: &Mixed<Paint>) -> Srgba {
match paint.same() {
Some(Paint::Solid(color)) => *color,
Some(Paint::Gradient(gradient)) => gradient.stops.first().map_or(Srgba::BLACK, |stop| stop.1),
_ => Srgba::BLACK,
}
}
/// A well's value for a screen reader: the hex of a solid, else the kind of paint.
fn paint_value(words: &PaintWords, paint: &Paint) -> String {
match paint {
Paint::None => words.no_color.as_str().to_owned(),
Paint::Solid(color) => color.to_hex(),
Paint::Gradient(_) => words.gradient.as_str().to_owned(),
Paint::Pattern(_) => words.pattern.as_str().to_owned(),
Paint::Picture(_) => words.picture.as_str().to_owned(),
}
}
/// The frame round the active well `at`: a gap outside its outline, concentric with its corners.
+57 -21
View File
@@ -1,9 +1,11 @@
//! Stories of the swatch pair.
use super::{PairWell, SwatchPair, Well};
use crate::ui::{GradientPreview, Paint};
use craft_behavior::Mixed;
use craft_theme::Srgba;
use craft_ui::contract::{Bind, Show as _, Validity};
use craft_ui::contract::{Bind, Role, Show as _, ShowContainer as _, Validity};
use craft_ui::layout_components::Row;
use craft_ui::rails::{LastUsed, ToolRail, ToolSlot};
use craft_ui::runtime::env::Message;
use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, story};
@@ -36,10 +38,7 @@ fn editing(ui: &mut Ui, data: &mut StoryData, names: [&'static str; 2], start: [
let defaults = [Srgba::rgb(0.0, 0.0, 0.0), Srgba::rgb(1.0, 1.0, 1.0)];
let state = data.value("colors", Colors { active: Well::Primary, colors: start });
let wells = [PairWell::new(names[0], state.colors[0]), PairWell::new(names[1], state.colors[1]).ring(ring)];
let shown = SwatchPair::<()>::new("Colours", wells, Bind::bound(&mut state.active))
.swap_button("Swap colours")
.default_button("Default colours")
.show(ui); // P3(widgets-w6): wg.W49
let shown = SwatchPair::<()>::new("Colours", wells, Bind::bound(&mut state.active)).swap_button("Swap colours").default_button("Default colours").show(ui);
if shown.swap {
state.colors.swap(0, 1);
}
@@ -58,30 +57,26 @@ fn editing(ui: &mut Ui, data: &mut StoryData, names: [&'static str; 2], start: [
StoryOutput::from(shown).readout(readout)
}
#[story(SwatchPair<'static>, covers = [Default], drive = Drive::Custom(next_well))]
#[story(SwatchPair<'static, u8>, covers = [Default], drive = Drive::Custom(next_well))]
fn swatch_pair(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let black_white = [Srgba::rgb(0.0, 0.0, 0.0), Srgba::rgb(1.0, 1.0, 1.0)];
editing(ui, data, ["Foreground colour", "Background colour"], black_white, false)
}
#[story(SwatchPair<'static>, covers = [], drive = Drive::Never)]
#[story(SwatchPair<'static, u8>, covers = [], drive = Drive::Never)]
fn swatch_pair_ring(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
editing(ui, data, ["Fill colour", "Stroke colour"], [Srgba::rgb(0.2, 0.55, 0.8), Srgba::rgb(0.9, 0.35, 0.2)], true)
}
#[story(SwatchPair<'static>, covers = [], drive = Drive::Never)]
#[story(SwatchPair<'static, u8>, covers = [], drive = Drive::Never)]
fn swatch_pair_host_picker(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
SwatchPair::<()>::new("Colours", wells(false), Bind::bound(data.value("active", Well::Primary)))
.popover(false)
.click_activates(false)
.show(ui)
.into() // P3(widgets-w6): wg.W49
SwatchPair::<()>::new("Colours", wells(false), Bind::bound(data.value("active", Well::Primary))).popover(false).click_activates(false).show(ui).into()
}
#[story(SwatchPair<'static>, covers = [Mixed], drive = Drive::Never)]
#[story(SwatchPair<'static, u8>, covers = [Mixed], drive = Drive::Never)]
fn swatch_pair_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let wells = [PairWell::new("Fill", Mixed::<Srgba>::Mixed), PairWell::new("Stroke", Srgba::rgb(0.1, 0.3, 0.8)).ring(true)];
SwatchPair::<()>::new("Fill and stroke", wells, Bind::bound(data.value("active", Well::Primary))).show(ui).into() // P3(widgets-w6): wg.W49
SwatchPair::<()>::new("Fill and stroke", wells, Bind::bound(data.value("active", Well::Primary))).show(ui).into()
}
/// Opens the picker of the focused well with Enter.
@@ -91,20 +86,20 @@ fn open_picker(fixture: &mut Fixture) {
fixture.idle(4);
}
#[story(SwatchPair<'static>, covers = [Open], drive = Drive::Custom(open_picker))]
#[story(SwatchPair<'static, u8>, covers = [Open], drive = Drive::Custom(open_picker))]
fn swatch_pair_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
SwatchPair::<()>::new("Colours", wells(false), Bind::bound(data.value("active", Well::Primary))).show(ui).into() // P3(widgets-w6): wg.W49
SwatchPair::<()>::new("Colours", wells(false), Bind::bound(data.value("active", Well::Primary))).show(ui).into()
}
#[story(SwatchPair<'static>, covers = [Invalid], drive = Drive::Never)]
#[story(SwatchPair<'static, u8>, covers = [Invalid], drive = Drive::Never)]
fn swatch_pair_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let refuse_secondary =
|well: &Well| if *well == Well::Secondary { Validity::Refuse(Message::new("Only the foreground can be edited")) } else { Validity::Ok };
SwatchPair::<()>::new("Colours", wells(false), Bind::bound(data.value("active", Well::Secondary)).check(refuse_secondary)).show(ui).into() // P3(widgets-w6): wg.W49
SwatchPair::<()>::new("Colours", wells(false), Bind::bound(data.value("active", Well::Secondary)).check(refuse_secondary)).show(ui).into()
}
/// The pair in a tool rail's footer, as PhotoCraft's colour chips: the gap round the front well takes the rail's chrome.
#[story(SwatchPair<'static>, covers = [], drive = Drive::Never)]
#[story(SwatchPair<'static, u8>, covers = [], drive = Drive::Never)]
fn swatch_pair_tool_rail(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let active = data.value("active", Well::Primary);
let (slots, last): (Vec<ToolSlot<u8>>, LastUsed<u8>) = (Vec::new(), LastUsed::default());
@@ -112,7 +107,7 @@ fn swatch_pair_tool_rail(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let mut shown = None;
ToolRail::new("Tools", &slots, &0, &last).show_rail(ui, |ui, _| {
shown = Some(
SwatchPair::<()>::new("Colours", wells.clone(), Bind::bound(&mut *active)) // P3(widgets-w6): wg.W49
SwatchPair::<()>::new("Colours", wells.clone(), Bind::bound(&mut *active))
.popover(false)
.swap_button("Swap colours")
.default_button("Default colours")
@@ -121,3 +116,44 @@ fn swatch_pair_tool_rail(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
});
shown.map(StoryOutput::from).unwrap_or_default()
}
/// Wells that show a gradient and No Color, as squares and as rings.
#[story(SwatchPair<'static, u8>, covers = [], drive = Drive::Never)]
fn swatch_pair_paints(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let ramp = || Paint::Gradient(GradientPreview::new(vec![(0.0, Srgba::rgb(0.9, 0.3, 0.2)), (1.0, Srgba::rgb(0.2, 0.4, 0.9))]));
Row::new().show(ui, |ui, _| {
for ring in [false, true] {
let wells = [PairWell::paint("Fill", ramp()).ring(ring), PairWell::paint("Stroke", Paint::None).ring(ring)];
let name = if ring { "Ring paints" } else { "Paints" };
let _ = SwatchPair::<()>::new(name, wells, Bind::given(Well::Primary)).show(ui);
}
});
StoryOutput::default()
}
/// Drags the first pair's primary well onto the second pair's.
fn drag_across(fixture: &mut Fixture) {
let wells = fixture.by_role(Role::RADIO_BUTTON);
let (from, to) = (wells[0].rect.center(), wells[2].rect.center());
fixture.drag_at(from, to - from);
}
/// Two pairs whose wells drag a payload and take the other pair's.
#[story(SwatchPair<'static, u8>, covers = [], drive = Drive::Custom(drag_across))]
fn swatch_pair_drags(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let dropped = data.note("dropped", String::new());
Row::new().show(ui, |ui, _| {
for first in [1u8, 3] {
let wells = [PairWell::new("Source", Srgba::rgb(0.1, 0.3, 0.8)), PairWell::new("Target", Srgba::rgb(0.9, 0.35, 0.2))];
let shown = SwatchPair::<()>::new(format!("Pair {first}"), wells, Bind::given(Well::Primary))
.drags([Some(first), Some(first + 1)])
.accepts(|_, _| true)
.show(ui);
if let Some((well, payload)) = shown.dropped {
*dropped = format!("{payload} on {well:?}");
}
}
});
let readout = format!("Dropped: {dropped}");
StoryOutput::default().readout(readout)
}
+81 -6
View File
@@ -1,13 +1,14 @@
//! `SwatchPair` wells take the theme's well shape (`shape.wells`): a round well is round to the pointer too.
use std::cell::Cell;
use std::cell::{Cell, RefCell};
use std::rc::Rc;
use craft_color_ui::ui::{PairWell, SwatchPair, Well};
use craft_behavior::Mixed;
use craft_color_ui::ui::{PairWell, SwatchPair, SwatchPairOutput, Well};
use craft_theme::{Srgba, ThemeId};
use craft_ui::contract::{Bind, Role, Show as _};
use craft_ui::testing::{Fixture, trial};
use egui::{Vec2, vec2};
use egui::{Rect, Ui, Vec2, vec2};
/// Where a click lands on the primary well in theme `theme`: at the well's middle and just inside the corner of its
/// square. Each is the well the click reached, if any.
@@ -16,9 +17,7 @@ fn clicks(theme: &str) -> [Option<Well>; 2] {
let seen = clicked.clone();
let mut fixture = Fixture::new(move |ui| {
let wells = [PairWell::new("Foreground colour", Srgba::rgb(0.1, 0.3, 0.8)), PairWell::new("Background colour", Srgba::rgb(1.0, 1.0, 1.0))];
let shown = SwatchPair::<()>::new("Colours", wells, Bind::given(Well::Primary)) // P3(widgets-w6): wg.W49
.popover(false)
.show(ui);
let shown = SwatchPair::<()>::new("Colours", wells, Bind::given(Well::Primary)).popover(false).show(ui);
if shown.clicked.is_some() {
seen.set(shown.clicked);
}
@@ -34,6 +33,82 @@ fn clicks(theme: &str) -> [Option<Well>; 2] {
})
}
/// What the two pairs of the drag trial reported.
#[derive(Default)]
struct Log {
first: Option<(Well, u8)>,
second: Option<(Well, u8)>,
over_second: Option<Well>,
}
/// A pair whose wells drag `first` and `first + 1`; it accepts every payload when `takes_all`, else only 2.
fn draggable(ui: &mut Ui, name: &'static str, first: u8, back: Mixed<Srgba>, takes_all: bool) -> SwatchPairOutput<u8> {
let wells = [PairWell::new("Fore", Srgba::rgb(0.1, 0.3, 0.8)), PairWell::new("Back", back)];
SwatchPair::<()>::new(name, wells, Bind::given(Well::Primary))
.popover(false)
.drags([Some(first), Some(first + 1)])
.accepts(move |_, payload| takes_all || *payload == 2)
.show(ui)
}
/// A point on the primary well that the secondary one does not cover, and the reverse.
fn in_primary(well: Rect) -> egui::Pos2 {
well.min + well.size() * vec2(0.15, 0.5)
}
fn in_secondary(well: Rect) -> egui::Pos2 {
well.min + well.size() * vec2(0.85, 0.5)
}
/// A well drags its payload past the slop and the well under the pointer takes it when `accepts` allows; a mixed well
/// drags nothing and takes nothing.
#[trial]
fn a_pair_well_drags_its_payload_and_takes_a_drop_a_mixed_well_does_neither() {
let log = Rc::new(RefCell::new(Log::default()));
let seen = log.clone();
let mut fixture = Fixture::new(move |ui| {
let first = draggable(ui, "First", 1, Mixed::Same(Srgba::WHITE), false);
let second = draggable(ui, "Second", 3, Mixed::Mixed, true);
let mut log = seen.borrow_mut();
if first.dropped.is_some() {
log.first = first.dropped;
}
if second.dropped.is_some() {
log.second = second.dropped;
}
log.over_second = second.over;
});
fixture.room(vec2(240.0, 400.0));
fixture.settle();
let wells = fixture.by_role(Role::RADIO_BUTTON);
let [a_primary, a_secondary, b_primary, b_secondary] = [0, 1, 2, 3].map(|i| wells[i].rect);
let mut drag = |fixture: &mut Fixture, from: egui::Pos2, to: egui::Pos2| {
*log.borrow_mut() = Log::default();
fixture.drag_at(from, to - from);
};
drag(&mut fixture, in_primary(a_primary), in_secondary(a_secondary));
assert_eq!(log.borrow().first, None, "payload 1 is refused by the pair that accepts only 2");
drag(&mut fixture, in_secondary(a_secondary), in_primary(a_primary));
assert_eq!(log.borrow().first, Some((Well::Primary, 2)), "the secondary well's payload lands on the primary one");
drag(&mut fixture, in_primary(a_primary), in_primary(b_primary));
assert_eq!(log.borrow().second, Some((Well::Primary, 1)), "the primary well's payload lands on the other pair's well");
drag(&mut fixture, in_primary(a_primary), in_secondary(b_secondary));
assert_eq!(log.borrow().second, None, "a mixed well takes no drop");
*log.borrow_mut() = Log::default();
let over = Cell::new(None);
fixture.drag_at_pausing(in_primary(a_primary), in_primary(b_primary) - in_primary(a_primary), |_| over.set(log.borrow().over_second));
assert_eq!(over.get(), Some(Well::Primary), "the well a payload is over is reported while it is held");
drag(&mut fixture, in_secondary(b_secondary), in_primary(a_primary));
assert_eq!(log.borrow().first, None, "a mixed well drags nothing");
assert_eq!(log.borrow().over_second, None, "a mixed well starts no drag");
}
/// Adwaita's wells are round: a click in the corner of a well's square misses it. Pro's are square: it hits.
#[trial]
fn the_well_corner_follows_the_theme_well_shape() {
+3 -6
View File
@@ -10,26 +10,23 @@ use std::sync::Arc;
#[derive(Clone)]
pub struct FacePaint {
key: u64,
#[allow(dead_code)] // P3(widgets-w6): wg.W04
paint: Arc<dyn Fn(&ContentPainterCx<'_>, Rect) + Send + Sync>,
}
impl FacePaint {
/// A face identified by `key` that paints with `paint`.
pub fn new(key: u64, paint: impl Fn(&ContentPainterCx<'_>, Rect) + Send + Sync + 'static) -> Self {
let _ = (key, paint);
todo!("wg.W04")
FacePaint { key, paint: Arc::new(paint) }
}
/// The key that identifies the face.
pub fn key(&self) -> u64 {
todo!("wg.W04")
self.key
}
/// Paints the face into `rect`.
pub fn paint(&self, cx: &ContentPainterCx<'_>, rect: Rect) {
let _ = (cx, rect);
todo!("wg.W04")
(self.paint)(cx, rect);
}
}
+95 -36
View File
@@ -7,12 +7,12 @@ use crate::contract::{
Access, Activation, Common, Component, Cx, DisabledLook, GroupHandle, MeasureCx, Meta as _, Outcome, PaintUi, Pointer as _, Props as _, Role,
Sizing, Styled as _, WordSetCx as _,
};
use crate::primitives::{ContentPainterCx, Draw, PaintShape, StrokeWidth};
use crate::primitives::{Checker, ContentPainterCx, DataWidth, Draw, FacePaint, PaintShape, StrokeWidth};
use crate::runtime::requests::ColorRequest;
use crate::style::{ComponentStyle, DataColor, Flags, FocusLook, State, StateMix, StateSet, StyleColor, StyleCx, UiTokens, resolve_style};
use craft_behavior::{Metrics, Mixed, Sense, Value};
use craft_theme::{Rgba, Srgba, Stateful, States, over};
use egui::{Color32, CornerRadius, Rect, Response, Vec2};
use egui::{Color32, CornerRadius, Rect, Response, Vec2, pos2};
#[cfg(feature = "testing")]
mod stories;
@@ -56,8 +56,10 @@ pub struct SwatchStyle {
edge: Stateful<StyleColor>,
/// The ring inside the outline of a selected or checked well; clear while it is off.
ring: Stateful<StyleColor>,
/// The thin edge just inside the outline of a marked well.
/// The thin edge just inside the outline of a marked well, and the ink of the cell marks.
mark: StyleColor,
/// The extent of a corner or centre cell mark: `size.icon.sm`.
mark_size: f32,
/// The checkerboard behind a translucent colour: the colours of its corners and its other cells.
checker: [Rgba; 2],
/// The mixed well's colour, which `inner_edge` contrasts with.
@@ -122,8 +124,10 @@ impl<E> crate::contract::ItemOutput<E> for SwatchOutput {
/// translucent) and whose colour value is the colour; a mixed well has the value "Mixed" and no colour value.
/// `member` makes the swatch a member of the enclosing `RadioGroup`: a radio button, checked when the group holds its
/// value, whose keys and focus are the group's. `cell` makes it a cell of a table of touching swatches, a list box
/// option. The selected ring is `selected` or a checked radio. `marked` draws a thin edge in the text colour just inside
/// the outline: a cell that stands out from its row, such as the harmony colour among its variations.
/// option. The selected ring is `selected` or a checked radio. `marks` draws the cell marks (`CellMarks`): a thin edge
/// in the text colour just inside the outline for a cell that stands out from its row, such as the harmony colour among
/// its variations, and the locked, web-safe, transparent and source marks. `stroke` shows the colour as a ring and
/// `face` replaces the colour with a host painter.
#[derive(crate::contract::Component, crate::contract::Props)]
#[component(content_painter, probe(Swatch<u8>))]
pub struct Swatch<T: Value + 'static = ()> {
@@ -140,18 +144,15 @@ pub struct Swatch<T: Value + 'static = ()> {
#[style_key]
#[prop(flag)]
well: bool,
/// A thin edge in the text colour just inside the outline.
#[prop(flag)]
marked: bool,
/// The marks drawn on the well.
marks: CellMarks,
/// The well shows its colour as a ring: a band of the colour round the edge, open in the middle.
#[style_key]
#[prop(flag)]
#[allow(dead_code)] // P3(widgets-w6): cv.F40
stroke: bool,
/// The face the well shows over its checker instead of the colour; ring, mark and mixed look unchanged.
#[prop]
#[allow(dead_code)] // P3(widgets-w6): wg.W33
face: Option<crate::primitives::FacePaint>,
face: Option<FacePaint>,
/// The key of the `ColorRequest` a click files.
#[prop(into)]
picker: Option<String>,
@@ -168,7 +169,7 @@ impl Swatch<()> {
member: None,
cell: false,
well: false,
marked: false,
marks: CellMarks::default(),
stroke: false,
face: None,
picker: None,
@@ -188,7 +189,7 @@ impl<T: Value + 'static> Swatch<T> {
member: Some(value),
cell: self.cell,
well: self.well,
marked: self.marked,
marks: self.marks,
stroke: self.stroke,
face: self.face,
picker: self.picker,
@@ -201,8 +202,7 @@ impl<T: Value + 'static> Swatch<T> {
/// transparent checker half and the source-colour corner triangle, each from tokens.
#[must_use]
pub fn marks(self, marks: CellMarks) -> Self {
let _ = marks;
todo!("ex.E19")
Self { marks, ..self }
}
}
@@ -227,36 +227,31 @@ impl CellMarks {
/// Sets the edge mark.
#[must_use]
pub fn edge(self, on: bool) -> Self {
let _ = on;
todo!("ex.E19")
Self { edge: on, ..self }
}
/// Sets the locked mark.
#[must_use]
pub fn locked(self, on: bool) -> Self {
let _ = on;
todo!("ex.E19")
Self { locked: on, ..self }
}
/// Sets the web-safe mark.
#[must_use]
pub fn web_safe(self, on: bool) -> Self {
let _ = on;
todo!("ex.E19")
Self { web_safe: on, ..self }
}
/// Sets the transparent mark.
#[must_use]
pub fn transparent(self, on: bool) -> Self {
let _ = on;
todo!("ex.E19")
Self { transparent: on, ..self }
}
/// Sets the source-colour mark.
#[must_use]
pub fn source(self, color: Srgba) -> Self {
let _ = color;
todo!("ex.E19")
Self { source: Some(color), ..self }
}
}
@@ -266,8 +261,19 @@ pub const RING_SHARE: f32 = 0.3;
/// Paints `color` as a ring in `well`: a band of the colour round the edge, open in the middle, each side with the
/// edge and the inner edge (`SwatchStyle::inner_edge`) that stand out from the colour, in `state`.
pub fn paint_ring(draw: &Draw<'_>, well: Rect, color: Srgba, style: &SwatchStyle, state: &StateSet, radius: CornerRadius) {
let _ = (draw, well, color, style, state, radius);
todo!("cv.F40")
let band = well.width() * RING_SHARE;
let line = draw.width(StrokeWidth::Thin);
let contrast = style.inner_edge(Some(color));
let edge = state.resolve(&style.edge);
let shape = PaintShape::Rect(well, radius);
draw.stroke(&shape, DataWidth::points(band), DataColor::new(Color32::from(color)));
draw.stroke(&shape, StrokeWidth::Thin, contrast);
draw.stroke(&PaintShape::Rect(well.expand(line), UiTokens::corner(f32::from(radius.nw) + line)), StrokeWidth::Thin, edge);
let hole = well.shrink(band);
// The hole's corners are concentric with the well's: square for a square well, round for a round one.
let corner = |grow: f32| UiTokens::corner((f32::from(radius.nw) - band + grow).max(0.0));
draw.stroke(&PaintShape::Rect(hole.expand(2.0 * line), corner(2.0 * line)), StrokeWidth::Thin, contrast);
draw.stroke(&PaintShape::Rect(hole.expand(line), corner(line)), StrokeWidth::Thin, edge);
}
impl<T: Value + 'static> Component for Swatch<T> {
@@ -293,6 +299,7 @@ impl<T: Value + 'static> Component for Swatch<T> {
edge: Stateful::new(rest),
ring: Stateful::new(clear).on(States::new(accent, accent, accent, accent)),
mark: cx.color(colors.text.normal),
mark_size: cx.tokens.size.icon.sm,
checker: [colors.overlay.checker_light, colors.overlay.checker_dark],
mixed_rgba: colors.surface.sunken,
}
@@ -347,7 +354,9 @@ impl<T: Value + 'static> Component for Swatch<T> {
}
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
paint_face(&ui.draw(), cx.rect, cx.style, cx.state(), self.color, self.marked);
let painter = ui.content_painter(cx);
let look = FaceLook { color: self.color, face: self.face.as_ref(), stroke: self.stroke, marks: self.marks, rtl: cx.flow.is_rtl() };
paint_face(&painter, cx.rect, cx.style, cx.state(), &look);
}
fn finish(self, cx: Cx<'_, Self>) -> SwatchOutput {
@@ -357,17 +366,66 @@ impl<T: Value + 'static> Component for Swatch<T> {
}
}
/// The one swatch face painter: the well of `color` in `well` (a checkerboard behind a translucent colour, the dash
/// of a mixed one), then the outline ring, the mark when `marked`, and the selection ring, in `state`.
fn paint_face(draw: &Draw<'_>, well: Rect, style: &SwatchStyle, state: &StateSet, color: Mixed<Srgba>, marked: bool) {
/// What a swatch face shows beyond its style and state.
struct FaceLook<'a> {
color: Mixed<Srgba>,
face: Option<&'a FacePaint>,
stroke: bool,
marks: CellMarks,
rtl: bool,
}
/// The one swatch face painter: the well in `well` (the host's face over a checkerboard, a ring of the colour, or the
/// colour over a checkerboard where it is translucent, the dash of a mixed one), then the outline, the cell marks and
/// the selection ring, in `state`.
fn paint_face(cx: &ContentPainterCx<'_>, well: Rect, style: &SwatchStyle, state: &StateSet, look: &FaceLook<'_>) {
let shape = PaintShape::Rect(well, style.radius);
draw.swatch_well(well, style.radius, color.same().copied());
draw.stroke(&shape, StrokeWidth::Thin, state.resolve(&style.edge));
if marked {
let ring = look.color.same().copied().filter(|_| look.stroke && look.face.is_none());
match (look.face, ring) {
(Some(face), _) => {
cx.checker_with(&Checker::new(), well, style.radius);
face.paint(cx, well);
}
(None, Some(_)) => {}
(None, None) => cx.with_draw(|draw| draw.swatch_well(well, style.radius, look.color.same().copied())),
}
if look.marks.transparent {
let half = if look.rtl { Rect::from_min_max(well.min, pos2(well.center().x, well.max.y)) } else { Rect::from_min_max(pos2(well.center().x, well.min.y), well.max) };
cx.checker_with(&Checker::new(), half, CornerRadius::ZERO);
}
cx.with_draw(|draw| {
match ring {
// The ring's outline sits outside its well, so the well is taken in by one line to keep the outline in the rect.
Some(color) => paint_ring(draw, well.shrink(draw.width(StrokeWidth::Thin)), color, style, state, style.radius),
None => draw.stroke(&shape, StrokeWidth::Thin, state.resolve(&style.edge)),
}
paint_marks(draw, well, style, &look.marks, look.rtl);
draw.stroke(&shape, StrokeWidth::Thick, state.resolve(&style.ring));
});
}
/// The marks of `marks` that `Draw` paints, with the corner marks at the start-top and end-bottom corners of the flow.
fn paint_marks(draw: &Draw<'_>, well: Rect, style: &SwatchStyle, marks: &CellMarks, rtl: bool) {
let side = style.mark_size;
if marks.edge {
let inside = PaintShape::Rect(well.shrink(draw.width(StrokeWidth::Thin)), style.radius);
draw.stroke(&inside, StrokeWidth::Thin, style.mark);
}
draw.stroke(&shape, StrokeWidth::Thick, state.resolve(&style.ring));
if marks.locked {
let x = if rtl { well.max.x - side } else { well.min.x };
let square = Rect::from_min_size(pos2(x, well.min.y), Vec2::splat(side));
draw.fill(&PaintShape::Rect(square, CornerRadius::ZERO), style.mark);
}
if marks.web_safe {
let (c, h) = (well.center(), side / 2.0);
let diamond = vec![pos2(c.x, c.y - h), pos2(c.x + h, c.y), pos2(c.x, c.y + h), pos2(c.x - h, c.y)];
draw.stroke(&PaintShape::Polygon(diamond), StrokeWidth::Thin, style.mark);
}
if let Some(color) = marks.source {
let (x, step) = if rtl { (well.min.x, side) } else { (well.max.x, -side) };
let triangle = vec![pos2(x, well.max.y), pos2(x + step, well.max.y), pos2(x, well.max.y - side)];
draw.data_fill(&PaintShape::Polygon(triangle), DataColor::new(Color32::from(color)));
}
}
/// The face of a swatch outside a `Swatch`: a preset thumbnail of a colour (`PresetBrowser::thumb`). It paints
@@ -399,6 +457,7 @@ impl SwatchFace {
let style = resolve_style(&scope, key, cx.painter.ctx(), Swatch::<()>::style);
let (flags, on) = if self.selected { (Flags::SELECTED, 1.0) } else { (Flags::empty(), 0.0) };
let state = StateSet::new(State::Rest, flags, StateMix::new(0.0, 0.0, on));
cx.with_draw(|draw| paint_face(draw, rect, &style, &state, self.color, false));
let look = FaceLook { color: self.color, face: None, stroke: false, marks: CellMarks::default(), rtl: false };
paint_face(cx, rect, &style, &state, &look);
}
}
+43 -1
View File
@@ -1,9 +1,10 @@
//! Stories of `Swatch`.
use super::Swatch;
use super::{CellMarks, Swatch};
use crate::choice::RadioGroup;
use crate::contract::{Bind, Gap, Props as _, Show as _, ShowContainer as _};
use crate::layout_components::{Row, Stack};
use crate::primitives::FacePaint;
use crate::testing::{Drive, StoryData, StoryOutput, show_as_only_item, story};
use craft_behavior::Mixed;
use craft_theme::Srgba;
@@ -75,6 +76,47 @@ fn swatch_table_cells(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
StoryOutput::default()
}
/// The well shows a host face over its checker instead of the colour.
#[story(Swatch<u8>, covers = [], drive = Drive::Never)]
fn swatch_face(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let face = FacePaint::new(1, |cx, rect| {
cx.painter.rect_filled(rect, 0.0, egui::Color32::from_rgb(0x2f, 0x6f, 0xd9));
});
Swatch::new("Face", BLUE).face(face).show(ui).into()
}
/// The colour as a ring, opaque, translucent, selected and mixed.
#[story(Swatch<u8>, covers = [], drive = Drive::Never)]
fn swatch_stroke(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
Row::new().show(ui, |ui, _| {
Swatch::new("Ring", BLUE).stroke().show(ui);
Swatch::new("Translucent ring", Srgba { r: 0.90, g: 0.28, b: 0.30, a: 0.43 }).stroke().show(ui);
Swatch::new("Selected ring", PALETTE[5]).stroke().selected(true).show(ui);
Swatch::new("Mixed ring", Mixed::<Srgba>::Mixed).stroke().show(ui);
});
StoryOutput::default()
}
/// One cell for each mark: edge, locked, web safe, transparent and source colour.
#[story(Swatch<u8>, covers = [], drive = Drive::Never)]
fn swatch_marks(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let marks = [
("Edge", CellMarks::default().edge(true)),
("Locked", CellMarks::default().locked(true)),
("Web safe", CellMarks::default().web_safe(true)),
("Transparent", CellMarks::default().transparent(true)),
("Source", CellMarks::default().source(PALETTE[0])),
];
Row::new().gap(Gap::Tight).show(ui, |ui, _| {
for (name, marks) in marks {
Row::new().show(ui, |ui, _| {
show_as_only_item(ui, Swatch::new(name, BLUE).cell().marks(marks));
});
}
});
StoryOutput::default()
}
/// A well and a line that counts its clicks.
#[story(Swatch<u8>, covers = [], drive = Drive::Never)]
fn swatch_clicks(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {