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-canvas/src/canvas/pasteboard/mod.rs b/crates/ui-canvas/src/canvas/pasteboard/mod.rs index c09a2b0fe5..07ca5269c5 100644 --- a/crates/ui-canvas/src/canvas/pasteboard/mod.rs +++ b/crates/ui-canvas/src/canvas/pasteboard/mod.rs @@ -9,8 +9,8 @@ pub(crate) mod stories; use super::space::canvas_space; use crate::contract::overlay::{Dismiss, LayerRole, Outside}; use crate::contract::{ - Access, Bind, Common, Component, Cx, MeasureCx, Name, NoValue, Outcome, Overlay, OverlayUi, Overlays as _, PaintUi, PartsCx, Pointer as _, - Props as _, Rename, Role, Show as _, + Access, Bind, Common, Component, Cx, MeasureCx, Name, NoValue, Outcome, Overlay, OverlayUi, Overlays as _, POPUP_PAD, PaintUi, PartsCx, + Pointer as _, Props as _, Rename, Role, Show as _, }; use crate::primitives::{Checker, CheckerArea, PaintShape, PaintSlot, Rule, StrokeColor, StrokeWidth, TextRun, paint_surround}; use crate::runtime::env::Label; @@ -590,7 +590,8 @@ impl Component for Pasteboard<'_> { let layer = Overlay::popover() .dismiss(Dismiss::new().outside(Outside::Keep)) .focus(FocusPolicy::POPUP.initial(Initial::First)) - .role(LayerRole::InPlaceEditor); + .role(LayerRole::InPlaceEditor) + .pad(POPUP_PAD); let layer = match field.or(state.shown) { Some(rect) => layer.placed(rect), None => layer, 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-contract/src/contract/overlay/props.rs b/crates/ui-contract/src/contract/overlay/props.rs index 829e4e6974..8c36ed2c0a 100644 --- a/crates/ui-contract/src/contract/overlay/props.rs +++ b/crates/ui-contract/src/contract/overlay/props.rs @@ -2,6 +2,7 @@ use super::opener::{Opener, Trigger}; use super::place::{Anchor, DragBounds, FloatPlace, OverlayFit, Place, Resize, ResizeEdges, SizeLimits, ViewportShare}; +use crate::contract::{POPOVER_PAD, POPUP_PAD, Pad}; use crate::runtime::access::PopupKind; use crate::runtime::focus::{FocusPolicy, Initial}; use crate::runtime::motion::{MotionSpec, spec}; @@ -146,6 +147,10 @@ pub struct Overlay { /// Whether a container mounted as this layer scrolls its body vertically. Off for a layer whose body fills it and /// manages its own scrolling (a dock tree); a body that is one collection uses `collection_body` instead. pub body_scroll: bool, + /// The padding [`OverlayUi::show`](super::OverlayUi::show) puts around a popup's body closure: `POPUP_PAD` for the + /// rows of a menu or a list, which carry their own inset, and `POPOVER_PAD` for a popover's content. A container + /// mounted as the layer takes its own padding from its props. + pub pad: Pad, /// Whether the layer's move band moves the OS window the layer is shown in, in place of the layer: the chrome a /// modal puts over the part of a title bar it covers. The layer stays where it is placed. pub moves_window: bool, @@ -203,6 +208,7 @@ impl Overlay { bounds: None, opacity: 1.0, body_scroll: true, + pad: POPUP_PAD, moves_window: false, moved_by_app: false, continue_move: None, @@ -240,11 +246,12 @@ impl Overlay { } /// A popover: a popup anchored below, from its content, at least as wide as its anchor and capped by the window, - /// taking focus in. It closes when the focus moves out of it. + /// taking focus in. It closes when the focus moves out of it. Its content stands `POPOVER_PAD` in from the edges. pub fn popover() -> Overlay { let mut overlay = Overlay::base(Rank::Popup, Overlay::below(), OverlayFit::Content, OwnerClass::Popup, FocusPolicy::POPUP); overlay.dismiss = Dismiss::new().focus_left(true); overlay.min_width = MinWidth::Anchor; + overlay.pad = POPOVER_PAD; overlay } @@ -442,6 +449,12 @@ impl Overlay { self } + /// Sets the padding [`OverlayUi::show`](super::OverlayUi::show) puts around a popup's body closure. + pub fn pad(mut self, pad: Pad) -> Overlay { + self.pad = pad; + self + } + /// Sets the layer's opacity, from 0 (invisible) to 1. pub fn opacity(mut self, opacity: f32) -> Overlay { self.opacity = opacity; diff --git a/crates/ui-contract/src/contract/overlay/ui.rs b/crates/ui-contract/src/contract/overlay/ui.rs index 178b1d75db..60836efd4f 100644 --- a/crates/ui-contract/src/contract/overlay/ui.rs +++ b/crates/ui-contract/src/contract/overlay/ui.rs @@ -6,8 +6,7 @@ use super::placement::PopupRegion; use super::popups::{PopupHandle, PopupLayer, with_popups}; use super::props::Overlay; use crate::contract::{ - BodyCx, Common, Component, Container, ContainerProps, Cx, Inner, Internal, Mount, NoValue, Outcome, POPUP_PAD, Props as _, Resolved, Role, - ShowContainer, + BodyCx, Common, Component, Container, ContainerProps, Cx, Inner, Internal, Mount, NoValue, Outcome, Props as _, Resolved, Role, ShowContainer, }; use crate::runtime::access::PopupShown; use crate::runtime::egui::areas::{self}; @@ -89,8 +88,8 @@ impl<'a> OverlayUi<'a> { }); } - /// Shows the popup while its handle is open, on a popup surface, inside `POPUP_PAD`; the content is a body closure. - /// `None` while closed. + /// Shows the popup while its handle is open, on a popup surface, inside the overlay's `pad` (`POPUP_PAD` for a menu + /// or a list, `POPOVER_PAD` for a popover); the content is a body closure. `None` while closed. /// /// The popup is a layer container sized from its content: its body is measured in this pass before the layer is /// placed, so a popup whose content changes is placed by its new size in the pass that shows it. A child that fills @@ -122,7 +121,7 @@ impl<'a> OverlayUi<'a> { } .body_scroll(false); let label = self.resolved.label_value.clone(); - let props = ContainerProps::new().surface(SurfaceKind::Popup).pad(POPUP_PAD).mount(Mount::Layer(overlay)); + let props = ContainerProps::new().surface(SurfaceKind::Popup).pad(overlay.pad).mount(Mount::Layer(overlay)); let container = PopupBody { common: Common::new(), props: ContainerProps { owner: Some(owner), ..props } }.label(label); self.show_container_with(popup, container, body).and_then(|shown| shown.inner) } @@ -227,7 +226,7 @@ impl Outcome for PopupBodyOutput { } /// The layer container [`OverlayUi::show`] shows a popup's body closure in: content-sized, on a popup surface inside -/// `POPUP_PAD`, its memory owned by the component that shows the popup. It adds no node of its own: the layer's node +/// the overlay's `pad`, its memory owned by the component that shows the popup. It adds no node of its own: the layer's node /// is the popup's. #[derive(crate::contract::Component)] #[component(container, unregistered)] 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