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

This commit is contained in:
bflatastic
2026-11-24 12:57:45 +07:00
parent 95c1456826
commit bb06692b13
4 changed files with 45 additions and 4 deletions
+7 -2
View File
@@ -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<FooterFn<'a>>,
/// 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<T: Value + MemoProps + PlainData + 'static> 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
@@ -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;
+14 -2
View File
@@ -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>() {
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()
+13
View File
@@ -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> {