mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 20:25:06 +00:00
Glyph roles for icon-only buttons: a container sets the role its buttons show their glyph in (child_glyphs, or glyphs on one component), so the tool rail draws size.icon.lg icons resting in text.muted, the panel rail rests in text.faint and AlignBar draws size.icon.md
This commit is contained in:
@@ -683,7 +683,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
let enabled = gate.unwrap_or(true);
|
||||
// What the body and the end region share: gate, size, roving group and commands. The body adds its arena,
|
||||
// transform and scroll owner; the end region lies outside them.
|
||||
let line_env = if enabled && props.child_size.is_none() && props.roving.is_none() {
|
||||
let line_env = if enabled && props.child_size.is_none() && props.child_glyphs.is_none() && props.roving.is_none() {
|
||||
region_env.clone()
|
||||
} else {
|
||||
region_env.derive_local(|scoped| {
|
||||
@@ -691,6 +691,9 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
if let Some(size) = props.child_size {
|
||||
scoped.size = size;
|
||||
}
|
||||
if let Some(role) = props.child_glyphs {
|
||||
scoped.glyphs = role;
|
||||
}
|
||||
if props.roving.is_some() {
|
||||
scoped.roving = Some(crate::contract::steps::body_group(id));
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::runtime::env::{EnvValue, Label};
|
||||
use crate::runtime::focus::FocusPolicy;
|
||||
use crate::runtime::memory::SaveKey;
|
||||
use crate::runtime::windows::WindowSpec;
|
||||
use crate::style::SurfaceKind;
|
||||
use crate::style::{GlyphRole, SurfaceKind};
|
||||
use craft_behavior::{CanvasTransform, Roving};
|
||||
use craft_theme::ControlSize;
|
||||
use egui::Rect;
|
||||
@@ -654,6 +654,8 @@ pub struct ContainerProps {
|
||||
pub edge_rule: bool,
|
||||
/// A scope size for the body.
|
||||
pub child_size: Option<ControlSize>,
|
||||
/// A scope glyph role for the body: how the icon-only buttons in it show their glyph.
|
||||
pub child_glyphs: Option<GlyphRole>,
|
||||
/// The container is an arena root.
|
||||
pub arena: bool,
|
||||
/// The container is its body's scroll owner without a scroll region, as a canvas with a view of its own is: the
|
||||
@@ -713,6 +715,7 @@ impl ContainerProps {
|
||||
&& self.body_gap == other.body_gap
|
||||
&& self.least_width == other.least_width
|
||||
&& self.child_size == other.child_size
|
||||
&& self.child_glyphs == other.child_glyphs
|
||||
&& self.transform == other.transform
|
||||
&& self.theme == other.theme
|
||||
&& self.label == other.label
|
||||
@@ -742,6 +745,7 @@ impl ContainerProps {
|
||||
least_width: None,
|
||||
edge_rule: false,
|
||||
child_size: None,
|
||||
child_glyphs: None,
|
||||
arena: false,
|
||||
scroll_owner: false,
|
||||
gates: false,
|
||||
@@ -876,6 +880,12 @@ impl ContainerProps {
|
||||
self
|
||||
}
|
||||
|
||||
/// A scope glyph role for the body: a rail's buttons show its icons at the rail's side and ink.
|
||||
pub const fn child_glyphs(mut self, role: GlyphRole) -> Self {
|
||||
self.child_glyphs = Some(role);
|
||||
self
|
||||
}
|
||||
|
||||
/// Makes the container's `bool` value a gate on its content.
|
||||
#[doc(hidden)]
|
||||
pub const fn gates(mut self) -> Self {
|
||||
|
||||
@@ -437,13 +437,16 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
|
||||
if let Some(scope) = command_scope {
|
||||
crate::runtime::commands::register_instance(&ctx, scope, id);
|
||||
}
|
||||
let child_size = comp.props(Internal::new()).child_size;
|
||||
let (child_size, child_glyphs) = (comp.props(Internal::new()).child_size, comp.props(Internal::new()).child_glyphs);
|
||||
// The rows sit on the surface the collection paints, else on the one the collection sits on.
|
||||
let own = surface.or_else(|| cx.style.surface().and_then(|look| look.kind_in(&cx.core.state)));
|
||||
let base_env = env.derive(|scoped| {
|
||||
scoped.extend_values(values);
|
||||
scoped.arena = Some(ArenaId::new(id));
|
||||
scoped.size = child_size.unwrap_or(cx.core.resolved.size);
|
||||
if let Some(role) = child_glyphs {
|
||||
scoped.glyphs = role;
|
||||
}
|
||||
scoped.surface = SurfaceKind::under(own, scoped.surface);
|
||||
});
|
||||
self.header.paint(ui, cx, env, id, rtl);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use super::{IdSource, Internal, Meta, Sizing};
|
||||
use crate::runtime::commands::{CommandRef, CommandScope};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::GlyphRole;
|
||||
use craft_behavior::DocKey;
|
||||
use craft_theme::{ControlSize, Variant};
|
||||
use egui::{AsIdSalt, Id, IdSalt};
|
||||
@@ -17,6 +18,7 @@ pub struct Common {
|
||||
pub(crate) enabled: Option<bool>,
|
||||
pub(crate) read_only: Option<bool>,
|
||||
pub(crate) size: Option<ControlSize>,
|
||||
pub(crate) glyphs: Option<GlyphRole>,
|
||||
pub(crate) variant: Option<Variant>,
|
||||
#[doc(hidden)]
|
||||
pub tooltip: Option<Tooltip>,
|
||||
@@ -47,6 +49,7 @@ impl Common {
|
||||
enabled: None,
|
||||
read_only: None,
|
||||
size: None,
|
||||
glyphs: None,
|
||||
variant: None,
|
||||
tooltip: None,
|
||||
description: None,
|
||||
@@ -101,6 +104,13 @@ pub trait Props: Meta + Sized {
|
||||
self
|
||||
}
|
||||
|
||||
/// How the component's icon-only buttons show their glyph, over the scope's role. A composite passes it on to the
|
||||
/// buttons it shows as faces.
|
||||
fn glyphs(mut self, role: GlyphRole) -> Self {
|
||||
self.common_mut(Internal::new()).glyphs = Some(role);
|
||||
self
|
||||
}
|
||||
|
||||
/// How the component takes its size. A container or collection takes it over its own default (`ContainerProps`).
|
||||
/// A leaf with `Sizing::Content` is as wide as its content, without the ideal width its style asks for where the
|
||||
/// room allows (a field's `size.length.field`); a leaf otherwise keeps that width, and fills only along the axis
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::contract::{Common, Component, Resolved};
|
||||
use crate::runtime::commands::{self, ResolvedCommand};
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::style::{ComponentStyle, accepted_variant};
|
||||
use crate::style::{ComponentStyle, GlyphRole, accepted_variant};
|
||||
use craft_theme::{ControlSize, Variant};
|
||||
use egui::{Context, Id};
|
||||
use std::sync::Arc;
|
||||
@@ -13,6 +13,7 @@ pub(crate) struct EnvStep {
|
||||
pub enabled: bool,
|
||||
pub read_only: bool,
|
||||
pub size: ControlSize,
|
||||
pub glyphs: GlyphRole,
|
||||
/// The variant the component accepts for the one requested.
|
||||
pub variant: Variant,
|
||||
/// The variant as requested, which the style cache logs a fallback from.
|
||||
@@ -41,6 +42,7 @@ pub(crate) fn env(ctx: &Context, env: &Env, common: &Common, (requested, variant
|
||||
enabled: common.enabled.unwrap_or(true) && env.enabled && command.as_ref().is_none_or(|command| command.enabled),
|
||||
read_only: common.read_only == Some(true) || env.read_only,
|
||||
size: common.size.unwrap_or(env.size),
|
||||
glyphs: common.glyphs.unwrap_or(env.glyphs),
|
||||
variant,
|
||||
requested,
|
||||
label,
|
||||
|
||||
@@ -10,6 +10,7 @@ use std::sync::Arc;
|
||||
/// The `StyleCx` of the env the component shows in.
|
||||
pub(crate) fn style_cx<'a>(ctx: &'a Context, env: &'a Env, step: &EnvStep) -> StyleCx<'a> {
|
||||
StyleCx::new(ctx, &env.tokens, &env.values, step.size, step.requested, env.direction, env.scale, env.os, env.active, env.key, env.line_ratio)
|
||||
.with_glyphs(step.glyphs)
|
||||
}
|
||||
|
||||
/// Step 2, style: `&C::Style` from the cache, keyed `(TypeId of StyleKey, key, EnvKey, variant, size)`.
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::runtime::egui::memory::FastMap;
|
||||
use crate::runtime::egui::{pass, repaint, scale, stack, style};
|
||||
use crate::runtime::frame::PerViewport;
|
||||
use crate::runtime::windows;
|
||||
use crate::style::{EnvKey, Ink, SurfaceKind, UiTokens};
|
||||
use crate::style::{EnvKey, GlyphRole, Ink, SurfaceKind, UiTokens};
|
||||
use craft_behavior::{CanvasTransform, MotionMode};
|
||||
use craft_host::Host;
|
||||
use craft_host::target::{Os, ShellInfo};
|
||||
@@ -78,6 +78,8 @@ pub struct Scoped {
|
||||
pub key: EnvKey,
|
||||
/// Ambient control size; the root default is `Md`.
|
||||
pub size: ControlSize,
|
||||
/// How the icon-only buttons of the scope show their glyph; the root default and a layer's is `Control`.
|
||||
pub glyphs: GlyphRole,
|
||||
/// AND of every scope and gate above.
|
||||
pub enabled: bool,
|
||||
/// OR of every scope above.
|
||||
@@ -399,6 +401,7 @@ impl Env {
|
||||
ink: Ink::default(),
|
||||
surface: SurfaceKind::Background,
|
||||
size: ControlSize::Md,
|
||||
glyphs: GlyphRole::Control,
|
||||
enabled: true,
|
||||
read_only: false,
|
||||
wheel: WheelScope::Plain,
|
||||
@@ -476,6 +479,7 @@ impl Env {
|
||||
s.unbounded = (false, false);
|
||||
s.lazy = None;
|
||||
s.pane_edge = None;
|
||||
s.glyphs = GlyphRole::Control;
|
||||
s.item = None;
|
||||
s.row = None;
|
||||
s.item_facts = None;
|
||||
|
||||
@@ -21,6 +21,22 @@ use std::any::{Any, TypeId};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// How the icon-only buttons of a scope show their glyph, set by the container that holds them
|
||||
/// (`ContainerProps::child_glyphs`) or on one component (`Props::glyphs`). Each role reads size tokens only.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum GlyphRole {
|
||||
/// A glyph inside a control: `size.icon.glyph_sm` or `glyph_md` by the control size, in the variant's ink.
|
||||
#[default]
|
||||
Control,
|
||||
/// A command strip of tool icons (align and distribute): `size.icon.md`, in the variant's ink.
|
||||
Tool,
|
||||
/// A tool rail: `size.icon.lg`, resting in `text.muted` and in the variant's ink under the pointer.
|
||||
ToolRail,
|
||||
/// A panel rail: the control glyph, resting in `text.faint` and in the variant's ink under the pointer.
|
||||
PanelRail,
|
||||
}
|
||||
|
||||
/// What `fn style` gets. Tokens are read here and nowhere else.
|
||||
#[derive(Clone, Copy)]
|
||||
#[non_exhaustive]
|
||||
@@ -41,6 +57,8 @@ pub struct StyleCx<'a> {
|
||||
pub active: bool,
|
||||
/// The key of everything above that the style cache depends on.
|
||||
pub key: EnvKey,
|
||||
/// The glyph role of the scope; the key folds it in when it is not `Control`.
|
||||
glyphs: GlyphRole,
|
||||
/// The text colour of the part this component is shown as the face of.
|
||||
host: Option<&'a Stateful<StyleColor>>,
|
||||
/// The muted text colour of the host part, when the host has one.
|
||||
@@ -126,7 +144,22 @@ impl<'a> StyleCx<'a> {
|
||||
key: EnvKey,
|
||||
line_ratio: f32,
|
||||
) -> Self {
|
||||
StyleCx { tokens, size, variant, direction, scale, os, active, key, host: None, host_muted: None, line_ratio, ctx, values }
|
||||
StyleCx {
|
||||
tokens,
|
||||
size,
|
||||
variant,
|
||||
direction,
|
||||
scale,
|
||||
os,
|
||||
active,
|
||||
key,
|
||||
glyphs: GlyphRole::Control,
|
||||
host: None,
|
||||
host_muted: None,
|
||||
line_ratio,
|
||||
ctx,
|
||||
values,
|
||||
}
|
||||
}
|
||||
|
||||
/// The same context with another variant.
|
||||
@@ -135,6 +168,12 @@ impl<'a> StyleCx<'a> {
|
||||
StyleCx { variant, ..*self }
|
||||
}
|
||||
|
||||
/// The same context in a scope whose icon-only buttons show their glyph in `role`.
|
||||
pub(crate) fn with_glyphs(&self, role: GlyphRole) -> StyleCx<'a> {
|
||||
let key = if role == GlyphRole::Control { self.key } else { self.key.folded(role as u64 + 1) };
|
||||
StyleCx { glyphs: role, key, ..*self }
|
||||
}
|
||||
|
||||
/// The same context for a component shown as the face of a part whose text colour is `ink` and whose muted text
|
||||
/// colour is `muted`. The key folds both in, so a face's cached styles are per host look.
|
||||
pub(crate) fn hosted(&self, ink: &'a Stateful<StyleColor>, muted: Option<&'a Stateful<StyleColor>>) -> StyleCx<'a> {
|
||||
@@ -269,6 +308,11 @@ impl<'a> StyleCx<'a> {
|
||||
BySize { sm: icon.glyph_sm, md: icon.glyph_md }.get(self.size)
|
||||
}
|
||||
|
||||
/// How the icon-only buttons of the scope show their glyph.
|
||||
pub fn glyph_role(&self) -> GlyphRole {
|
||||
self.glyphs
|
||||
}
|
||||
|
||||
/// `control` at `size`, whatever the ambient size: the part of a control that keeps its own size (a field's
|
||||
/// adornment button) reads its height here.
|
||||
pub fn control_of(&self, size: ControlSize) -> ControlMetrics {
|
||||
|
||||
@@ -19,7 +19,7 @@ pub use craft_theme::GroupValues;
|
||||
pub use craft_theme::{FlagMask, Flags, Mix, Resolve, State, StateMix, Stateful, States, TokenGroup, Tokens, TypeRole, Variant};
|
||||
pub use craft_ui_macros::{ComponentStyle, TokenGroup};
|
||||
pub(crate) use cx::control_metrics;
|
||||
pub use cx::{StyleCx, VariantParts};
|
||||
pub use cx::{GlyphRole, StyleCx, VariantParts};
|
||||
pub use key::{EnvKey, Ink, StyleKey};
|
||||
pub(crate) use look::StyleView;
|
||||
pub use look::{ComponentStyle, Corners, DataColor, FocusLook, IconLook, StyleColor, SurfaceKind, SurfaceLook, TextLook, TrackLook};
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::contract::{
|
||||
use crate::menu::{self, Menu, MenuItem};
|
||||
use crate::runtime::commands::{FireSource, ResolvedCommand};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, StyleCx};
|
||||
use crate::style::{ComponentStyle, GlyphRole, StyleCx};
|
||||
use craft_behavior::overlay::{Align, Side};
|
||||
use craft_behavior::{HitLevel, HitPriority, IconId, Metrics, PartKey, PointerButton, PressPhase, Sense, Value};
|
||||
use egui::{Rect, Response, Vec2};
|
||||
@@ -32,6 +32,8 @@ pub struct FlyoutButtonStyle {
|
||||
metrics: Metrics,
|
||||
/// The side of the corner mark, which is also its inset from the face's corner.
|
||||
mark: f32,
|
||||
/// The button's glyph role, which its face shows the icon in.
|
||||
glyphs: GlyphRole,
|
||||
}
|
||||
|
||||
/// A rail button that is dragged and takes drops while the toolbar is edited.
|
||||
@@ -147,16 +149,17 @@ impl<'a, T: Value + 'static> FlyoutButton<'a, T> {
|
||||
self.tools.iter().position(|tool| tool.id == *self.shown).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// The face the button shows: the shown tool's icon, in the look of its command (label, enabled state, marked dot).
|
||||
/// The face the button shows: the shown tool's icon in the button's glyph role, in the look of its command (label,
|
||||
/// enabled state, marked dot).
|
||||
/// The button itself runs the command, so the face only wears it, and the button's selected state with it.
|
||||
fn face(&self, laid: &Laid, selected: bool) -> IconButton<'static> {
|
||||
fn face(&self, laid: &Laid, selected: bool, glyphs: GlyphRole) -> IconButton<'static> {
|
||||
let resolved = laid.resolved.get(laid.shown).and_then(Option::as_ref);
|
||||
let icon = resolved.and_then(|resolved| resolved.icon.clone()).map_or_else(|| IconId::new("more"), IconId::from);
|
||||
let face = match self.tools.get(laid.shown) {
|
||||
Some(tool) => IconButton::command(icon, tool.command.clone()),
|
||||
None => IconButton::new(icon),
|
||||
};
|
||||
let mut face = face.selected(selected);
|
||||
let mut face = face.selected(selected).glyphs(glyphs);
|
||||
if self.has_flyout() {
|
||||
face = face.popup(PopupKind::Menu).popup_mark(true);
|
||||
}
|
||||
@@ -176,12 +179,12 @@ impl<T: Value + 'static> Component for FlyoutButton<'_, T> {
|
||||
|
||||
fn style(cx: &StyleCx<'_>, _: FlyoutButtonStyleKey<T>) -> FlyoutButtonStyle {
|
||||
let side = cx.tokens.size.rail.button;
|
||||
FlyoutButtonStyle { metrics: Metrics::new().min_size(Vec2::splat(side)), mark: cx.tokens.space.gap.tight }
|
||||
FlyoutButtonStyle { metrics: Metrics::new().min_size(Vec2::splat(side)), mark: cx.tokens.space.gap.tight, glyphs: cx.glyph_role() }
|
||||
}
|
||||
|
||||
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
|
||||
let laid = self.resolve(cx);
|
||||
cx.face(self.face(&laid, cx.resolved.selected == Some(true)))
|
||||
cx.face(self.face(&laid, cx.resolved.selected == Some(true), cx.style.glyphs))
|
||||
}
|
||||
|
||||
/// A button that is edited is dragged; one with a flyout senses a drag away from it, which opens the flyout.
|
||||
@@ -316,7 +319,7 @@ impl<T: Value + 'static> Component for FlyoutButton<'_, T> {
|
||||
|
||||
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
let Some(laid) = &self.laid else { return };
|
||||
let face = self.face(laid, cx.resolved.selected == Some(true));
|
||||
let face = self.face(laid, cx.resolved.selected == Some(true), cx.style.glyphs);
|
||||
ui.face(FACE, face);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
|
||||
use super::FlyoutButton;
|
||||
use crate::contract::overlay::HOLD;
|
||||
use crate::contract::{Role, Show as _};
|
||||
use crate::contract::{Props as _, Role, Show as _};
|
||||
use crate::rails::tool::stories::{BRUSH, tools};
|
||||
use crate::style::GlyphRole;
|
||||
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
#[story(FlyoutButton<'static, u8>, covers = [Default], drive = Drive::Activate)]
|
||||
fn flyout_button(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let tools = tools(&[BRUSH, BRUSH + 1, BRUSH + 2]);
|
||||
FlyoutButton::new(&tools, &BRUSH).show(ui).into()
|
||||
// The button as a tool rail shows it, holding the current tool.
|
||||
FlyoutButton::new(&tools, &BRUSH).glyphs(GlyphRole::ToolRail).selected(true).show(ui).into()
|
||||
}
|
||||
|
||||
/// Holds the press on the button, which opens the flyout.
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::contract::{
|
||||
use crate::runtime::access::Name;
|
||||
use crate::runtime::commands;
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, StyleCx, SurfaceKind};
|
||||
use crate::style::{ComponentStyle, GlyphRole, StyleCx, SurfaceKind};
|
||||
use craft_behavior::{Metrics, NavShape, Roving, Sense, Value};
|
||||
use craft_theme::ControlSize;
|
||||
use egui::{Response, Ui};
|
||||
@@ -89,6 +89,7 @@ impl<'a, P: Value + 'static> PanelRail<'a, P> {
|
||||
.layout(BodyLayout::stack())
|
||||
.body_gap(Gap::Tight)
|
||||
.child_size(ControlSize::Md)
|
||||
.child_glyphs(GlyphRole::PanelRail)
|
||||
.roving(Roving::new(NavShape::Flat))
|
||||
.scroll(Scroll::vertical())
|
||||
.footer(FooterRegion::new())
|
||||
|
||||
@@ -71,3 +71,40 @@ fn a_marked_panel_icon_shows_its_mark_only_while_the_panel_is_closed_and_each_ic
|
||||
assert!(closed > open, "the mark shows while the panel is closed ({closed}) and not while open ({open})");
|
||||
assert_eq!(items, 3, "one response per icon");
|
||||
}
|
||||
|
||||
/// The rails set the glyph role of their buttons: the tool rail's icons are larger than a lone icon button's and rest
|
||||
/// in a quieter ink than they show under the pointer; the panel rail's keep the lone button's side and rest quieter
|
||||
/// than it.
|
||||
#[trial]
|
||||
fn the_rails_show_their_buttons_icons_in_their_glyph_roles() {
|
||||
use crate::buttons::IconButton;
|
||||
use crate::contract::Props as _;
|
||||
use crate::rails::{LastUsed, ToolRail, ToolSlot};
|
||||
use craft_behavior::IconId;
|
||||
let glyphs = |rail: Option<bool>| {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let panels = tools(&[0, 1]);
|
||||
match rail {
|
||||
Some(true) => {
|
||||
let slots = vec![ToolSlot::new(0, panels.clone())];
|
||||
ToolRail::new("Tools", &slots, &0, &LastUsed::default()).show_rail(ui, |_, _| {});
|
||||
}
|
||||
Some(false) => {
|
||||
PanelRail::new("Panels", &panels).show_rail(ui, |_| {});
|
||||
}
|
||||
None => {
|
||||
IconButton::new(IconId::new("move")).label("Alone").show(ui);
|
||||
}
|
||||
}
|
||||
});
|
||||
fixture.settle();
|
||||
let seen = fixture.styles_of(std::any::type_name::<IconButton<'static>>());
|
||||
let glyph = seen.first().and_then(|seen| seen.looks.icons.first().cloned());
|
||||
glyph.unwrap_or_else(|| panic!("an icon button showed ({rail:?})"))
|
||||
};
|
||||
let (alone, tool, panel) = (glyphs(None), glyphs(Some(true)), glyphs(Some(false)));
|
||||
assert!(tool.side > alone.side, "a tool rail icon ({}) is larger than a lone one ({})", tool.side, alone.side);
|
||||
assert!(tool.color.off.rest != tool.color.off.hover, "a tool rail icon rests quieter than under the pointer");
|
||||
assert_eq!(panel.side, alone.side, "a panel rail icon keeps the control glyph");
|
||||
assert!(panel.color.off.rest != alone.color.off.rest, "a panel rail icon rests quieter than a lone one");
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::layout_components::{Row, Stack};
|
||||
use crate::runtime::access::Name;
|
||||
use crate::runtime::commands::Commands as _;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::style::{ComponentStyle, StyleCx, SurfaceKind};
|
||||
use crate::style::{ComponentStyle, GlyphRole, StyleCx, SurfaceKind};
|
||||
use craft_behavior::overlay::Side;
|
||||
use craft_behavior::{IconId, Metrics, NavShape, Roving, Sense, Value};
|
||||
use craft_theme::ControlSize;
|
||||
@@ -151,6 +151,7 @@ impl<'a, T: Value + 'static> ToolRail<'a, T> {
|
||||
.layout(BodyLayout::stack())
|
||||
.body_gap(Gap::Inline)
|
||||
.child_size(ControlSize::Md)
|
||||
.child_glyphs(GlyphRole::ToolRail)
|
||||
.scroll(Scroll::vertical())
|
||||
.footer(FooterRegion::new());
|
||||
ToolRail {
|
||||
|
||||
@@ -6,6 +6,7 @@ use super::items::{BarItem, BarItems, MoreMenu};
|
||||
use super::words::BarWords;
|
||||
use crate::contract::{NoValue, Outcome, Props as _, Show as _};
|
||||
use crate::runtime::env::Env;
|
||||
use crate::style::GlyphRole;
|
||||
use craft_behavior::fit::FitKeep;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
@@ -114,7 +115,8 @@ impl Outcome for AlignBarOutput {
|
||||
}
|
||||
|
||||
/// The align buttons, the optional distribute buttons and the menu button, shown as children of a `Bar`. The menu
|
||||
/// lists every command, the align commands, a rule, then the distribute commands.
|
||||
/// lists every command, the align commands, a rule, then the distribute commands. The buttons show their icons at the
|
||||
/// tool size (`GlyphRole::Tool`).
|
||||
#[derive(crate::contract::Pattern)]
|
||||
pub struct AlignBar {
|
||||
distribute: DistributeButtons,
|
||||
@@ -139,7 +141,7 @@ impl AlignBar {
|
||||
let distribute_keep = if self.distribute == DistributeButtons::Row { FitKeep::Free } else { FitKeep::Menu };
|
||||
let align = AlignAction::ALIGN.into_iter().map(BarItem::new);
|
||||
let distribute = AlignAction::DISTRIBUTE.into_iter().map(|action| BarItem::new(action).section(1).keep(distribute_keep));
|
||||
let response = BarItems::new(align.chain(distribute).collect()).label(name).more(MoreMenu::Every).show(ui);
|
||||
let response = BarItems::new(align.chain(distribute).collect()).label(name).more(MoreMenu::Every).glyphs(GlyphRole::Tool).show(ui);
|
||||
AlignBarOutput { response }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::menu::{Menu, MenuItem};
|
||||
use crate::primitives::IconSpec;
|
||||
use crate::runtime::commands::{CommandRef, ResolvedCommand};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, StyleCx};
|
||||
use crate::style::{ComponentStyle, GlyphRole, StyleCx};
|
||||
use craft_behavior::fit::{FitItem, FitKeep, fit_items};
|
||||
use craft_behavior::{Axis, IconId, Metrics, NavShape, PartKey, PartRef, Proposal, Roving, Sense};
|
||||
use craft_theme::Variant;
|
||||
@@ -100,6 +100,8 @@ pub struct BarItemsStyle {
|
||||
section_gap: f32,
|
||||
/// Between the groups of a vertical strip, which draws no rule: an item gap and `space.gap.stack`.
|
||||
stack_gap: f32,
|
||||
/// The strip's glyph role, which its item faces show their icons in.
|
||||
glyphs: GlyphRole,
|
||||
}
|
||||
|
||||
/// An item whose command resolved this pass.
|
||||
@@ -167,14 +169,15 @@ fn display_of(present: &Present) -> ItemDisplay {
|
||||
if present.item.display != ItemDisplay::Text && icon_of(&present.resolved).is_none() { ItemDisplay::Text } else { present.item.display }
|
||||
}
|
||||
|
||||
/// The face of an item: an icon button, a toggle for a command with a checked state, or a text button.
|
||||
fn face_of(present: &Present) -> Face {
|
||||
/// The face of an item: an icon button, a toggle for a command with a checked state, or a text button. Icon-only faces
|
||||
/// take the strip's glyph role.
|
||||
fn face_of(present: &Present, glyphs: GlyphRole) -> Face {
|
||||
let (item, resolved) = (&present.item, &present.resolved);
|
||||
let icon = icon_of(resolved);
|
||||
let toggle = resolved.checked.is_some();
|
||||
match (display_of(present), icon) {
|
||||
(ItemDisplay::Icon, Some(icon)) if toggle => Face::Toggle(ToggleButton::command(item.command.clone()).icon(icon).icon_only()),
|
||||
(ItemDisplay::Icon, Some(icon)) => Face::Action(IconButton::command(icon, item.command.clone())),
|
||||
(ItemDisplay::Icon, Some(icon)) if toggle => Face::Toggle(ToggleButton::command(item.command.clone()).icon(icon).icon_only().glyphs(glyphs)),
|
||||
(ItemDisplay::Icon, Some(icon)) => Face::Action(IconButton::command(icon, item.command.clone()).glyphs(glyphs)),
|
||||
(ItemDisplay::IconText, Some(icon)) if toggle => Face::Toggle(ToggleButton::command(item.command.clone()).icon(icon)),
|
||||
(ItemDisplay::IconText, Some(icon)) => Face::Text(Button::command(item.command.clone()).variant(Variant::GHOST).icon(icon)),
|
||||
(_, _) if toggle => Face::Toggle(ToggleButton::command(item.command.clone())),
|
||||
@@ -241,9 +244,9 @@ impl BarItems {
|
||||
|
||||
fn sizes(&self, cx: &MeasureCx<'_, Self>, present: &[Present]) -> Sizes {
|
||||
let axis = self.axis;
|
||||
let items = present.iter().map(|present| face_of(present).size(cx)).collect();
|
||||
let items = present.iter().map(|present| face_of(present, cx.style.glyphs).size(cx)).collect();
|
||||
let rule = if axis == Axis::Y { cx.face(Divider::horizontal()).y } else { cx.face(Divider::vertical()).x };
|
||||
let more = cx.face(IconButton::new(IconId::new("more")).label(cx.env.words::<BarWords>().items_more.clone()));
|
||||
let more = cx.face(IconButton::new(IconId::new("more")).label(cx.env.words::<BarWords>().items_more.clone()).glyphs(cx.style.glyphs));
|
||||
Sizes { items, rule, more }
|
||||
}
|
||||
|
||||
@@ -295,7 +298,13 @@ impl Component for BarItems {
|
||||
|
||||
fn style(cx: &StyleCx<'_>, _: BarItemsStyleKey) -> BarItemsStyle {
|
||||
let gap = cx.tokens.space.gap.inline;
|
||||
BarItemsStyle { metrics: Metrics::new().gap(gap), joint: gap, section_gap: gap * 2.0, stack_gap: gap + cx.tokens.space.gap.stack }
|
||||
BarItemsStyle {
|
||||
metrics: Metrics::new().gap(gap),
|
||||
joint: gap,
|
||||
section_gap: gap * 2.0,
|
||||
stack_gap: gap + cx.tokens.space.gap.stack,
|
||||
glyphs: cx.glyph_role(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The whole strip, or the room along the strip when that is shorter. Asked for the narrowest it takes (a
|
||||
@@ -430,7 +439,7 @@ impl Component for BarItems {
|
||||
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
let Some(laid) = &self.laid else { return };
|
||||
for &(index, _) in &laid.shown {
|
||||
face_of(&laid.present[index]).paint(ui, ITEM.at(index as u64));
|
||||
face_of(&laid.present[index], cx.style.glyphs).paint(ui, ITEM.at(index as u64));
|
||||
}
|
||||
for (at, rule) in laid.rules.iter().enumerate() {
|
||||
if self.axis == Axis::Y {
|
||||
@@ -440,7 +449,7 @@ impl Component for BarItems {
|
||||
}
|
||||
}
|
||||
if laid.more.is_some() {
|
||||
ui.face(MORE, IconButton::new(IconId::new("more")).label(cx.words::<BarWords>().items_more.clone()));
|
||||
ui.face(MORE, IconButton::new(IconId::new("more")).label(cx.words::<BarWords>().items_more.clone()).glyphs(cx.style.glyphs));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use crate::contract::{Component, Cx, MeasureCx, PaintUi, Styled as _};
|
||||
use crate::primitives::{HAlign, IconSpec, TextRun};
|
||||
use crate::style::{FocusLook, IconLook, StyleColor, StyleCx, SurfaceKind, SurfaceLook, TextLook, TypeRole, UiTokens, VariantParts};
|
||||
use crate::style::{FocusLook, GlyphRole, IconLook, StyleColor, StyleCx, SurfaceKind, SurfaceLook, TextLook, TypeRole, UiTokens, VariantParts};
|
||||
use craft_behavior::{Flow, Insets, Metrics, Proposal};
|
||||
use craft_theme::{
|
||||
Stateful, States, Variant,
|
||||
@@ -109,18 +109,30 @@ pub(super) fn on_surface(cx: &StyleCx<'_>, off: &VariantParts, on: &VariantParts
|
||||
pub(super) struct IconFace {
|
||||
pub surface: SurfaceLook,
|
||||
pub metrics: Metrics,
|
||||
/// The glyph at the glyph side, in the on look's text colour while on.
|
||||
/// The glyph at the side of the scope's glyph role, in the on look's text colour while on.
|
||||
pub glyph: IconLook,
|
||||
}
|
||||
|
||||
/// The icon-only look of the instance's variant: a square of the control height with control corners, as a ghost
|
||||
/// button of the old look (a capsule would round the on plate), showing the on look while on.
|
||||
/// 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(super) fn icon_face(cx: &StyleCx<'_>) -> IconFace {
|
||||
let (off, on) = (cx.variant_look(), on_parts(cx));
|
||||
let (icon, text) = (&cx.tokens.size.icon, &cx.tokens.color.text);
|
||||
let (side, rest) = match cx.glyph_role() {
|
||||
GlyphRole::Tool => (icon.md, None),
|
||||
GlyphRole::ToolRail => (icon.lg, Some(text.muted)),
|
||||
GlyphRole::PanelRail => (cx.glyph(), Some(text.faint)),
|
||||
_ => (cx.glyph(), None),
|
||||
};
|
||||
let mut ink = off.text.clone();
|
||||
if let Some(rest) = rest {
|
||||
ink.off.rest = cx.color(rest);
|
||||
}
|
||||
IconFace {
|
||||
surface: on_surface(cx, &off, &on).radius(UiTokens::corner(cx.tokens.shape.radius.control)),
|
||||
metrics: Metrics::new().min_size(Vec2::splat(cx.control().height)),
|
||||
glyph: IconLook::new(cx.glyph(), off.text.clone().on(on.text.off)),
|
||||
glyph: IconLook::new(side, ink.on(on.text.off)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -973,8 +973,8 @@ A theme with its own shape replaces the radii or adds an offset to control, surf
|
||||
| Role | Components |
|
||||
| --- | --- |
|
||||
| `size.control.sm`, `size.control.md` | Controls, fields, buttons |
|
||||
| `size.icon.sm`, `size.icon.md`, `size.icon.lg` | Icons |
|
||||
| `size.icon.glyph_sm`, `size.icon.glyph_md` | The glyph in an icon-only button |
|
||||
| `size.icon.sm`, `size.icon.md`, `size.icon.lg` | Icons; `md` is the glyph of a tool strip (`GlyphRole::Tool`), `lg` of a tool rail (`GlyphRole::ToolRail`). A stroke icon below `md` draws `stroke.thin`, from `md` up `stroke.medium` |
|
||||
| `size.icon.glyph_sm`, `size.icon.glyph_md` | The glyph in an icon-only button (`GlyphRole::Control`, the default; a container sets another with `ContainerProps::child_glyphs`) |
|
||||
| `size.bar.title`, `size.bar.tab`, `size.bar.status`, `size.bar.options`, `size.bar.options_narrow` | Title bar, document tab bar, status bar, options bar |
|
||||
| `size.panel_header` | Panel headers |
|
||||
| `size.popup_min` | Least width of a popup surface (menus only; popup lists such as Select and ComboBox take their anchor's width) |
|
||||
|
||||
Reference in New Issue
Block a user