From a89e8ac7b50d455b0f5086253167a2cfdefbb0a2 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 05:19:48 +0000 Subject: [PATCH] Colour markers: one marker look for colour fields, wheels, discs and gradient stops A white ring with a dark halo just outside it, so one of the two reads on any colour; filled with the colour it marks on the disc and the gradient line, accent when a gradient stop or end is selected, large for a disc's base colour and a gradient line's ends. PointPicker's ring, the wheel knobs, the ramp cursor, the disc markers and the gradient overlay's stops and ends draw it in place of their own rings. --- crates/color/src/ui/disc.rs | 35 +++---- crates/color/src/ui/ramp.rs | 12 +-- crates/color/src/ui/wheel.rs | 12 +-- .../src/ui/gradient/gradient_overlay/mod.rs | 42 +++------ .../src/ui/gradient/gradient_overlay/parts.rs | 5 +- crates/ui-contract/src/primitives/draw.rs | 10 ++ crates/ui-contract/src/primitives/marker.rs | 91 +++++++++++++++++++ crates/ui-contract/src/primitives/mod.rs | 2 + crates/ui-contract/src/style/cx.rs | 8 +- crates/ui-contract/src/style/mod.rs | 4 +- crates/ui-contract/src/style/paint.rs | 39 +++++++- .../ui-widgets/src/value_drag/point_picker.rs | 11 ++- 12 files changed, 200 insertions(+), 71 deletions(-) create mode 100644 crates/ui-contract/src/primitives/marker.rs diff --git a/crates/color/src/ui/disc.rs b/crates/color/src/ui/disc.rs index a0e064b3c..be64dc4ea 100644 --- a/crates/color/src/ui/disc.rs +++ b/crates/color/src/ui/disc.rs @@ -5,15 +5,15 @@ use super::channels::{finite, primary}; use super::wheel::{hue_at, hue_direction, vertex}; use craft_behavior::nav::{Arrows, NavShape, Roving}; use craft_behavior::{CancelReason, HitShape, Metrics, NavMove, PartKey, PressPhase, Sense}; -use craft_theme::{ColorModel, Flags, HsbModel, ModelValues, Resolve as _, Srgba, State, StateMix, Stateful}; +use craft_theme::{ColorModel, HsbModel, ModelValues, Srgba}; use craft_ui::contract::{ Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Focus as _, Input, MeasureCx, Name, Numeric, Outcome, PaintUi, PartsCx, Pointer as _, Props as _, Remember as _, Role, WordSetCx as _, }; -use craft_ui::primitives::{PaintShape, StrokeWidth}; +use craft_ui::primitives::{Marker, MarkerSize, PaintShape, StrokeWidth}; use craft_ui::runtime::env::Label; use craft_ui::runtime::focus::{ActivateKeys, FocusShape, KeepKeys, KeyUse}; -use craft_ui::style::{ComponentStyle, DataColor, FocusLook, StyleColor, StyleCx}; +use craft_ui::style::{ComponentStyle, FocusLook, MarkerLook, StyleColor, StyleCx}; use egui::{Color32, Mesh, Pos2, Response, Vec2}; #[cfg(feature = "screen-testing")] @@ -74,17 +74,14 @@ pub struct ColorDiscStyle { focus: FocusLook, /// The distance from the area's edge to the disc. inset: f32, - /// A marker's radius; the selected marker's is larger. - marker: Stateful, + /// The markers; the selected one, the set's base colour, is large. + marker: MarkerLook, /// A press within this of a marker grabs it. grab: f32, /// The disc's edge. edge: StyleColor, /// The line from the centre to a marker. spoke: StyleColor, - /// A marker's inner ring and the halo round it. - ring: StyleColor, - halo: StyleColor, /// The least side of the picture, and the most it takes of the width it is given. least: f32, most: f32, @@ -219,12 +216,10 @@ impl Component for ColorDisc<'_> { most: tokens.size.plot.width, focus: cx.focus_look(), inset: tokens.space.pad.regular, - marker: Stateful::new(tokens.size.handle.sm).when(Flags::SELECTED, tokens.size.handle.md), + marker: cx.marker(), grab: tokens.size.hit.target, edge: cx.color(colors.line.control_edge), spoke: cx.color(colors.overlay.handle_fill.faded(SPOKE_SHARE)), - ring: cx.color(colors.overlay.handle_fill), - halo: cx.color(colors.overlay.halo), } } @@ -248,8 +243,8 @@ impl Component for ColorDisc<'_> { Some(moved) => *moved, None => self.resting(index), }; - let radius_of = marker_radius(cx.style, self.chosen == Some(index)); - let part = cx.part(MARKER.at(index as u64), HitShape::circle(Self::marker_pos(center, radius, at.hue, at.saturation), radius_of)); + let reach = Marker::reach(&cx.style.marker, marker_size(self.chosen == Some(index))); + let part = cx.part(MARKER.at(index as u64), HitShape::circle(Self::marker_pos(center, radius, at.hue, at.saturation), reach)); // A marker takes no press of its own: the disc grabs the nearest. let part = part.focusable().focus_shape(FocusShape::Circle); if index == stop { @@ -399,11 +394,8 @@ impl Component for ColorDisc<'_> { let selected = self.chosen.filter(|selected| *selected < places.len()); let order = (0..places.len()).filter(|index| Some(*index) != selected).chain(selected); for index in order { - let r = marker_radius(cx.style, Some(index) == selected); - let circle = PaintShape::Circle(places[index], r); - draw.data_fill(&circle, DataColor::new(Color32::from(self.markers[index]))); - draw.stroke(&circle, StrokeWidth::Thick, cx.style.halo); - draw.stroke(&circle, StrokeWidth::Medium, cx.style.ring); + let marker = Marker::filled(places[index], Color32::from(self.markers[index])).size(marker_size(Some(index) == selected)); + draw.marker(&cx.style.marker, &marker); } } @@ -439,8 +431,7 @@ fn disc_mesh(center: Pos2, radius: f32, brightness: f32) -> Mesh { mesh } -/// The radius of a marker, larger while it is the selected one. -fn marker_radius(style: &ColorDiscStyle, selected: bool) -> f32 { - let flags = if selected { Flags::SELECTED } else { Flags::empty() }; - style.marker.resolve(State::Rest, flags, StateMix::default()) +/// The size of a marker: large while it is the selected one. +fn marker_size(selected: bool) -> MarkerSize { + if selected { MarkerSize::Large } else { MarkerSize::Regular } } diff --git a/crates/color/src/ui/ramp.rs b/crates/color/src/ui/ramp.rs index 2076881b8..bb32f3fb8 100644 --- a/crates/color/src/ui/ramp.rs +++ b/crates/color/src/ui/ramp.rs @@ -8,11 +8,11 @@ use craft_ui::contract::{ Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Focus as _, Input, Name, Outcome, PaintUi, PartsCx, Pointer as _, Props as _, Remember as _, Role, WordSetCx as _, }; -use craft_ui::primitives::{PaintShape, StrokeWidth}; +use craft_ui::primitives::{Marker, PaintShape, StrokeWidth}; use craft_ui::runtime::commands::FireSource; use craft_ui::runtime::env::Label; use craft_ui::runtime::focus::{KeepKeys, KeyUse}; -use craft_ui::style::{ComponentStyle, DataColor, FocusLook, StyleColor, StyleCx}; +use craft_ui::style::{ComponentStyle, DataColor, FocusLook, MarkerLook, StyleColor, StyleCx}; use egui::{Color32, CornerRadius, Mesh, Pos2, Rect, Response, Vec2, pos2}; use std::hash::{DefaultHasher, Hash, Hasher}; use std::sync::Arc; @@ -56,8 +56,8 @@ pub struct ColorRampStyle { boxes: f32, /// The gap between the bar and the boxes. boxes_gap: f32, - /// The diameter of the cursor cell's marker. - marker: f32, + /// The cursor cell's marker. + marker: MarkerLook, } /// Which colours the ramp shows. @@ -358,7 +358,7 @@ impl Component for ColorRamp<'_> { edge: cx.color(tokens.color.line.control_edge), boxes: tokens.size.icon.lg, boxes_gap: tokens.space.gap.tight, - marker: tokens.size.handle.md, + marker: cx.marker(), } } @@ -462,7 +462,7 @@ impl Component for ColorRamp<'_> { if cx.focus_visible() && cx.active_part() == Some(BAR.into()) { let (fx, fy) = centre_of(self.cursor); let at = pos2(bar.left() + bar.width() * fx, bar.top() + bar.height() * fy); - painter.outline(&PaintShape::Circle(at, cx.style.marker / 2.0)); + draw.marker(&cx.style.marker, &Marker::hollow(at)); } if self.boxes { let half = boxes.center().y; diff --git a/crates/color/src/ui/wheel.rs b/crates/color/src/ui/wheel.rs index 76feefee0..9d7ff2c86 100644 --- a/crates/color/src/ui/wheel.rs +++ b/crates/color/src/ui/wheel.rs @@ -8,10 +8,10 @@ use craft_ui::contract::{ Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Focus as _, Input, MeasureCx, Name, Numeric, PaintUi, PartsCx, Pointer as _, Props as _, Role, WordSetCx as _, }; -use craft_ui::primitives::{PaintShape, StrokeWidth}; +use craft_ui::primitives::{Marker, PaintShape, StrokeWidth}; use craft_ui::runtime::env::Label; use craft_ui::runtime::focus::{ActivateKeys, FocusShape, KeepKeys, KeyUse}; -use craft_ui::style::{ComponentStyle, FocusLook, StyleColor, StyleCx}; +use craft_ui::style::{ComponentStyle, FocusLook, MarkerLook, StyleColor, StyleCx}; use egui::{Mesh, Pos2, Rect, Vec2, vec2}; use std::f32::consts::TAU; @@ -168,8 +168,8 @@ pub struct ColorWheelStyle { grab: f32, /// The edge round the ring and the triangle. edge: StyleColor, - /// The diameter of the knobs. - knob: f32, + /// The knobs. + knob: MarkerLook, /// The least side of the picture, and the most it takes of the width it is given. least: f32, most: f32, @@ -300,7 +300,7 @@ impl Component for ColorWheel<'_> { triangle_inset: tokens.stroke.thin, grab: tokens.size.hit.target, edge: cx.color(tokens.color.line.control_edge), - knob: tokens.size.handle.md, + knob: cx.marker(), } } @@ -395,7 +395,7 @@ impl Component for ColorWheel<'_> { draw.stroke(&PaintShape::Polygon(corners.to_vec()), StrokeWidth::Thin, cx.style.edge); let knobs = [geometry.ring_knob(hue), triangle_point(corners, saturation / 100.0, brightness / 100.0)]; for at in knobs { - painter.outline(&PaintShape::Circle(at, cx.style.knob / 2.0)); + draw.marker(&cx.style.knob, &Marker::hollow(at)); } } diff --git a/crates/draw/src/ui/gradient/gradient_overlay/mod.rs b/crates/draw/src/ui/gradient/gradient_overlay/mod.rs index 1235579f7..8ee8cb265 100644 --- a/crates/draw/src/ui/gradient/gradient_overlay/mod.rs +++ b/crates/draw/src/ui/gradient/gradient_overlay/mod.rs @@ -18,10 +18,10 @@ use craft_ui::contract::{ Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Focus as _, MeasureCx, Name, Outcome, PaintUi, PartsCx, Pointer as _, Props, Remember as _, Role, Styled as _, WordSetCx as _, }; -use craft_ui::primitives::{Dashes, PaintShape, StrokeWidth}; +use craft_ui::primitives::{Dashes, Marker, MarkerSize, PaintShape, StrokeWidth}; use craft_ui::runtime::env::Label; use craft_ui::runtime::focus::KeyUse; -use craft_ui::style::{ComponentStyle, DataColor, HandleLook, StyleColor, StyleCx}; +use craft_ui::style::{ComponentStyle, HandleLook, MarkerLook, StyleColor, StyleCx}; use egui::{Color32, Pos2, Rect, Response, Vec2, vec2}; use super::gradient_line::{at_screen, midpoint_location}; @@ -63,22 +63,18 @@ pub struct GradientOverlayStyle { metrics: Metrics, /// The end handles' look. handle: HandleLook, - /// The line, the extent and the rings. + /// The end rings and the colour stops. + marker: MarkerLook, + /// The line and the extent. line: StyleColor, - /// The outline beside the line and under the rings. + /// The outline beside the line and the extent, and round the diamonds. halo: StyleColor, - /// The selected stop's ring, the selected diamond's fill and a picked end's ring. + /// The selected diamond's fill. selected: StyleColor, - /// The fill under a stop's colour where the colour has opacity. - backing: StyleColor, /// Length of a dash of the mirrored extent. dash: f32, /// Length of the gap between dashes of the mirrored extent. gap: f32, - /// Radius of an end handle's ring. - end_radius: f32, - /// Radius of a colour stop's disc. - stop_radius: f32, /// Radius of a midpoint's diamond. diamond_radius: f32, /// Distance from the line past which a dragged stop is torn off. @@ -283,14 +279,12 @@ impl Component for GradientOverlay<'_> { GradientOverlayStyle { metrics: Metrics::new().min_size(Vec2::splat(size.handle.md)), handle: cx.handle(), + marker: cx.marker(), line: cx.color(overlay.handle_fill), halo: cx.color(overlay.halo), selected: cx.color(overlay.handle_stroke), - backing: cx.color(overlay.handle_fill), dash: stroke.dash, gap: stroke.dash_gap, - end_radius: size.handle.md, - stop_radius: size.handle.sm, diamond_radius: size.handle.sm, tear_off: TEAR_OFF, } @@ -412,9 +406,7 @@ impl GradientOverlay<'_> { } } for (at, key, part) in [(start, START, LinePart::Start), (end, END, LinePart::End)] { - let ring = PaintShape::Circle(at, style.end_radius); - draw.stroke(&ring, StrokeWidth::Thick, style.halo); - draw.stroke(&ring, StrokeWidth::Medium, if marked(key, part) { style.selected } else { style.line }); + draw.marker(&style.marker, &Marker::hollow(at).size(MarkerSize::Large).selected(marked(key, part))); } for (i, stop) in value.stops.color.iter().enumerate() { if self.report.torn && cx.part(STOP.at(i as u64)).press.phase.is_drag() { @@ -422,17 +414,11 @@ impl GradientOverlay<'_> { } let at = at_screen(start, end, stop.location, self.reverse); let color = Color32::from(stop.color); - let disc = PaintShape::Circle(at, style.stop_radius); - draw.stroke(&PaintShape::Circle(at, style.stop_radius), StrokeWidth::Thick, style.halo); - match self.rules.rows { - StopRows::Combined => { - draw.fill(&disc, style.backing); - draw.data_fill(&disc, DataColor::new(color)); - } - _ => draw.data_fill(&disc, DataColor::new(Color32::from_rgb(color.r(), color.g(), color.b()))), - } - let ring = if selected == Some(StopRef::Color(i)) { style.selected } else { style.line }; - draw.stroke(&disc, StrokeWidth::Medium, ring); + let color = match self.rules.rows { + StopRows::Combined => color, + _ => Color32::from_rgb(color.r(), color.g(), color.b()), + }; + draw.marker(&style.marker, &Marker::filled(at, color).selected(selected == Some(StopRef::Color(i)))); } }); } diff --git a/crates/draw/src/ui/gradient/gradient_overlay/parts.rs b/crates/draw/src/ui/gradient/gradient_overlay/parts.rs index 87aae530e..a046b0537 100644 --- a/crates/draw/src/ui/gradient/gradient_overlay/parts.rs +++ b/crates/draw/src/ui/gradient/gradient_overlay/parts.rs @@ -3,6 +3,7 @@ use craft_behavior::{CursorIcon, HitLevel, HitPriority, HitShape, NavShape, PartKey, PartRef, Roving, Sense}; use craft_ui::canvas::canvas_space; use craft_ui::contract::PartsCx; +use craft_ui::primitives::{Marker, MarkerSize}; use egui::Pos2; use super::{GradientOverlay, screen_line}; @@ -76,8 +77,8 @@ impl GradientOverlay<'_> { let (start, end) = screen_line(&space.view, value); let sense = if live { Sense::DRAG | Sense::CLICK | Sense::TAKE_FOCUS | Sense::CONTEXT_CLICK } else { Sense::HOVER }; let radius = |part: LinePart| match part { - LinePart::Start | LinePart::End => style.end_radius, - LinePart::Stop(_) => style.stop_radius, + LinePart::Start | LinePart::End => Marker::reach(&style.marker, MarkerSize::Large), + LinePart::Stop(_) => Marker::reach(&style.marker, MarkerSize::Regular), _ => style.diamond_radius, }; let at = |part: LinePart| -> Pos2 { diff --git a/crates/ui-contract/src/primitives/draw.rs b/crates/ui-contract/src/primitives/draw.rs index 102cb6c74..7e50fd96c 100644 --- a/crates/ui-contract/src/primitives/draw.rs +++ b/crates/ui-contract/src/primitives/draw.rs @@ -306,6 +306,16 @@ impl<'a> Draw<'a> { self.painter.extend(super::ResetMark::shapes(look, center, differs)); } + /// Paints `marker` in `look`. A `Draw` for an inactive part fills a filled marker with the theme's disabled fill, as + /// `data_fill` does. + pub fn marker(&self, look: &crate::style::MarkerLook, marker: &super::Marker) { + let marker = match marker.fill() { + Some(color) => marker.with_fill(self.data_color(DataColor::new(color))), + None => *marker, + }; + self.painter.extend(marker.shapes(look)); + } + /// Paints the line of `kind` from `from` to `to`. pub fn rule(&self, kind: RuleKind, from: Pos2, to: Pos2) { let look = rule_look(self.env.tokens, kind); diff --git a/crates/ui-contract/src/primitives/marker.rs b/crates/ui-contract/src/primitives/marker.rs new file mode 100644 index 000000000..1baa5c663 --- /dev/null +++ b/crates/ui-contract/src/primitives/marker.rs @@ -0,0 +1,91 @@ +//! `Marker`: the mark that shows where a colour sits on a colour field, wheel, disc or gradient line. + +use crate::style::MarkerLook; +use egui::{Color32, Pos2, Shape, Stroke}; + +/// How large a marker is drawn. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub enum MarkerSize { + /// A marker of the look's radius. + #[default] + Regular, + /// The look's large radius: the base colour of a set, or a line's end. + Large, +} + +/// A colour marker centred on `at`: the colour it marks (when filled), a ring and a halo ring just outside it. +#[derive(Clone, Copy, Debug, PartialEq)] +#[must_use] +pub struct Marker { + at: Pos2, + fill: Option, + size: MarkerSize, + selected: bool, +} + +impl Marker { + /// A ring that shows the field under it. + pub const fn hollow(at: Pos2) -> Self { + Marker { at, fill: None, size: MarkerSize::Regular, selected: false } + } + + /// A disc of `color`; a translucent colour sits on the look's backing. + pub const fn filled(at: Pos2, color: Color32) -> Self { + Marker { at, fill: Some(color), size: MarkerSize::Regular, selected: false } + } + + /// Drawn at `size`. + pub const fn size(mut self, size: MarkerSize) -> Self { + self.size = size; + self + } + + /// The ring in the look's selected colour while `selected`. + pub const fn selected(mut self, selected: bool) -> Self { + self.selected = selected; + self + } + + /// The colour it marks, if filled. + pub(crate) const fn fill(&self) -> Option { + self.fill + } + + /// The same marker filled with `color`. + pub(crate) const fn with_fill(mut self, color: Color32) -> Self { + self.fill = Some(color); + self + } + + /// The radius of a marker of `size`, out to the inner edge of its ring. + pub fn radius(look: &MarkerLook, size: MarkerSize) -> f32 { + match size { + MarkerSize::Regular => look.radius, + MarkerSize::Large => look.large, + } + } + + /// How far a marker of `size` reaches from its centre, halo included. + pub fn reach(look: &MarkerLook, size: MarkerSize) -> f32 { + Self::radius(look, size) + look.ring_width + look.halo_width + } + + /// The shapes, bottom first. + pub fn shapes(&self, look: &MarkerLook) -> Vec { + let radius = Self::radius(look, self.size); + let mut shapes = Vec::with_capacity(4); + if let Some(color) = self.fill { + if !color.is_opaque() { + shapes.push(Shape::circle_filled(self.at, radius, look.backing.egui())); + } + shapes.push(Shape::circle_filled(self.at, radius, color)); + } + let ring = if self.selected { look.selected } else { look.ring }; + shapes.push(Shape::circle_stroke(self.at, radius, Stroke::new(look.ring_width, ring.egui()))); + // A circle strokes outside its radius: the halo starts where the ring ends. + let halo = radius + look.ring_width; + shapes.push(Shape::circle_stroke(self.at, halo, Stroke::new(look.halo_width, look.halo.egui()))); + shapes + } +} diff --git a/crates/ui-contract/src/primitives/mod.rs b/crates/ui-contract/src/primitives/mod.rs index f947d6cf2..977d5ad2d 100644 --- a/crates/ui-contract/src/primitives/mod.rs +++ b/crates/ui-contract/src/primitives/mod.rs @@ -10,6 +10,7 @@ mod handle; mod icon; mod ime_surface; mod kit; +mod marker; mod record; mod reset_mark; mod rule; @@ -37,6 +38,7 @@ pub use kit::{ Checker, CheckerArea, GridAxis, GridInk, GridLines, GridLook, GridStroke, MAX_LINES, Tick, TickEdge, TickRank, dashed, drop_mark, ellipse, grid_lines, grid_lines_with, marching_ants, outline, ramp, ticks, }; +pub use marker::{Marker, MarkerSize}; pub use reset_mark::ResetMark; pub use rule::{Rule, RuleKind}; pub use scroll_bar::{HiddenContent, ScrollBar}; diff --git a/crates/ui-contract/src/style/cx.rs b/crates/ui-contract/src/style/cx.rs index bfffea3c8..7e93534eb 100644 --- a/crates/ui-contract/src/style/cx.rs +++ b/crates/ui-contract/src/style/cx.rs @@ -3,7 +3,8 @@ use super::key::{EnvKey, Ink}; use super::look::{DataColor, FocusLook, StyleColor, SurfaceKind, SurfaceLook, TrackLook}; use super::paint::{ - HandleLook, ResetMarkLook, RuleKind, RuleLook, ScrollBarKind, ScrollBarLook, handle_look, reset_mark_look, rule_look, scroll_bar_look, + HandleLook, MarkerLook, ResetMarkLook, RuleKind, RuleLook, ScrollBarKind, ScrollBarLook, handle_look, marker_look, reset_mark_look, rule_look, + scroll_bar_look, }; use super::surface::{SurfaceStyle, surface_style}; use super::tokens::UiTokens; @@ -347,6 +348,11 @@ impl<'a> StyleCx<'a> { handle_look(self.tokens) } + /// The look of a colour marker. + pub fn marker(&self) -> MarkerLook { + marker_look(self.tokens) + } + /// The look of a scroll bar of `kind`. pub fn scroll_bar(&self, kind: ScrollBarKind) -> ScrollBarLook { scroll_bar_look(self.tokens, kind) diff --git a/crates/ui-contract/src/style/mod.rs b/crates/ui-contract/src/style/mod.rs index c003eb4ae..85cf3584e 100644 --- a/crates/ui-contract/src/style/mod.rs +++ b/crates/ui-contract/src/style/mod.rs @@ -23,7 +23,9 @@ pub use cx::{StyleCx, VariantParts}; pub use key::{EnvKey, Ink, StyleKey}; pub(crate) use look::StyleView; pub use look::{ComponentStyle, Corners, DataColor, FocusLook, IconLook, StyleColor, SurfaceKind, SurfaceLook, TextLook, TrackLook}; -pub use paint::{HandleLook, ResetMarkLook, ResizeLineLook, RuleKind, RuleLook, RuleWidth, ScrollBarKind, ScrollBarLook, resize_line_look}; +pub use paint::{ + HandleLook, MarkerLook, ResetMarkLook, ResizeLineLook, RuleKind, RuleLook, RuleWidth, ScrollBarKind, ScrollBarLook, resize_line_look, +}; pub(crate) use paint::{min_thumb, scroll_bar_look}; pub use replacements::{DuplicateStyle, StyleReplacements}; pub use state::StateSet; diff --git a/crates/ui-contract/src/style/paint.rs b/crates/ui-contract/src/style/paint.rs index 1fd1640f5..b2008f722 100644 --- a/crates/ui-contract/src/style/paint.rs +++ b/crates/ui-contract/src/style/paint.rs @@ -1,4 +1,4 @@ -//! What the small painters (rules, handles, scroll bars, the reset mark) draw, read from tokens. +//! What the small painters (rules, handles, colour markers, scroll bars, the reset mark) draw, read from tokens. use super::tokens::UiTokens; use craft_theme::{Rgba, Stateful}; @@ -132,6 +132,43 @@ pub(crate) fn handle_look(tokens: &UiTokens) -> HandleLook { HandleLook { side: tokens.size.handle.md, fill, stroke: style_color(c.overlay.handle_stroke), stroke_width: tokens.stroke.thin } } +/// A colour marker: the mark on a colour field, wheel, disc or gradient line that shows where a colour sits. Its ring +/// and the halo just outside it make one of the two read on any colour. +#[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] +pub struct MarkerLook { + /// The radius of a marker, out to the inner edge of its ring. + pub radius: f32, + /// The radius of a large marker (a set's base colour). + pub large: f32, + /// The ring colour. + pub ring: StyleColor, + /// The ring colour of a selected marker. + pub selected: StyleColor, + /// The ring's width. + pub ring_width: f32, + /// The halo ring's colour, just outside the ring. + pub halo: StyleColor, + /// The halo ring's width. + pub halo_width: f32, + /// The fill under a translucent marked colour. + pub backing: StyleColor, +} + +pub(crate) fn marker_look(tokens: &UiTokens) -> MarkerLook { + let (o, stroke, handle) = (&tokens.color.overlay, &tokens.stroke, &tokens.size.handle); + MarkerLook { + radius: handle.sm, + large: handle.md, + ring: style_color(o.handle_fill), + selected: style_color(o.handle_stroke), + ring_width: stroke.medium, + halo: style_color(o.halo), + halo_width: stroke.thin, + backing: style_color(o.handle_fill), + } +} + /// Where a scroll bar sits. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] diff --git a/crates/ui-widgets/src/value_drag/point_picker.rs b/crates/ui-widgets/src/value_drag/point_picker.rs index 281d80f37..2a151eaa4 100644 --- a/crates/ui-widgets/src/value_drag/point_picker.rs +++ b/crates/ui-widgets/src/value_drag/point_picker.rs @@ -7,10 +7,10 @@ use crate::contract::{ Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Focus as _, Input, MeasureCx, Numeric, PaintUi, PartsCx, Pointer as _, Props as _, Role, WordSetCx as _, }; -use crate::primitives::{ContentPainterCx, PaintShape}; +use crate::primitives::{ContentPainterCx, Marker, PaintShape}; use crate::runtime::access::Name; use crate::runtime::focus::{ActivateKeys, KeepKeys, KeyUse}; -use crate::style::{ComponentStyle, FocusLook, StyleCx}; +use crate::style::{ComponentStyle, FocusLook, MarkerLook, StyleCx}; use craft_behavior::nav::{LARGE_STEPS, STEP_SHARE, StepResult, ValueAxes, ValueSteps, snap_to_step, step_until_changed, step_value}; use craft_behavior::{ AccessAction, Axis, CursorIcon, HitLevel, HitPriority, Metrics, Mixed, MoveMods, NavMove, PartKey, Sense, ValueDrag, Wheel, decimals_for_step, @@ -53,8 +53,10 @@ pub struct PointPickerStyle { metrics: Metrics, #[style(focus)] focus: FocusLook, - /// The length of the cross, and the width of the ring, at the point. + /// The length of the cross at the point. thumb: f32, + /// The ring at the point. + marker: MarkerLook, /// The side of the square that grabs the point. hit: f32, } @@ -342,6 +344,7 @@ impl Component for PointPicker<'_> { metrics: Metrics::new().min_size(Vec2::new(cx.tokens.size.plot.width, cx.tokens.size.plot.height)), focus: cx.focus_look(), thumb: cx.tokens.size.handle.md, + marker: cx.marker(), hit: cx.tokens.size.hit.target, } } @@ -456,7 +459,7 @@ impl Component for PointPicker<'_> { painter.outline(&PaintShape::Path(vec![center + from, center + to])); } } - PointMark::Ring => painter.outline(&PaintShape::Circle(center, arm)), + PointMark::Ring => ui.draw().marker(&cx.style.marker, &Marker::hollow(center)), } } }