From bb06692b13fe9ccca9c793b9b723d8ec487597e7 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Tue, 24 Nov 2026 12:57:45 +0700 Subject: [PATCH] ui-widgets, ui-panels: ActiveLook::Pressed shows an icon button that is on in the pressed fill with no accent edge; ToolRail::active_look gives it to the rail's buttons --- crates/ui-panels/src/rails/tool.rs | 9 +++++++-- crates/ui-panels/src/rails/tool/stories.rs | 11 +++++++++++ crates/ui-widgets/src/buttons/face.rs | 16 ++++++++++++++-- crates/ui-widgets/src/buttons/mod.rs | 13 +++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/crates/ui-panels/src/rails/tool.rs b/crates/ui-panels/src/rails/tool.rs index 9f34062de..ecd19c185 100644 --- a/crates/ui-panels/src/rails/tool.rs +++ b/crates/ui-panels/src/rails/tool.rs @@ -3,7 +3,7 @@ use super::flyout::{FlyoutButton, SlotEdit}; use super::words::RailWords; -use crate::buttons::IconButton; +use crate::buttons::{ActiveLook, IconButton}; use crate::contract::{ Access, Common, Component, Container, ContainerProps, Cx, FooterRegion, Gap, NoValue, Outcome, Pad, Pointer as _, Props as _, Role, Scroll, Show as _, ShowContainer as _, Sizing, WordSetCx as _, @@ -185,6 +185,9 @@ pub struct ToolRail<'a, T: Value + MemoProps + PlainData + 'static> { /// How tightly the rail packs its buttons; its columns follow the rail grid at that density. #[prop] density: RailDensity, + /// How the button of the current tool shows it is on. + #[prop] + active_look: ActiveLook, footer: Option>, /// The columns the rail lays out in this pass. columns: usize, @@ -222,6 +225,7 @@ impl<'a, T: Value + MemoProps + PlainData + 'static> ToolRail<'a, T> { reveal: None, tips: None, density: RailDensity::Regular, + active_look: ActiveLook::Accent, footer: None, columns: 1, shown: Rc::default(), @@ -545,9 +549,10 @@ impl Component for ToolRail<'_, T> { } } - /// The rail's density reaches its buttons. + /// The rail's density and active look reach its buttons. fn content_env(&self, _: &Cx<'_, Self>, values: &mut AppValues) { values.set(self.density); + values.set(self.active_look); } /// While the toolbar is edited the rail takes the drops its buttons do not: a blank toolbar's, and those in the room diff --git a/crates/ui-panels/src/rails/tool/stories.rs b/crates/ui-panels/src/rails/tool/stories.rs index c15ee0579..f566e9d4a 100644 --- a/crates/ui-panels/src/rails/tool/stories.rs +++ b/crates/ui-panels/src/rails/tool/stories.rs @@ -1,6 +1,7 @@ //! Stories of `ToolRail`, and the commands its stories and the flyout's use as tools. use super::{LastUsed, RailDensity, RailTool, ToolRail, ToolRailOutput, ToolSlot, ToolTips}; +use crate::buttons::ActiveLook; use crate::contract::{MemoProps, Show as _, Tracked}; use crate::display::{Shade, Text}; use crate::runtime::env::Env; @@ -126,6 +127,16 @@ fn tool_rail_density(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { in_columns(ui, columns, slots.len(), None, ToolRail::new("Tools", &slots, &BRUSH, &last).density(density)).into() } +/// The current tool (the brush) in each active look: the accent's soft fill and edge, or the pressed fill with no +/// edge. +#[story(ToolRail<'static, u8>, covers = [], drive = Drive::Never)] +fn tool_rail_active_look(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let look = *data.choice("active look", ActiveLook::Pressed, &[("Accent", ActiveLook::Accent), ("Pressed", ActiveLook::Pressed)]); + let slots = Tracked::new(slots()); + let last = Tracked::new(LastUsed::default()); + in_columns(ui, 1, slots.len(), None, ToolRail::new("Tools", &slots, &BRUSH, &last).active_look(look)).into() +} + /// The tips of the brush and the eraser: the tool's name over what it does. #[derive(MemoProps)] struct StoryTips; diff --git a/crates/ui-widgets/src/buttons/face.rs b/crates/ui-widgets/src/buttons/face.rs index 7a331f0aa..136b28b95 100644 --- a/crates/ui-widgets/src/buttons/face.rs +++ b/crates/ui-widgets/src/buttons/face.rs @@ -1,7 +1,7 @@ //! What a push or toggle button shows: a leading icon (or spinner), a label and a trailing icon, centred in the //! button unless it aligns them to an edge, and the look parts the buttons share. -use super::{ControlPlace, GroupLevel, RibbonLook}; +use super::{ActiveLook, ControlPlace, GroupLevel, RibbonLook}; use crate::contract::{Component, Cx, MeasureCx, PaintUi, Styled as _}; use crate::list::ThumbAspect; use crate::primitives::{HAlign, IconSpec, TextLayout, TextRun}; @@ -396,7 +396,11 @@ pub(crate) struct IconFace { /// button of the old look (a capsule would round the on plate), showing the on look while on. The scope's glyph role /// sets the glyph's side and, in a rail, the quieter ink it rests in. pub(crate) fn icon_face(cx: &StyleCx<'_>) -> IconFace { - let (off, on) = (cx.variant_look(), on_parts(cx)); + let on = match cx.env::() { + ActiveLook::Accent => on_parts(cx), + ActiveLook::Pressed => pressed_parts(cx), + }; + let off = cx.variant_look(); let (icon, text) = (&cx.tokens.size.icon, &cx.tokens.color.text); let (side, rest) = match cx.glyph_role() { GlyphRole::Tool => (icon.md, None), @@ -426,6 +430,14 @@ pub(super) fn on_parts(cx: &StyleCx<'_>) -> VariantParts { VariantParts { fill: Stateful::new(fill), text: Stateful::new(ink).off(States::new(ink, ink, ink, soft.text.off.disabled)), ..soft } } +/// The on look under `ActiveLook::Pressed`: the pressed state's fill with no edge, the normal text colour. +fn pressed_parts(cx: &StyleCx<'_>) -> VariantParts { + let soft = on_parts(cx); + let colors = &cx.tokens.color; + let (fill, ink) = (cx.color(colors.state.pressed), cx.color(colors.text.normal)); + VariantParts { fill: Stateful::new(fill), text: Stateful::new(ink).off(States::new(ink, ink, ink, soft.text.off.disabled)), edge: None, ..soft } +} + /// The focus ring of a button. pub(crate) fn focus(cx: &StyleCx<'_>) -> FocusLook { cx.focus_look() diff --git a/crates/ui-widgets/src/buttons/mod.rs b/crates/ui-widgets/src/buttons/mod.rs index 101f7d9fd..3b9e5ba2a 100644 --- a/crates/ui-widgets/src/buttons/mod.rs +++ b/crates/ui-widgets/src/buttons/mod.rs @@ -63,6 +63,19 @@ pub enum ControlPlace { SideMenu, } +/// How an icon button that is on shows it. A tool rail sets it for its buttons (`ToolRail::active_look`), so the +/// current tool can show the look an app's tools had. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, EnvValue, MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum ActiveLook { + /// The accent's soft fill and edge, with the accent's text colour. + #[default] + Accent, + /// The pressed state's fill with no edge, and the glyph in the normal text colour. + Pressed, +} + /// The style context a push or split button draws in: in a ribbon (`ControlPlace::Ribbon`) the default variant /// becomes the ghost one, so the button is flat at rest; any other variant, and any other place, stays as it is. pub(crate) fn placed<'a>(cx: &crate::style::StyleCx<'a>) -> crate::style::StyleCx<'a> {