ui-panels: focused title row parts, dock chevrons, grips and dividers show the focus ring

The paint step draws the focus ring only for a style that has a focus
look, and no style in ui-panels had one. After Tab, these stops showed
no ring:

- a title row's disclosure or check box lead, commands and actions
- a group grip, and a docked group's drag band and panel menu button
- a dock column's chevron and its dividers
- a dock window's chevron
- a collapsed column's chevron, icon cells and edge divider
- a split area's handles and the dividers between stacked sections

Each of these styles now takes the theme's focus look, as Link and the
breadcrumb bar do, and the paint step rings the focused part's rect.
FloatingGroupStyle no longer derives Default, since the focus
look has no default.
This commit is contained in:
dotCooCoo committed 2026-11-25 02:22:58 -08:00
1 parent 9a2615d2d9
commit a2692197cb
9 files changed
+203 -16

No files matched your search

+5 -2
View File
@@ -15,7 +15,7 @@ use crate::contract::{
use crate::menu::GroupItem;
use crate::runtime::env::Label;
use crate::runtime::focus::KeyUse;
use crate::style::{ComponentStyle, Corners, StyleCx, SurfaceEdge, SurfaceKind, SurfaceStyle, UiTokens};
use crate::style::{ComponentStyle, Corners, FocusLook, StyleCx, SurfaceEdge, SurfaceKind, SurfaceStyle, UiTokens};
use crate::tabs::PanelTabLook;
use craft_behavior::divider::{self as push, Segment};
use craft_behavior::dock::{Column, DockEdge, Group};
@@ -160,6 +160,9 @@ impl<P> Outcome for DockColumnOutput<P> {
pub struct DockColumnStyle {
#[style(metrics)]
metrics: Metrics,
/// The ring around the chevron or the divider that has keyboard focus.
#[style(focus)]
focus: FocusLook,
sizes: DockSizes,
/// The card of a column shown as one ([`card`](DockColumn::card)).
card: SurfaceStyle,
@@ -469,7 +472,7 @@ impl<P: Value + Debug + Hash + 'static> Component for DockColumn<'_, P> {
}
fn style(cx: &StyleCx<'_>, _: DockColumnStyleKey<P>) -> DockColumnStyle {
DockColumnStyle { metrics: Metrics::new(), sizes: DockSizes::style(cx), card: card_style(cx) }
DockColumnStyle { metrics: Metrics::new(), focus: cx.focus_look(), sizes: DockSizes::style(cx), card: card_style(cx) }
}
fn sense(&self) -> Sense {
+8 -5
View File
@@ -25,7 +25,7 @@ use crate::runtime::env::{Env, Label};
use crate::runtime::overlay::CloseReason;
use crate::runtime::windows::{ResizeEdge, WindowSpec};
use crate::sections::{HeaderAction, HeaderStrength, MenuRows, TitleRow};
use crate::style::{ComponentStyle, StyleCx, SurfaceKind, UiTokens};
use crate::style::{ComponentStyle, FocusLook, StyleCx, SurfaceKind, UiTokens};
use craft_behavior::dock::DockEdge;
use craft_behavior::{GesturePhase, IconId, Metrics, Sense};
use craft_ui_widgets::popover::WholeWindow;
@@ -45,12 +45,15 @@ pub(crate) fn title_row(tokens: &UiTokens) -> f32 {
/// title bar has beside its double arrow; the menu opens from the band.
const ACTIONS: [HeaderAction; 1] = [HeaderAction::Close];
/// The style of a floating group: the surface and padding come from the container.
#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)]
/// The style of a floating group: the surface and padding come from the container, and the ring from the theme.
#[derive(Clone, Debug, PartialEq, ComponentStyle)]
#[non_exhaustive]
pub struct FloatingGroupStyle {
#[style(metrics)]
metrics: Metrics,
/// The ring around the chevron while it has keyboard focus.
#[style(focus)]
focus: FocusLook,
}
/// The column a dock's floating window holds. The window's title row is the column's bar: it shows the column's
@@ -511,8 +514,8 @@ impl Component for FloatingGroup<'_> {
type Style = FloatingGroupStyle;
type Output = FloatingGroupOutput;
fn style(_: &StyleCx<'_>, _: FloatingGroupStyleKey) -> FloatingGroupStyle {
FloatingGroupStyle::default()
fn style(cx: &StyleCx<'_>, _: FloatingGroupStyleKey) -> FloatingGroupStyle {
FloatingGroupStyle { metrics: Metrics::new(), focus: cx.focus_look() }
}
fn sense(&self) -> Sense {
+9 -3
View File
@@ -21,7 +21,7 @@ use crate::runtime::env::Label;
use crate::runtime::focus::{self, FocusRequest, FocusTarget};
use crate::runtime::memory::sub;
use crate::sections::FooterBar;
use crate::style::{ComponentStyle, Corners, RuleLook, RuleWidth, StyleColor, StyleCx, SurfaceKind, TypeRole};
use crate::style::{ComponentStyle, Corners, FocusLook, RuleLook, RuleWidth, StyleColor, StyleCx, SurfaceKind, TypeRole};
use crate::tabs::{PanelTabLook, Tab, TabKind, TabStrip, TornOff};
use craft_behavior::{CursorIcon, CursorPriority, DockSide, IconId, Metrics, PartKey, PressPhase, Sense, keyed};
use craft_theme::{ControlSize, GripMark, GripShape, Tokens};
@@ -37,6 +37,9 @@ use std::sync::Arc;
pub struct GroupGripStyle {
#[style(metrics)]
metrics: Metrics,
/// The ring the grip shows while it has keyboard focus.
#[style(focus)]
focus: FocusLook,
/// The marks a grip with [`ticks`](GroupGrip::ticks) shows.
marks: GripMarks,
}
@@ -166,7 +169,7 @@ impl<P: Clone + Send + Sync + 'static> Component for GroupGrip<P> {
type Output = GroupGripOutput;
fn style(cx: &StyleCx<'_>, _: GroupGripStyleKey<P>) -> GroupGripStyle {
GroupGripStyle { metrics: Metrics::new(), marks: GripMarks::style(cx) }
GroupGripStyle { metrics: Metrics::new(), focus: cx.focus_look(), marks: GripMarks::style(cx) }
}
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
@@ -320,6 +323,9 @@ impl Outcome for DockGroupOutput {
pub struct DockGroupStyle {
#[style(metrics)]
metrics: Metrics,
/// The ring around the drag band or the panel menu button while it has keyboard focus.
#[style(focus)]
focus: FocusLook,
header: f32,
sizes: DockSizes,
}
@@ -506,7 +512,7 @@ impl<P: Clone + PartialEq + Debug + Hash + Send + Sync + 'static> Component for
fn style(cx: &StyleCx<'_>, _: DockGroupStyleKey<P>) -> DockGroupStyle {
let sizes = DockSizes::style(cx);
DockGroupStyle { metrics: Metrics::new(), header: sizes.strip, sizes }
DockGroupStyle { metrics: Metrics::new(), focus: cx.focus_look(), header: sizes.strip, sizes }
}
fn sense(&self) -> Sense {
+5 -1
View File
@@ -18,7 +18,7 @@ use crate::menu::GroupItem;
use crate::primitives::{IconSpec, TextRun};
use crate::runtime::env::{Env, EnvValue, Label, with_env};
use crate::runtime::focus::KeyUse;
use crate::style::{ComponentStyle, Corners, GlyphRole, RuleKind, StyleColor, StyleCx, SurfaceKind, SurfaceStyle};
use crate::style::{ComponentStyle, Corners, FocusLook, GlyphRole, RuleKind, StyleColor, StyleCx, SurfaceKind, SurfaceStyle};
use crate::tabs::PanelTabLook;
use craft_behavior::dock::{Column, DockEdge, Group};
use craft_behavior::overlay::Side;
@@ -177,6 +177,9 @@ impl<P: Value + Hash + 'static> Outcome for IconicColumnOutput<P> {
pub struct IconicColumnStyle {
#[style(metrics)]
metrics: Metrics,
/// The ring around the chevron, the icon cell or the edge divider that has keyboard focus.
#[style(focus)]
focus: FocusLook,
sizes: IconicSizes,
/// The ink of a panel's name in a wide column.
name: StyleColor,
@@ -549,6 +552,7 @@ impl<P: Value + Hash + Debug + 'static> Component for IconicColumn<'_, P> {
let colors = &cx.tokens.color;
IconicColumnStyle {
metrics: Metrics::new(),
focus: cx.focus_look(),
sizes: IconicSizes::style(cx),
name: cx.color(colors.text.normal),
name_open: cx.color(colors.accent.text),
+5 -2
View File
@@ -75,7 +75,7 @@ use crate::runtime::commands::CommandRef;
use crate::runtime::env::Label;
use crate::runtime::focus::KeyUse;
use crate::runtime::memory::sub;
use crate::style::{ComponentStyle, StyleCx};
use crate::style::{ComponentStyle, FocusLook, StyleCx};
use craft_behavior::dock::{DockEdge, Layout, Node, SplitSize};
use craft_behavior::{Axis, EditEvents, Flow, Metrics, PartKey, Sense};
use divider::{Divider, Drag};
@@ -247,6 +247,9 @@ pub struct PanelDrag {
pub struct SplitAreaStyle {
#[style(metrics)]
metrics: Metrics,
/// The ring around the handle that has keyboard focus.
#[style(focus)]
focus: FocusLook,
/// The docking sizes: the dividers' gap, reach and key steps, and the groups' least extent and strip.
sizes: DockSizes,
}
@@ -416,7 +419,7 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Component for SplitAr
type Output = SplitAreaOutput<P>;
fn style(cx: &StyleCx<'_>, _: SplitAreaStyleKey<P>) -> SplitAreaStyle {
SplitAreaStyle { metrics: Metrics::new(), sizes: DockSizes::style(cx) }
SplitAreaStyle { metrics: Metrics::new(), focus: cx.focus_look(), sizes: DockSizes::style(cx) }
}
fn sense(&self) -> Sense {
+5 -2
View File
@@ -7,7 +7,7 @@ use crate::contract::{
Access, Common, Component, Container, ContainerProps, Cx, NoValue, Outcome, Pad, PaintUi, PartsCx, Role, Sizing, WordSetCx as _,
};
use crate::runtime::focus::KeyUse;
use crate::style::{ComponentStyle, StyleCx};
use crate::style::{ComponentStyle, FocusLook, StyleCx};
use craft_behavior::divider::{self as push, Segment};
use craft_behavior::{Axis, Metrics, PartKey, Sense};
use egui::{Rect, Response};
@@ -99,6 +99,9 @@ pub fn section_heights(sections: &[StackSection], total: f32, header: f32) -> Ve
pub struct StackSectionsStyle {
#[style(metrics)]
metrics: Metrics,
/// The ring around the divider that has keyboard focus.
#[style(focus)]
focus: FocusLook,
sizes: DockSizes,
}
@@ -189,7 +192,7 @@ impl Component for StackSections {
type Output = StackSectionsOutput;
fn style(cx: &StyleCx<'_>, _: StackSectionsStyleKey) -> StackSectionsStyle {
StackSectionsStyle { metrics: Metrics::new(), sizes: DockSizes::style(cx) }
StackSectionsStyle { metrics: Metrics::new(), focus: cx.focus_look(), sizes: DockSizes::style(cx) }
}
fn sense(&self) -> Sense {
+5 -1
View File
@@ -14,7 +14,7 @@ use crate::menu::Menu;
use crate::primitives::{IconSpec, Span, TextRun};
use crate::runtime::commands::CommandRef;
use crate::runtime::env::{EnvValue, Label};
use crate::style::{ComponentStyle, IconLook, Ink, StyleCx, TextLook, TypeRole};
use crate::style::{ComponentStyle, FocusLook, IconLook, Ink, StyleCx, TextLook, TypeRole};
use craft_behavior::{CursorIcon, Flow, IconId, Metrics, Mixed, NavShape, PartKey, Roving, Sense};
use craft_theme::variant::Tone;
use craft_theme::{ControlSize, Stateful, States};
@@ -186,6 +186,9 @@ pub struct TitleRowStyle {
icon: IconLook,
/// The kind at the band's end: caption text in the faint text colour.
subtitle: TextLook,
/// The ring around the lead, command or action part that has keyboard focus.
#[style(focus)]
focus: FocusLook,
/// The side of an action part: the control height, which is below a tall header's height.
action: f32,
/// Whether the row is a quiet title's text row (`QuietTitleRow::Text`), as tall as it must be to hold its title
@@ -397,6 +400,7 @@ impl Component for TitleRow<'_> {
let faint = cx.color(text.faint);
TextLook::new(TypeRole::Caption, Stateful::new(faint).off(States::new(faint, faint, faint, disabled)))
},
focus: cx.focus_look(),
action: cx.control().height,
text_row,
}
+1
View File
@@ -3,6 +3,7 @@
pub(crate) mod dialog_tab;
pub(crate) mod keys;
pub(crate) mod press;
pub(crate) mod rings;
pub(crate) mod roving;
pub(crate) mod scopes;
+160
View File
@@ -0,0 +1,160 @@
//! The focus ring of the panel family's focusable parts: Tab to each one and the paint step rings it, as it rings a
//! button.
use craft_behavior::dock::{Column, DockEdge, Group};
use craft_behavior::{Axis, PartKey};
use craft_ui::contract::{Bind, Props as _, Show as _, ShowContainer as _};
use craft_ui::docking::stack::{StackSection, StackSections};
use craft_ui::docking::{
DockColumn, DockGroup, DragUnit, FloatingGroup, GroupGrip, IconicColumn, PanelKey, PanelSpec, PanelTitle, SplitArea, Titles, WindowColumn,
};
use craft_ui::menu::PanelRow;
use craft_ui::sections::{HeaderAction, Panel, TitleRow};
use craft_ui::testing::memory::global;
use craft_ui::testing::{Fixture, trial};
use egui::{Key, Modifiers, Pos2, Rect, Shape, Vec2};
/// Presses Tab until a stop that `wanted` accepts holds the focus, and returns the rect of the focused part, or of
/// the focused component when the stop is a whole component. Panics when Tab never reaches one.
fn tab_to(fixture: &mut Fixture, wanted: impl Fn(Option<PartKey>) -> bool) -> Rect {
for _ in 0..16 {
fixture.key(Key::Tab, Modifiers::NONE).settle();
let Some((owner, part)) = fixture.focused_stop() else { continue };
if !wanted(part.map(|part| part.key)) {
continue;
}
let rect = match part {
Some(part) => fixture.part_rect(owner, part),
None => fixture.node_of(owner).map(|target| target.rect),
};
return rect.unwrap_or_else(|| panic!("the focused stop {owner:?} {part:?} has a rect"));
}
panic!("Tab never reached the wanted stop");
}
/// Tab to the part `key`.
fn tab_to_part(fixture: &mut Fixture, key: &'static str) -> Rect {
tab_to(fixture, |part| part == Some(PartKey::new(key)))
}
/// Whether the latest frame paints a focus ring (a rectangle stroke at least two points wide) around `target`.
fn ringed(fixture: &mut Fixture, target: Rect) -> bool {
fixture.frame_shapes().iter().any(|shape| match shape {
Shape::Rect(rect) if rect.stroke.width >= 2.0 => rect.rect.expand(1.0).contains_rect(target),
_ => false,
})
}
fn spec(panel: &u8) -> PanelSpec {
PanelSpec::new(["Brushes", "Swatches", "History"].get(usize::from(*panel)).copied().unwrap_or("Panel"))
}
/// A title row's disclosure lead and its action buttons are rung when Tab reaches them.
#[trial]
fn a_title_rows_focused_lead_and_action_show_the_focus_ring() {
let mut fixture = Fixture::new(|ui| {
let mut open = true;
TitleRow::new("Layers").disclosure(Bind::bound(&mut open)).show(ui);
});
fixture.settle();
let lead = tab_to_part(&mut fixture, "lead");
assert!(ringed(&mut fixture, lead), "the focused disclosure lead {lead:?} is ringed");
let mut fixture = Fixture::new(|ui| {
TitleRow::new("Layers").actions([HeaderAction::Close]).show(ui);
});
fixture.settle();
let action = tab_to_part(&mut fixture, "action");
assert!(ringed(&mut fixture, action), "the focused action {action:?} is ringed");
}
/// A group grip and a docked group's drag band and panel menu button are rung when Tab reaches them.
#[trial]
fn a_focused_group_grip_drag_band_and_panel_menu_button_show_the_focus_ring() {
let mut fixture = Fixture::new(|ui| {
let strip = Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(60.0, 16.0));
GroupGrip::new(DragUnit::Group(1usize), PanelKey::new(1)).label("Move tab group").show_at(ui, strip);
});
fixture.settle();
let grip = tab_to(&mut fixture, |part| part.is_none());
assert!(ringed(&mut fixture, grip), "the focused grip {grip:?} is ringed");
let group = || {
let panels = vec![PanelTitle::new(PanelKey::new(1), "Layers")];
Fixture::new(move |ui| {
let group = DockGroup::new(1usize, Titles::from_content(panels.clone()), panels[0].key).menu(Vec::<PanelRow>::new);
let _ = group.show_at(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(300.0, 240.0)), |_, _| ());
})
};
for part in ["grip", "panel_menu"] {
let mut fixture = group();
fixture.settle();
let rect = tab_to_part(&mut fixture, part);
assert!(ringed(&mut fixture, rect), "the group's focused {part} part {rect:?} is ringed");
}
}
/// A docked column's chevron and the divider between its groups are rung when Tab reaches them.
#[trial]
fn a_dock_columns_focused_chevron_and_divider_show_the_focus_ring() {
for part in ["chevron", "divider"] {
let mut fixture = Fixture::new(|ui| {
let column = Column::new(vec![Group::new(vec![0, 1], 0), Group::new(vec![2], 0)]);
DockColumn::new("Panels", global("dock column", "focus ring trial"), &column, &spec).show_groups(ui, |_, rect, ui, _| {
Panel::new("Panel").show_at(ui, rect, |_, _| ());
});
});
fixture.room(Vec2::new(240.0, 400.0)).settle();
let rect = tab_to_part(&mut fixture, part);
assert!(ringed(&mut fixture, rect), "the column's focused {part} part {rect:?} is ringed");
}
}
/// A dock window's chevron is rung when Tab reaches it.
#[trial]
fn a_dock_windows_focused_chevron_shows_the_focus_ring() {
let mut fixture = Fixture::new(|ui| {
let rect = Rect::from_min_size(Pos2::new(40.0, 40.0), Vec2::new(240.0, 180.0));
FloatingGroup::new("Layers", rect).column(WindowColumn::expanded(DockEdge::Start)).show_group(ui, |_, _| ());
});
fixture.settle();
let chevron = tab_to_part(&mut fixture, "chevron");
assert!(ringed(&mut fixture, chevron), "the window's focused chevron {chevron:?} is ringed");
}
/// A collapsed column's chevron and icon cells are rung when Tab reaches them.
#[trial]
fn an_iconic_columns_focused_chevron_and_cell_show_the_focus_ring() {
for part in ["chevron", "cell"] {
let mut fixture = Fixture::new(|ui| {
let column = Column::new(vec![Group::new(vec![0, 1], 0)]);
let mut open = None;
IconicColumn::new("Panels", global("iconic column", "focus ring trial"), &column, Bind::bound(&mut open), &spec)
.show_flyouts(ui, |_, _, _, _| None);
});
fixture.room(Vec2::new(48.0, 300.0)).settle();
let rect = tab_to_part(&mut fixture, part);
assert!(ringed(&mut fixture, rect), "the column's focused {part} part {rect:?} is ringed");
}
}
/// The handle between two docked areas and the divider between two stacked sections are rung when Tab reaches them.
#[trial]
fn a_focused_split_handle_and_stack_divider_show_the_focus_ring() {
use craft_behavior::dock::{Layout, Node, SplitSize};
use craft_ui::contract::SizeLimits;
use craft_ui::docking::tree::FrameRules;
let mut fixture = Fixture::new(|ui| {
let root = Node::split(Axis::X, SplitSize::Ratio(0.5), Node::tabs(vec![0usize], 0), Node::tabs(vec![1usize], 0));
let mut layout = Layout::new(Some(root), Vec::new());
let limits = |_: &usize| SizeLimits::default();
SplitArea::new("Panels", Bind::bound(&mut layout), FrameRules::new(&limits)).show(ui, |_, _| ());
});
fixture.room(Vec2::new(400.0, 300.0)).settle();
let handle = tab_to_part(&mut fixture, "handle");
assert!(ringed(&mut fixture, handle), "the focused split handle {handle:?} is ringed");
let mut fixture = Fixture::new(|ui| {
StackSections::new(vec![StackSection::new(true), StackSection::new(true)]).label("Sections").show(ui, |_, _| ());
});
fixture.room(Vec2::new(240.0, 300.0)).settle();
let divider = tab_to_part(&mut fixture, "divider");
assert!(ringed(&mut fixture, divider), "the focused stack divider {divider:?} is ringed");
}