ui-widgets segmented: a picked segment follows ActiveLook; under ActiveLook::Pressed it takes state.pressed with text.normal at rest, under the pointer and pressed, as an icon button that is on does; ActiveLook::Accent, the default, keeps state.selected with text.on_selected. Segmented story under Pressed

This commit is contained in:
bflatastic committed 2026-11-24 19:38:21 +07:00
1 parent 68cde01dc5
commit 7cb5edfda4
3 files changed
+27 -7

No files matched your search

+3 -2
View File
@@ -63,8 +63,9 @@ 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.
/// How an icon button or a segment 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; an app sets it at its root (`RootEnv::values`) for its
/// segmented pickers as well.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, EnvValue, MemoProps)]
#[env(style)]
#[non_exhaustive]
+9 -4
View File
@@ -2,6 +2,7 @@
//! face that is flat and muted, with a hover fill, and takes the selection fill and edge while it is picked. The row is one Tab stop over its segments: arrows, Home and End move focus between them, Space,
//! Enter or a click picks the focused one.
use crate::buttons::ActiveLook;
use crate::buttons::face::{self, FaceLook, FaceSpec};
use crate::contract::{
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Entry, MeasureCx, Name, PaintUi, PartsCx, Props as _, Role, SetPosition,
@@ -214,8 +215,12 @@ impl Component for Segment {
fn style(cx: &StyleCx<'_>, _: SegmentStyleKey) -> SegmentStyle {
let colors = &cx.tokens.color;
let c = |rgba| cx.color(rgba);
let (clear, selected, selected_hover) = (c(Rgba::TRANSPARENT), c(colors.state.selected), c(colors.state.selected_hover));
let disabled = c(colors.state.disabled_fill);
// The picked segment wears the look of an icon button that is on (`face::pressed_parts` under `Pressed`).
let (selected, selected_hover, on_ink) = match cx.env::<ActiveLook>() {
ActiveLook::Accent => (c(colors.state.selected), c(colors.state.selected_hover), c(colors.text.on_selected)),
ActiveLook::Pressed => (c(colors.state.pressed), c(colors.state.pressed), c(colors.text.normal)),
};
let (clear, disabled) = (c(Rgba::TRANSPARENT), c(colors.state.disabled_fill));
let fill = cx.state_layer().on(States::new(selected, selected_hover, selected_hover, disabled));
let edge = Stateful::new(c(colors.line.control_edge)).off(States::new(clear, clear, clear, clear)).on(States::new(
c(colors.line.control_edge),
@@ -223,8 +228,8 @@ impl Component for Segment {
c(colors.line.control_edge),
c(colors.line.divider),
));
let (muted, on_selected, off) = (c(colors.text.muted), c(colors.text.on_selected), c(colors.text.disabled));
let ink = Stateful::new(muted).off(States::new(muted, muted, muted, off)).on(States::new(on_selected, on_selected, on_selected, off));
let (muted, off) = (c(colors.text.muted), c(colors.text.disabled));
let ink = Stateful::new(muted).off(States::new(muted, muted, muted, off)).on(States::new(on_ink, on_ink, on_ink, off));
let control = cx.segment_control();
SegmentStyle {
// The selected segment rises: a bevelled theme draws the raised bevel, a flat one the edge alone.
@@ -1,8 +1,9 @@
//! Stories of `Segmented`.
use super::Segmented;
use crate::buttons::ActiveLook;
use crate::contract::{Entry, Props as _, Show as _, Validity};
use crate::runtime::env::Message;
use crate::runtime::env::{Message, with_env};
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story};
use craft_behavior::{IconId, Mixed};
use craft_theme::ControlSize;
@@ -89,3 +90,16 @@ fn segmented_icons(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
fn segmented_icons_five(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
icon_row(ui, data, 5, 2)
}
/// The row of an app that sets `ActiveLook::Pressed` at its root: the picked segment takes the pressed
/// fill with the normal text colour, as an icon button that is on does, at rest, under the pointer and pressed.
#[story(Segmented<'static, u8>, covers = [], drive = Drive::Custom(pick_add), group = "Text", title = "Pressed look")]
fn segmented_pressed_look(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
with_env(
ui,
|overrides| {
overrides.values.set(ActiveLook::Pressed);
},
|ui| text_row(ui, data, 3, 0, ControlSize::Md),
)
}