mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
Reset dot: a ring at the default, the state layer and a tooltip
The label's reset mark shows a ring in text.disabled while the value is at its reset value, so the slot shows before anything changes, and the filled dot while it differs. The dot part takes the state layer and the tooltip "Reset to default" (common.resetToDefault).
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::<CommonWords>().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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Shape> {
|
||||
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<Shape> {
|
||||
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()))]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<StyleColor> {
|
||||
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`.
|
||||
|
||||
Reference in New Issue
Block a user