ui-contract style: TrackFill, a root style value; under TrackFill::Accent a slider's and a range slider's track fill the value's part in accent.solid (disabled text.disabled) on a line.outline groove; TrackFill::Muted, the default, keeps text.muted on line.control_edge. Slider story under Accent

This commit is contained in:
bflatastic
2026-11-24 19:38:11 +07:00
parent 66ab239f53
commit 09650e1d3d
4 changed files with 37 additions and 7 deletions
+9 -5
View File
@@ -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>() {
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,
+13
View File
@@ -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)]
+1 -1
View File
@@ -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,
@@ -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 {