diff --git a/crates/pages/src/ui/table/edges.rs b/crates/pages/src/ui/table/edges.rs index 9f5abe9f1..b755a00ea 100644 --- a/crates/pages/src/ui/table/edges.rs +++ b/crates/pages/src/ui/table/edges.rs @@ -394,11 +394,10 @@ impl Component for EdgePicker<'_> { let hovered = cx.hover_pos(SQUARE).and_then(|p| line_at(&lines, &keys, p, cx.style.inset)); for key in keys { let (a, b) = lines[key as usize]; - let (width, color) = if edges.get(key) || hovered == Some(key) { - (StrokeWidth::Thick, cx.resolve(&cx.style.on)) - } else { - (StrokeWidth::Thin, cx.resolve(&cx.style.off)) - }; + let (width, color) = + if edges.get(key) { (StrokeWidth::Thick, cx.resolve(&cx.style.on)) } else { (StrokeWidth::Thin, cx.resolve(&cx.style.off)) }; + // The line under the pointer widens in its own colour, so hovering never looks like choosing. + let width = if hovered == Some(key) { StrokeWidth::Heavy } else { width }; draw.stroke(&PaintShape::Path(vec![a, b]), width, color); } } diff --git a/crates/ui-contract/src/contract/label/leaf.rs b/crates/ui-contract/src/contract/label/leaf.rs index 95087f417..f7714369d 100644 --- a/crates/ui-contract/src/contract/label/leaf.rs +++ b/crates/ui-contract/src/contract/label/leaf.rs @@ -186,7 +186,8 @@ impl Component for LabelLeaf { fn parts(&mut self, _rect: Rect, cx: &mut PartsCx<'_, Self>) { if self.slot > 0.0 && self.differs { let (slot, _) = cx.flow.take_end(self.slot); - cx.part(DOT, slot).sense(Sense::CLICK).pointer_only("the Reset command"); + let tip = cx.env.words::().reset_to_default.as_str().to_owned(); + cx.part(DOT, slot).sense(Sense::CLICK).state_layer().tooltip(tip).pointer_only("the Reset command"); } } @@ -245,8 +246,8 @@ impl Component for LabelLeaf { draw.text(centred(detail_flow.rect(), size.y), &run); } } - if self.differs && self.slot > 0.0 { - draw.reset_mark(&cx.style.reset, slot.center()); + if self.slot > 0.0 { + draw.reset_mark(&cx.style.reset, slot.center(), self.differs); } } diff --git a/crates/ui-contract/src/primitives/draw.rs b/crates/ui-contract/src/primitives/draw.rs index 458248c51..d2060c726 100644 --- a/crates/ui-contract/src/primitives/draw.rs +++ b/crates/ui-contract/src/primitives/draw.rs @@ -278,9 +278,9 @@ impl<'a> Draw<'a> { super::icon::paint(self.painter, self.env.tokens, self.env.direction, rect, icon); } - /// Paints the reset dot of `look` centred on `center`. - pub fn reset_mark(&self, look: &crate::style::ResetMarkLook, center: Pos2) { - self.painter.extend(super::ResetMark::shapes(look, center)); + /// Paints the reset mark of `look` centred on `center`: the dot while the value `differs`, else the ring. + pub fn reset_mark(&self, look: &crate::style::ResetMarkLook, center: Pos2, differs: bool) { + self.painter.extend(super::ResetMark::shapes(look, center, differs)); } /// `v` moved to the centre of the physical pixel it lies in: a line one physical pixel wide placed there fills that diff --git a/crates/ui-contract/src/primitives/reset_mark.rs b/crates/ui-contract/src/primitives/reset_mark.rs index dbd4d7b3c..c741bd42f 100644 --- a/crates/ui-contract/src/primitives/reset_mark.rs +++ b/crates/ui-contract/src/primitives/reset_mark.rs @@ -1,4 +1,5 @@ -//! `ResetMark`: the dot the label step shows beside a side label while the value differs from its reset value. +//! `ResetMark`: the mark the label step shows beside a side label: a dot while the value differs from its reset value, +//! a ring while it is at it. use crate::style::ResetMarkLook; use egui::{Pos2, Shape}; @@ -7,8 +8,13 @@ use egui::{Pos2, Shape}; pub struct ResetMark; impl ResetMark { - /// The dot centred on `center`. - pub fn shapes(look: &ResetMarkLook, center: Pos2) -> Vec { - vec![Shape::circle_filled(center, look.diameter / 2.0, look.color.egui())] + /// The mark centred on `center`: the dot while the value `differs`, else the ring. + pub fn shapes(look: &ResetMarkLook, center: Pos2, differs: bool) -> Vec { + let radius = look.diameter / 2.0; + if differs { + vec![Shape::circle_filled(center, radius, look.color.egui())] + } else { + vec![Shape::circle_stroke(center, radius - look.ring_width / 2.0, egui::Stroke::new(look.ring_width, look.ring.egui()))] + } } } diff --git a/crates/ui-contract/src/runtime/words/common.rs b/crates/ui-contract/src/runtime/words/common.rs index 9228d56ac..c88eb434c 100644 --- a/crates/ui-contract/src/runtime/words/common.rs +++ b/crates/ui-contract/src/runtime/words/common.rs @@ -8,6 +8,8 @@ craft_ui::words! { cancel: "common.cancel" = "Cancel"; ok: "common.ok" = "OK"; dont_show_again: "common.dontShowAgain" = "Don't show again"; + /// The tooltip of a label's reset dot. + reset_to_default: "common.resetToDefault" = "Reset to default"; /// A caption beside its control; a catalog writes its language's punctuation (French " :"). caption: template "common.caption" = "{caption}:"; /// Between the steps of a path (a menu path, a tree picker's selection); a catalog changes it for a diff --git a/crates/ui-contract/src/style/paint.rs b/crates/ui-contract/src/style/paint.rs index 0123a42ef..416e6bb8c 100644 --- a/crates/ui-contract/src/style/paint.rs +++ b/crates/ui-contract/src/style/paint.rs @@ -104,18 +104,34 @@ pub(crate) fn scroll_bar_look(tokens: &UiTokens) -> ScrollBarLook { ScrollBarLook { track, thumb, thickness: tokens.size.handle.sm, min_thumb: tokens.size.handle.md * 2.0, fade: tokens.size.scroll_fade } } -/// The reset dot's colour and diameter. +/// The reset dot's colours and diameter. #[derive(Clone, Copy, Debug, PartialEq)] #[non_exhaustive] pub struct ResetMarkLook { - /// The dot colour. + /// The dot colour, while the value differs from its reset value. pub color: StyleColor, + /// The ring colour, while the value is at its reset value: the slot shows before anything changes. + pub ring: StyleColor, + /// The ring's line width. + pub ring_width: f32, /// The dot diameter. pub diameter: f32, } +/// The state layer: the theme's hover and press fills, clear at rest and while disabled. An opaque state fill takes +/// the place of the rest fill of a part without a surface of its own. +pub(crate) fn state_layer_look(tokens: &UiTokens) -> Stateful { + let (clear, state) = (style_color(Rgba::TRANSPARENT), &tokens.color.state); + Stateful::new(clear).off(craft_theme::States::new(clear, style_color(state.hover), style_color(state.pressed), clear)) +} + pub(crate) fn reset_mark_look(tokens: &UiTokens) -> ResetMarkLook { - ResetMarkLook { color: style_color(tokens.color.accent.solid), diameter: tokens.size.handle.sm / 2.0 } + ResetMarkLook { + color: style_color(tokens.color.accent.solid), + ring: style_color(tokens.color.text.disabled), + ring_width: tokens.stroke.thin, + diameter: tokens.size.handle.sm / 2.0, + } } /// The colour of `ink` in `tokens`.