diff --git a/crates/ui-contract/src/style/cx.rs b/crates/ui-contract/src/style/cx.rs index 5dbb72465..ccc0377e8 100644 --- a/crates/ui-contract/src/style/cx.rs +++ b/crates/ui-contract/src/style/cx.rs @@ -1,7 +1,7 @@ //! `StyleCx`: what `style` and the app colour hooks get. Tokens are readable only through it. use super::key::{EnvKey, Ink}; -use super::look::{DataColor, FocusLook, StyleColor, SurfaceKind, SurfaceLook, TrackLook}; +use super::look::{DataColor, FocusLook, StyleColor, SurfaceKind, SurfaceLook, TrackFill, TrackLook}; use super::paint::{ AutoScrollMarkLook, HandleLook, MarkerLook, ResetMarkLook, RuleKind, RuleLook, ScrollBarKind, ScrollBarLook, auto_scroll_mark_look, handle_look, marker_look, reset_mark_look, rule_look, scroll_bar_look_of, @@ -350,14 +350,18 @@ impl<'a> StyleCx<'a> { )) } - /// The look of a value track: a groove of `size.groove` with the part a value fills over it, and its marks. + /// The look of a value track: a groove of `size.groove` with the part a value fills over it, in the scope's + /// [`TrackFill`], and its marks. pub fn track(&self) -> TrackLook { let colors = &self.tokens.color; - let groove = self.color(colors.line.control_edge); - let muted = self.color(colors.text.muted); + let (groove, fill) = match self.env::() { + TrackFill::Muted => (colors.line.control_edge, colors.text.muted), + TrackFill::Accent => (colors.line.outline, colors.accent.solid), + }; + let (groove, fill) = (self.color(groove), self.color(fill)); TrackLook { unfilled: Stateful::new(groove), - filled: Stateful::new(muted).off(States::new(muted, muted, muted, self.color(colors.text.disabled))), + filled: Stateful::new(fill).off(States::new(fill, fill, fill, self.color(colors.text.disabled))), edge: Stateful::new(self.color(colors.line.control_edge)), edge_width: self.tokens.stroke.thin, thickness: self.tokens.size.groove, diff --git a/crates/ui-contract/src/style/look.rs b/crates/ui-contract/src/style/look.rs index 27b48a990..07fd98849 100644 --- a/crates/ui-contract/src/style/look.rs +++ b/crates/ui-contract/src/style/look.rs @@ -290,6 +290,19 @@ impl IconLook { } } +/// How a value track (`StyleCx::track`) colours its groove and the part a value fills: a slider's and a range +/// slider's. An app sets it once at its root (`RootEnv::values`); the default is the muted fill. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum TrackFill { + /// `text.muted` on a `line.control_edge` groove. + #[default] + Muted, + /// `accent.solid` on a `line.outline` groove: VectorCraft's. + Accent, +} + /// A value track: a groove with the part a value fills over it, and the marks and ticks along it. A slider, a /// range slider, a thumb row and a progress bar paint the same track. #[derive(Clone, Debug, PartialEq)] diff --git a/crates/ui-contract/src/style/mod.rs b/crates/ui-contract/src/style/mod.rs index 5fff01886..aea145c95 100644 --- a/crates/ui-contract/src/style/mod.rs +++ b/crates/ui-contract/src/style/mod.rs @@ -25,7 +25,7 @@ pub(crate) use cx::control_metrics; pub use cx::{GlyphRole, 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 look::{ComponentStyle, Corners, DataColor, FocusLook, IconLook, StyleColor, SurfaceKind, SurfaceLook, TextLook, TrackFill, TrackLook}; pub use paint::{ AutoScrollMarkLook, HandleLook, MarkerLook, ResetMarkLook, ResizeLineLook, RuleKind, RuleLook, RuleWidth, ScrollBarKind, ScrollBarLook, resize_line_look, diff --git a/crates/ui-widgets/src/value_drag/slider/stories.rs b/crates/ui-widgets/src/value_drag/slider/stories.rs index 26859e8c9..45fa02d1b 100644 --- a/crates/ui-widgets/src/value_drag/slider/stories.rs +++ b/crates/ui-widgets/src/value_drag/slider/stories.rs @@ -5,7 +5,8 @@ use super::{Slider, SliderScale, SliderThumb}; use crate::contract::{Props as _, Show as _, ShowContainer as _, Validity}; use crate::display::Progress; use crate::form::Field; -use crate::runtime::env::Message; +use crate::runtime::env::{Message, with_env}; +use crate::style::TrackFill; use crate::testing::{Drive, Grip, StoryData, StoryOutput, story}; use crate::value_drag::TrackFace; use craft_behavior::Mixed; @@ -91,6 +92,18 @@ fn slider_disabled_3(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { disabled_row(ui, data, "Disabled 3", 100.0) } +/// A slider of an app that sets `TrackFill::Accent` at its root: the filled part in the accent on an outline groove. +#[story(Slider<'static>, covers = [], drive = Drive::Drag(Grip::new(Slider::THUMB)), group = "Values", title = "Accent fill")] +fn slider_accent_fill(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + with_env( + ui, + |overrides| { + overrides.values.set(TrackFill::Accent); + }, + |ui| value_row(ui, data, "Opacity", 60.0), + ) +} + /// With the direction set to right to left the label moves to the right; the slider keeps its geometry. #[story(Slider<'static>, covers = [], drive = Drive::Step, group = "Right to left", title = "Opacity")] fn slider_right_to_left(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {