Components that show data paint their enabled look faded when disabled

Picture, ColorWheel, ColorDisc, ColorRamp, TrackRamp, GradientSwatch,
BrushStrokeStrip, Histogram, GraphEditor, FontSample, CurveGraph,
ToneRamp, CurvePreview, VectorscopePlot and FramePreview declare
DisabledLook::Faded: their content is data painted with the content
painter, and their chrome has no Disabled look of its own. GradientSwatch
goes the way of Swatch: its edge loses its Disabled entry.
This commit is contained in:
aiongg
2026-11-12 14:32:51 +00:00
parent b19f52dde8
commit 522e71a4f0
15 changed files with 41 additions and 34 deletions
+3 -2
View File
@@ -7,8 +7,8 @@ use craft_behavior::nav::{Arrows, NavShape, Roving};
use craft_behavior::{CancelReason, HitShape, Metrics, NavMove, PartKey, PressPhase, Sense};
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 _,
Access, Bind, BindMut, Common, Component, Cx, DisabledLook, 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::{Marker, MarkerSize, PaintShape, StrokeWidth};
use craft_ui::runtime::env::Label;
@@ -200,6 +200,7 @@ impl<'a> ColorDisc<'a> {
}
impl Component for ColorDisc<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const KEYS: KeyUse = KeyUse::of(Input::Pointer).with_keep(KeepKeys::BlockArrows).with_activate(ActivateKeys::Neither);
const SINGLE_VALUE: bool = true;
const ROLE: Role = Role::GROUP;
+2 -1
View File
@@ -5,7 +5,7 @@ use std::ops::RangeInclusive;
use craft_behavior::{Axis, Sense};
use craft_theme::{Channel, ColorModel, Srgba};
use craft_ui::contract::{Bind, Common, Component, Cx, EditResponse, MeasureCx, Role, Show as _};
use craft_ui::contract::{Bind, Common, Component, Cx, DisabledLook, EditResponse, MeasureCx, Role, Show as _};
use craft_ui::form::SliderField;
use craft_ui::primitives::{PaintShape, StrokeWidth};
use craft_ui::runtime::env::{Label, UnitKind};
@@ -89,6 +89,7 @@ impl TrackRamp {
}
impl Component for TrackRamp {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::IMAGE;
const PARTS: bool = false;
const STOPS: bool = false;
+3 -2
View File
@@ -5,8 +5,8 @@ use craft_behavior::{Axis, Metrics, NavMove, PartKey, PressPhase, Sense};
use craft_theme::{Hsb, Srgba};
use craft_ui::canvas::context_click;
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 _,
Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Focus as _, Input, Name, Outcome, PaintUi, PartsCx,
Pointer as _, Props as _, Remember as _, Role, WordSetCx as _,
};
use craft_ui::primitives::{Marker, PaintShape, StrokeWidth};
use craft_ui::runtime::commands::FireSource;
@@ -343,6 +343,7 @@ fn moved(cursor: (usize, usize), mv: NavMove, far: bool) -> (usize, usize) {
}
impl Component for ColorRamp<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const SINGLE_VALUE: bool = true;
const ROLE: Role = Role::GROUP;
const OVERLAYS: bool = false;
+3 -2
View File
@@ -5,8 +5,8 @@ use super::channels::{channel_step, finite, primary, settled, spoken};
use craft_behavior::{HitLevel, HitPriority, HitShape, Metrics, NavMove, PartKey, PressPhase, Sense};
use craft_theme::{ColorModel, HsbModel, ModelValues};
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 _,
Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Focus as _, Input, MeasureCx, Name, Numeric, PaintUi,
PartsCx, Pointer as _, Props as _, Role, WordSetCx as _,
};
use craft_ui::primitives::{Marker, PaintShape, StrokeWidth};
use craft_ui::runtime::env::Label;
@@ -280,6 +280,7 @@ fn keyed(values: &ModelValues, part: WheelPart, mv: NavMove, far: bool) -> Optio
}
impl Component for ColorWheel<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const SINGLE_VALUE: bool = true;
const ROLE: Role = Role::GROUP;
const KEYS: KeyUse = KeyUse::of(Input::Pointer).with_keep(KeepKeys::BlockArrows).with_activate(ActivateKeys::Neither);
+2 -1
View File
@@ -4,7 +4,7 @@
use std::sync::Arc;
use craft_behavior::{Axis, Metrics, Sense};
use craft_ui::contract::{Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role};
use craft_ui::contract::{Common, Component, Cx, DisabledLook, MeasureCx, PaintUi, Props as _, Role};
use craft_ui::primitives::{Revision, TextureStore, TextureStoreOptions};
use craft_ui::runtime::env::Label;
use craft_ui::style::{ComponentStyle, StyleCx, SurfaceLook};
@@ -123,6 +123,7 @@ impl<'a> BrushStrokeStrip<'a> {
}
impl Component for BrushStrokeStrip<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::IMAGE;
const OVERLAYS: bool = false;
type Style = BrushStrokeStripStyle;
+7 -14
View File
@@ -1,9 +1,8 @@
//! [`GradientSwatch`]: a well that shows a gradient.
use craft_behavior::{Axis, CursorIcon, CursorPriority, Metrics, Sense};
use craft_theme::{Stateful, States};
use craft_ui::choice::SwatchMetrics;
use craft_ui::contract::{Access, Common, Component, Cx, MeasureCx, Outcome, PaintUi, Pointer as _, PopupKind, Props as _, Role, Styled as _};
use craft_ui::contract::{Access, Common, Component, Cx, DisabledLook, MeasureCx, Outcome, PaintUi, Pointer as _, PopupKind, Props as _, Role};
use craft_ui::style::{ComponentStyle, FocusLook, StyleColor, StyleCx};
use egui::{CornerRadius, Response, Vec2};
@@ -27,7 +26,7 @@ pub struct GradientSwatchStyle {
/// The well's corners.
radius: CornerRadius,
/// The ring on the well's outline, which separates the well from the panel.
edge: Stateful<StyleColor>,
edge: StyleColor,
}
/// What a gradient swatch reports.
@@ -55,7 +54,7 @@ impl Outcome for GradientSwatchOutput {
/// swatch edits nothing; a click is the host's cue. The well has the gradient chip aspect
/// (`GradientRamp::CHIP_ASPECT`); `fill` takes the wider width the layout offers (an options bar
/// cell). AccessKit sees a button named by the label, with `has_popup` when the host opens a
/// dialog on the click. A disabled swatch keeps its gradient and fades its ring.
/// dialog on the click.
#[derive(craft_ui::contract::Component, craft_ui::contract::Props)]
#[component(content_painter)]
pub struct GradientSwatch<'a> {
@@ -86,6 +85,7 @@ impl<'a> GradientSwatch<'a> {
}
impl Component for GradientSwatch<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::BUTTON;
const PARTS: bool = false;
const OVERLAYS: bool = false;
@@ -93,15 +93,8 @@ impl Component for GradientSwatch<'_> {
type Output = GradientSwatchOutput;
fn style(cx: &StyleCx<'_>, _: GradientSwatchStyleKey) -> GradientSwatchStyle {
let (radius, rest) = GradientRamp::chip_look(cx);
let disabled = cx.color(cx.tokens.color.text.disabled);
GradientSwatchStyle {
metrics: Metrics::new(),
focus: cx.focus_look(),
side: SwatchMetrics::of(cx).side,
radius,
edge: Stateful::new(rest).off(States::new(rest, rest, rest, disabled)),
}
let (radius, edge) = GradientRamp::chip_look(cx);
GradientSwatchStyle { metrics: Metrics::new(), focus: cx.focus_look(), side: SwatchMetrics::of(cx).side, radius, edge }
}
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
@@ -138,7 +131,7 @@ impl Component for GradientSwatch<'_> {
let default = default_sampler(self.rows);
let sampler: &Sampler = self.sampler.unwrap_or(&default);
let colors = GradientRamp::colors(self.stops, sampler);
GradientRamp::paint_chip(&ui.content_painter(cx), cx.rect, style.radius, &colors, cx.resolve(&style.edge));
GradientRamp::paint_chip(&ui.content_painter(cx), cx.rect, style.radius, &colors, style.edge);
}
fn finish(self, cx: Cx<'_, Self>) -> GradientSwatchOutput {
+2 -1
View File
@@ -1,7 +1,7 @@
//! `FontSample`: text in a font face at the user's sample size, on one line at the reading start of its rect.
use craft_behavior::Sense;
use craft_ui::contract::{Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role};
use craft_ui::contract::{Common, Component, Cx, DisabledLook, MeasureCx, PaintUi, Props as _, Role};
use craft_ui::fonts::FontRef;
use craft_ui::primitives::{DocRun, DocText};
use craft_ui::runtime::env::Label;
@@ -69,6 +69,7 @@ impl<'a> FontSample<'a> {
}
impl Component for FontSample<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::LABEL;
const PARTS: bool = false;
const INPUT: craft_ui::contract::Input = craft_ui::contract::Input::Display;
+3 -2
View File
@@ -7,8 +7,8 @@ use crate::ui::histogram::{ChannelColor, HistogramData, HistogramInks, Histogram
use craft_behavior::{HitLevel, HitPriority, Input, Metrics, NavMove, PartKey, PointerButton, PressPhase, Sense};
use craft_keymap::{Chord, Key, Mods};
use craft_ui::contract::{
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Focus as _, MeasureCx, Outcome, PaintUi, PartsCx, Pointer as _,
Props as _, Remember as _, Role, WordSetCx as _,
Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Focus as _, MeasureCx, Outcome, PaintUi, PartsCx,
Pointer as _, Props as _, Remember as _, Role, WordSetCx as _,
};
use craft_ui::primitives::{ContentPainterCx, Draw, PaintShape, StrokeWidth};
use craft_ui::runtime::access::Name;
@@ -484,6 +484,7 @@ fn follow(rules: &CurveRules, map: Map, reach: f32, curve: &Curve, drag: &mut Dr
}
impl Component for CurveGraph<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::GROUP;
const INPUT: Input = Input::Pointer;
const OVERLAYS: bool = false;
+2 -1
View File
@@ -4,7 +4,7 @@ use super::graph::{CurveSampler, Map, PlotLook, outputs, paint_line};
use super::model::Curve;
use crate::ui::histogram::ChannelColor;
use craft_behavior::{Input, Metrics, Sense};
use craft_ui::contract::{Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role};
use craft_ui::contract::{Common, Component, Cx, DisabledLook, MeasureCx, PaintUi, Props as _, Role};
use craft_ui::primitives::ContentPainterCx;
use craft_ui::runtime::env::Label;
use craft_ui::style::{ComponentStyle, StyleCx};
@@ -61,6 +61,7 @@ impl CurvePreview<'static> {
}
impl Component for CurvePreview<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::IMAGE;
const INPUT: Input = Input::Display;
const PARTS: bool = false;
+2 -1
View File
@@ -1,7 +1,7 @@
//! `ToneRamp`: a gradient bar through evenly spaced stops.
use craft_behavior::{Axis, Input, Metrics, Sense};
use craft_ui::contract::{Common, Component, Cx, MeasureCx, PaintUi, Role};
use craft_ui::contract::{Common, Component, Cx, DisabledLook, MeasureCx, PaintUi, Role};
use craft_ui::style::{ComponentStyle, DataColor, StyleCx};
use egui::{Response, Vec2};
@@ -46,6 +46,7 @@ impl ToneRamp<'static> {
}
impl Component for ToneRamp<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::None;
const INPUT: Input = Input::Display;
const PARTS: bool = false;
+3 -2
View File
@@ -9,8 +9,8 @@ use super::words::HistogramWords;
use craft_behavior::{AccessAction, CancelReason, CursorIcon, Flow, IconId, Intent, Metrics, NavMove, PartKey, PressPhase, Sense};
use craft_theme::{Stateful, TypeRole};
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 _, Role, Styled as _, WordSetCx as _,
Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Focus as _, Input, MeasureCx, Name, Numeric, Outcome,
PaintUi, PartsCx, Pointer as _, Props as _, Role, Styled as _, WordSetCx as _,
};
use craft_ui::primitives::{IconSpec, TextRun};
use craft_ui::runtime::env::Label;
@@ -291,6 +291,7 @@ impl<'a> Histogram<'a> {
}
impl Component for Histogram<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::IMAGE;
const OVERLAYS: bool = false;
const KEYS: KeyUse = KeyUse::of(Input::Pointer).with_keep(KeepKeys::BlockArrows).with_activate(ActivateKeys::Neither).with_moves();
+2 -1
View File
@@ -2,7 +2,7 @@
use super::words::ScopeWords;
use craft_behavior::{Metrics, Sense};
use craft_ui::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role, WordSetCx as _};
use craft_ui::contract::{Access, Common, Component, Cx, DisabledLook, MeasureCx, PaintUi, Props as _, Role, WordSetCx as _};
use craft_ui::fonts::FontRef;
use craft_ui::primitives::{DocRun, DocText, HAlign, PaintShape, StrokeWidth};
use craft_ui::runtime::env::Label;
@@ -166,6 +166,7 @@ impl<'a> VectorscopePlot<'a> {
}
impl Component for VectorscopePlot<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::IMAGE;
const PARTS: bool = false;
const STOPS: bool = false;
+3 -2
View File
@@ -13,8 +13,8 @@ use craft_keymap::{Chord, Key, Mods};
use craft_ui::buttons::{IconButton, ToggleButton};
use craft_ui::contract::Remember as _;
use craft_ui::contract::{
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Focus as _, MeasureCx, Name, Outcome, PaintUi, PartsCx, Pointer as _,
Props, Role, Styled as _, WordSetCx as _,
Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Focus as _, MeasureCx, Name, Outcome, PaintUi, PartsCx,
Pointer as _, Props, Role, Styled as _, WordSetCx as _,
};
use craft_ui::primitives::{Dashes, GridInk, GridLines, IconSpec, PaintShape, RuleKind, StrokeWidth, TextRun, TickRank};
use craft_ui::runtime::env::Label;
@@ -697,6 +697,7 @@ fn applied(selection: &Selection<KeyframeId>, change: &SelectionChange<KeyframeI
}
impl Component for GraphEditor<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::GROUP;
const OVERLAYS: bool = false;
const KEYS: KeyUse = KeyUse::CANVAS.with_chrome_key(false).with_deletes().with_claims(&CLAIMED);
+2 -1
View File
@@ -5,7 +5,7 @@ mod stories;
use craft_behavior::{Axis, Metrics, Sense};
use craft_theme::Stateful;
use craft_ui::contract::{Access, Common, Component, Cx, Input, MeasureCx, Name, PaintUi, Props, Role, Styled as _};
use craft_ui::contract::{Access, Common, Component, Cx, DisabledLook, Input, MeasureCx, Name, PaintUi, Props, Role, Styled as _};
use craft_ui::primitives::{PaintShape, TextRun};
use craft_ui::runtime::env::Label;
use craft_ui::style::{ComponentStyle, DataColor, StyleCx, TextLook, TypeRole};
@@ -83,6 +83,7 @@ impl FramePreview {
}
impl Component for FramePreview {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::IMAGE;
const INPUT: Input = Input::Display;
const PARTS: bool = false;
+2 -1
View File
@@ -1,7 +1,7 @@
//! `Picture`: an image from pixels the caller makes, at the icon side or a thumbnail step.
use super::display_sense;
use crate::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role};
use crate::contract::{Access, Common, Component, Cx, DisabledLook, MeasureCx, PaintUi, Props as _, Role};
use crate::list::{ThumbAspect, ThumbSize};
use crate::primitives::{Revision, TextureStore, TextureStoreOptions, fit_rect};
use crate::runtime::env::Label;
@@ -67,6 +67,7 @@ impl<'a> Picture<'a> {
}
impl Component for Picture<'_> {
const DISABLED: DisabledLook = DisabledLook::Faded;
const ROLE: Role = Role::IMAGE;
const PARTS: bool = false;
const ALT_ROLES: &'static [Role] = &[Role::None];