From c0461c346830024aa9f297141c308efb29b40a51 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 11:13:44 -0800 Subject: [PATCH 1/3] ui-widgets: popovers pad as panels, menu samples and grid headers clear their neighbors Popover and CalendarPopover pad their content by the new POPOVER_PAD, space.pad.regular, instead of space.pad.control, so controls no longer sit against the popover's edge. Menus, popup lists and OverlayUi::show keep POPUP_PAD, since their rows carry their own inset. The color HUD places its start point through POPOVER_PAD, as it shows in a Popover. A menu row's sample column starts space.gap.section after the label, the gap the shortcut column already gets, so a font name no longer runs into its sample. A tile grid's group headers and tail rows end at the scroll bar while it shows, so the count at a header's end is not painted under the bar. --- crates/color-ui/src/ui/hud.rs | 4 +-- crates/ui-contract/src/contract/container.rs | 6 +++- crates/ui-contract/src/contract/mod.rs | 4 +-- crates/ui-widgets/src/menu/item.rs | 14 ++++++---- crates/ui-widgets/src/pickers/date/popover.rs | 4 +-- crates/ui-widgets/src/popover/anchored.rs | 4 +-- crates/ui-widgets/src/tile_grid/grid.rs | 7 +++-- crates/ui-widgets/tests/it/menu/rows.rs | 27 ++++++++++++++++++ crates/ui-widgets/tests/it/popover/popup.rs | 28 +++++++++++++++++++ crates/ui-widgets/tests/it/tile_grid/grid.rs | 27 ++++++++++++++++++ 10 files changed, 109 insertions(+), 16 deletions(-) diff --git a/crates/color-ui/src/ui/hud.rs b/crates/color-ui/src/ui/hud.rs index f8a15f453a..0d6b4e3660 100644 --- a/crates/color-ui/src/ui/hud.rs +++ b/crates/color-ui/src/ui/hud.rs @@ -6,7 +6,7 @@ use crate::AreaMode; use craft_behavior::{EditEvent, EditEvents, Metrics, PartKey, Sense}; use craft_theme::Srgba; use craft_ui::contract::{ - Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, EscapeEdit, MeasureCx, Outcome, POPUP_PAD, PaintUi, PartsCx, + Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, EscapeEdit, MeasureCx, Outcome, POPOVER_PAD, PaintUi, PartsCx, Pattern, Props as _, Role, Show as _, ShowContainer as _, pad_of, }; use craft_ui::popover::Popover; @@ -77,7 +77,7 @@ fn start_point(geometry: Geometry, start: Option) -> Pos2 { /// The popover's top left, so that the start colour's point in the area sits at `at`. fn origin(tokens: &UiTokens, at: Pos2, start: Option) -> Pos2 { let point = start_point(Geometry::of(tokens), start); - let pad = pad_of(tokens, POPUP_PAD); + let pad = pad_of(tokens, POPOVER_PAD); pos2(at.x - pad - point.x, at.y - pad - point.y) } diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index f31f68adcd..2cebed8f01 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -162,9 +162,13 @@ pub enum PadEdges { Inline, } -/// The padding of every popup surface around its content. +/// The padding of a menu's or a list's popup surface around its rows, which carry their own inset. pub const POPUP_PAD: Pad = Pad::Control; +/// The padding of a popover's surface around its content: `space.pad.regular`, as a panel's, so controls stand clear of +/// its edge. +pub const POPOVER_PAD: Pad = Pad::Regular; + /// How a container's size follows its content. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index 73411ddff7..72b593678d 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -70,8 +70,8 @@ pub use container::InBar; pub use container::InMenu; pub use container::{ BandFill, Bracket, Collapse, ContainerProps, DragBand, EndRegion, FooterPlace, FooterRegion, Gap, HeaderEdge, HeaderParts, HeaderRegion, - LeastWidth, Mount, MoveBandCursor, Notch, POPUP_PAD, Pad, PadEdges, PaneEdge, QuietHeader, Scroll, ScrollAnchor, ScrollAxes, ScrollIndicator, - SectionRhythm, ShellPane, Sizing, ThemeScope, WrapWidth, + LeastWidth, Mount, MoveBandCursor, Notch, POPOVER_PAD, POPUP_PAD, Pad, PadEdges, PaneEdge, QuietHeader, Scroll, ScrollAnchor, ScrollAxes, + ScrollIndicator, SectionRhythm, ShellPane, Sizing, ThemeScope, WrapWidth, }; pub use craft_tracked::{PlainData, Revision, Tracked}; pub use craft_ui_macros::{CommandSet, Component, Pattern, PlainData, Props, register_contract}; diff --git a/crates/ui-widgets/src/menu/item.rs b/crates/ui-widgets/src/menu/item.rs index c0d50da2ec..aa2d26c9dd 100644 --- a/crates/ui-widgets/src/menu/item.rs +++ b/crates/ui-widgets/src/menu/item.rs @@ -142,7 +142,7 @@ pub struct MenuItemStyle { /// The detail line under the label, in `text.muted`. #[style(text)] detail: TextLook, - /// The least space between the label and the shortcut: `space.gap.section`. + /// The least space between the label and the shortcut, and between the label and a sample: `space.gap.section`. shortcut_gap: f32, /// The gap between a submenu and its parent menu: `space.gap.tight`. submenu_gap: f32, @@ -478,7 +478,7 @@ impl<'a> MenuItem<'a> { let side = cx.icon(); let command = cx.command(); let (mark, icon) = self.lead_columns(cx.ui.ctx(), side, cx.gap(), command, level); - let sample = self.sample_column(cx.ui.ctx(), line, cx.gap()); + let sample = self.sample_column(cx.ui.ctx(), line, cx.style.shortcut_gap.max(cx.gap())); let trail = if self.submenu { side } else { self.keys(command).map_or(0.0, |keys| cx.face(keys).x) }; Columns { mark, icon, sample, trail } } @@ -705,7 +705,8 @@ impl Component for MenuItem<'_> { let detail_height = detail_run.as_ref().map_or(0.0, |run| draw.layout(run, f32::INFINITY).size().y); let trail = if self.submenu { side } else { cx.part_if_declared(SHORTCUT).map_or(0.0, |part| part.rect.width()) }; let line = label_line(cx.content_rect, detail_height); - let sample_column = self.sample_column(&cx.core.ctx, line.height(), gap); + let sample_gap = cx.style.shortcut_gap.max(gap); + let sample_column = self.sample_column(&cx.core.ctx, line.height(), sample_gap); let columns = Columns { mark: mark_column, icon: icon_column, sample: sample_column, trail }; let placed = self.place(&columns, line, rtl, cx.style.shortcut_gap.max(gap)); let ink = cx.resolve(&cx.style.icon.color); @@ -747,8 +748,11 @@ impl Component for MenuItem<'_> { // Samples start at one edge of the shared column, after its gap, so a level's samples line up; a sample-only // row's sample takes the label's room and the column. if let Some((aspect, face)) = &self.sample { - let rect = - if self.sample_only { placed.label.union(placed.sample) } else { Flow::new(placed.sample, rtl).span(gap, aspect.of(line.height())) }; + let rect = if self.sample_only { + placed.label.union(placed.sample) + } else { + Flow::new(placed.sample, rtl).span(sample_gap, aspect.of(line.height())) + }; face.paint(&ui.content_painter(cx), rect); } if self.submenu { diff --git a/crates/ui-widgets/src/pickers/date/popover.rs b/crates/ui-widgets/src/pickers/date/popover.rs index 1d5097cecb..98863e40b7 100644 --- a/crates/ui-widgets/src/pickers/date/popover.rs +++ b/crates/ui-widgets/src/pickers/date/popover.rs @@ -5,7 +5,7 @@ use super::{Calendar, CalendarView, DatePrecision, PickedDate, offered}; use crate::buttons::Link; use crate::choice::Segmented; use crate::contract::{ - Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, Entry, HeaderRegion, Mount, Overlay, POPUP_PAD, Props as _, + Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, Entry, HeaderRegion, Mount, Overlay, POPOVER_PAD, Props as _, Remember as _, Role, Show as _, ShowContainer as _, Trigger, WordSetCx as _, clicked, }; use crate::layout::RowAlign; @@ -170,7 +170,7 @@ impl<'a> CalendarPopover<'a> { /// `value` is a bound or kept binding: a given binding is never written, and the output carries no edit to report. pub fn new(label: impl Into