From 48162956312f0927ec6341e2fbd6d0fa34b8f1f1 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 15:55:32 +0000 Subject: [PATCH] Shell edge panes paint chrome and the rule toward the body; the window paints the background Every shell slot but the title is a chrome pane: its surface covers the whole pane, so a rail shorter than the window leaves no band of the clear colour, and a divider runs along its edge toward the body (rails, options bar, status bar, the canvas panel rail). The edge rule is drawn by the pane itself; PanelRail's own rule and the env's enclosing pane edge go. The window root paints the background surface and the document tabs pane sits on it. --- .../ui-contract/src/contract/body/inherit.rs | 7 +--- .../ui-contract/src/contract/body/regions.rs | 17 +++------- crates/ui-contract/src/contract/container.rs | 6 ++-- crates/ui-contract/src/primitives/rule.rs | 13 ++++++++ crates/ui-contract/src/runtime/env.rs | 4 --- crates/ui-contract/src/testing/stage.rs | 17 ++++++---- crates/ui-panels/src/rails/panel_rail.rs | 7 ++-- crates/ui-shell/src/shell/app_shell.rs | 32 ++++++++++++------- crates/ui-shell/src/shell/canvas_shell.rs | 6 ++-- crates/ui-shell/src/shell/regions.rs | 3 +- 10 files changed, 62 insertions(+), 50 deletions(-) diff --git a/crates/ui-contract/src/contract/body/inherit.rs b/crates/ui-contract/src/contract/body/inherit.rs index 046a57e76..d668877f0 100644 --- a/crates/ui-contract/src/contract/body/inherit.rs +++ b/crates/ui-contract/src/contract/body/inherit.rs @@ -2,7 +2,7 @@ use super::BodyHooks; use super::reorder::REORDER_SCOPE; -use crate::contract::{Container, ContainerProps, Cx, DragBand, Mount, PaneEdge, Scroll, Sizing}; +use crate::contract::{Container, ContainerProps, Cx, DragBand, Mount, Scroll, Sizing}; use crate::runtime::commands::{self, CommandSet as _, WindowCommand}; use crate::runtime::env::{AppValues, ArenaId, Scoped, ScrollOwner}; use crate::style::{ComponentStyle as _, SurfaceKind}; @@ -104,11 +104,6 @@ impl BodyHooks<'_> { scoped.arena = Some(ArenaId::new(id)); } scoped.transform = props.transform; - match &props.mount { - Mount::Pane(pane) if pane.edge != PaneEdge::Center => scoped.pane_edge = Some(pane.edge), - Mount::Inline => {} - _ => scoped.pane_edge = None, - } scoped.content_column = content_column; scoped.given_column = !content_column && matches!(props.layout, crate::layout::BodyLayout::Stack); scoped.row_room = None; diff --git a/crates/ui-contract/src/contract/body/regions.rs b/crates/ui-contract/src/contract/body/regions.rs index ede284284..12f2e8158 100644 --- a/crates/ui-contract/src/contract/body/regions.rs +++ b/crates/ui-contract/src/contract/body/regions.rs @@ -2,7 +2,7 @@ use super::BodyHooks; use crate::contract::cx::BodyCx; -use crate::contract::{Container, ContainerProps, FooterPlace, Gap, HeaderParts, LeastWidth, Mount, Pad, PaneEdge, Sizing}; +use crate::contract::{Container, ContainerProps, FooterPlace, Gap, HeaderParts, LeastWidth, Mount, Pad, Sizing}; use crate::layout::{ColumnGroup, Columns, Reached}; use crate::primitives::{RectSide, Rule}; use crate::runtime::access::{self}; @@ -172,18 +172,11 @@ impl RegionFrame<'_> { } } -/// The divider along the inner edge of the edge pane that encloses a container with `edge_rule`, inside `rect`: the -/// edge toward the window's centre, mirrored for a start or end pane under right-to-left. +/// The divider along the inner edge of an edge pane with `edge_rule`, inside `rect`: the edge toward the window's +/// centre (`RectSide::toward_centre`). pub(super) fn paint_edge_rule(ui: &mut Ui, props: &ContainerProps, env: &Env, rect: Rect) { - let Some(edge) = env.pane_edge.filter(|_| props.edge_rule) else { return }; - let rtl = env.direction.is_rtl(); - let side = match edge { - PaneEdge::Start => RectSide::end(rtl), - PaneEdge::End => RectSide::start(rtl), - PaneEdge::Top => RectSide::Bottom, - PaneEdge::Bottom => RectSide::Top, - PaneEdge::Center => return, - }; + let Mount::Pane(pane) = &props.mount else { return }; + let Some(side) = RectSide::toward_centre(pane.edge, env.direction.is_rtl()).filter(|_| props.edge_rule) else { return }; let rule = rule_look(&env.tokens, RuleKind::Divider); ui.painter().extend(Rule::edge(&rule, rect, side, ui.ctx().pixels_per_point())); } diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 7209982a9..72e657cef 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -704,8 +704,8 @@ pub struct ContainerProps { pub least_width: Option, /// The line length of the body's paragraphs while the container takes its width from its content, from a size role. pub wrap_width: Option, - /// A divider along the inner edge of the edge pane the container sits in: the edge that faces the window's centre. - /// Outside an edge pane it draws nothing. + /// A divider along the inner edge of a container mounted as an edge pane (`Mount::Pane` at an edge): the edge that + /// faces the window's centre. Any other container draws nothing. pub edge_rule: bool, /// A scope size for the body. pub child_size: Option, @@ -931,7 +931,7 @@ impl ContainerProps { self } - /// Draws a divider along the inner edge of the edge pane the container sits in. + /// Draws a divider along the inner edge of a container mounted as an edge pane. pub const fn edge_rule(mut self, on: bool) -> Self { self.edge_rule = on; self diff --git a/crates/ui-contract/src/primitives/rule.rs b/crates/ui-contract/src/primitives/rule.rs index c91ed542c..522edbb92 100644 --- a/crates/ui-contract/src/primitives/rule.rs +++ b/crates/ui-contract/src/primitives/rule.rs @@ -32,6 +32,19 @@ impl RectSide { pub const fn end(rtl: bool) -> RectSide { if rtl { RectSide::Left } else { RectSide::Right } } + + /// The side of a pane at `edge` that faces the window's centre, mirrored for a start or end pane under + /// right-to-left; none for the centre. + pub const fn toward_centre(edge: crate::contract::PaneEdge, rtl: bool) -> Option { + use crate::contract::PaneEdge; + match edge { + PaneEdge::Start => Some(RectSide::end(rtl)), + PaneEdge::End => Some(RectSide::start(rtl)), + PaneEdge::Top => Some(RectSide::Bottom), + PaneEdge::Bottom => Some(RectSide::Top), + PaneEdge::Center => None, + } + } } impl Rule { diff --git a/crates/ui-contract/src/runtime/env.rs b/crates/ui-contract/src/runtime/env.rs index b4d8da9da..2809caf04 100644 --- a/crates/ui-contract/src/runtime/env.rs +++ b/crates/ui-contract/src/runtime/env.rs @@ -160,8 +160,6 @@ pub struct Scoped { pub(crate) unbounded: (bool, bool), /// The view of the innermost scroll area, for the children that run only in view (`contract::Lazy`). pub(crate) lazy: Option, - /// The window edge of the innermost edge pane that encloses the scope (`Mount::Pane`). - pub(crate) pane_edge: Option, /// The id of the collection item the scope shows: its root is not a Tab stop (17.3). pub(crate) item: Option, /// The roving group of the collection row the scope shows: the stops of its components and parts join it, so @@ -349,7 +347,6 @@ impl Scoped { self.wheel = WheelScope::Plain; self.unbounded = (false, false); self.lazy = None; - self.pane_edge = None; self.glyphs = GlyphRole::Control; self.item = None; self.row = None; @@ -501,7 +498,6 @@ impl Env { scroll_owner: None, unbounded: (false, false), lazy: None, - pane_edge: None, item: None, row: None, item_facts: None, diff --git a/crates/ui-contract/src/testing/stage.rs b/crates/ui-contract/src/testing/stage.rs index 13fdddf5d..3366309db 100644 --- a/crates/ui-contract/src/testing/stage.rs +++ b/crates/ui-contract/src/testing/stage.rs @@ -2,7 +2,9 @@ use crate::contract::PaneEdge; use crate::layout::flow_room; +use crate::primitives::{RectSide, Rule}; use crate::runtime::env::Env; +use crate::style::{RuleKind, rule_look}; use egui::{Rect, Ui}; /// Allocates the stage of a story of a canvas control or a root that fills both axes, and returns its rect: the width @@ -37,11 +39,14 @@ pub fn stage_width(ui: &Ui) -> f32 { } /// Runs `story` as the content of an edge pane at `edge`, as a rail or panel docked at that edge of an app window -/// shows: a container that draws a divider along its pane's inner edge (`ContainerProps::edge_rule`) draws it. +/// shows: with the divider the pane draws along its inner edge (`ContainerProps::edge_rule`), here along the edge of +/// what the story drew. pub fn in_edge_pane(ui: &mut Ui, edge: PaneEdge, story: impl FnOnce(&mut Ui) -> R) -> R { - let ctx = ui.ctx().clone(); - let installed = Env::install_for(ui, Env::of(ui).derive_local(|scoped| scoped.pane_edge = Some(edge))); - let out = story(ui); - Env::restore(&ctx, installed); - out + let shown = ui.scope(story); + let env = Env::of(ui); + if let Some(side) = RectSide::toward_centre(edge, env.direction.is_rtl()) { + let rule = rule_look(&env.tokens, RuleKind::Divider); + ui.painter().extend(Rule::edge(&rule, shown.response.rect, side, ui.ctx().pixels_per_point())); + } + shown.inner } diff --git a/crates/ui-panels/src/rails/panel_rail.rs b/crates/ui-panels/src/rails/panel_rail.rs index 1715bb808..389be9714 100644 --- a/crates/ui-panels/src/rails/panel_rail.rs +++ b/crates/ui-panels/src/rails/panel_rail.rs @@ -61,8 +61,8 @@ impl Outcome for PanelRailOutput

{ type FooterFn<'a> = Box; -/// The rail of icons that open panels, as a side panel at one edge of the window, with a rule along the edge that faces -/// the canvas (the inner edge of its pane). A panel is a toggle command: its +/// The rail of icons that open panels, as a side panel at one edge of the window; the pane it sits in draws the rule +/// along the edge that faces the canvas. A panel is a toggle command: its /// label, icon, chord and enabled state come from the command, the icon shows the on look while the command is /// checked (the panel is open), and the command's `marked` state and `hint` mark a closed panel that has content /// to show. A click runs the command and reports the request that matches the panel's state. The icons are one @@ -92,8 +92,7 @@ impl<'a, P: Value + 'static> PanelRail<'a, P> { .child_glyphs(GlyphRole::PanelRail) .roving(Roving::new(NavShape::Flat)) .scroll(Scroll::vertical()) - .footer(FooterRegion::new()) - .edge_rule(true); + .footer(FooterRegion::new()); PanelRail { common: Common::new(), props, panels, footer: None }.label(label) } diff --git a/crates/ui-shell/src/shell/app_shell.rs b/crates/ui-shell/src/shell/app_shell.rs index 46cb00933..94a0a20fc 100644 --- a/crates/ui-shell/src/shell/app_shell.rs +++ b/crates/ui-shell/src/shell/app_shell.rs @@ -98,11 +98,12 @@ pub struct ShellRegion { } impl ShellRegion { - /// The whole content of the window: its edges resize the window where the app draws the frame. It paints no - /// surface of its own: the parts the shell places paint theirs, and a gap between them (a dock's gutter) shows the - /// window's clear colour. + /// The whole content of the window: its edges resize the window where the app draws the frame. It paints the + /// background surface under everything the shell places, so a gap between parts (a dock's gutter, the room beside + /// the document tabs) shows the background, never the platform's clear colour. pub fn window() -> Self { - let props = ContainerProps::new().mount(Mount::window(Resize::GRIPS)).command_scope(ScreenModeCommands::SCOPE); + let props = + ContainerProps::new().mount(Mount::window(Resize::GRIPS)).surface(SurfaceKind::Background).command_scope(ScreenModeCommands::SCOPE); ShellRegion { common: Common::new(), props, shell: None, senses_surface: false } } @@ -125,6 +126,15 @@ impl ShellRegion { let props = ContainerProps::new().mount(Mount::Pane(pane)).focus(FocusPolicy::PANE); ShellRegion { common: Common::new(), props, shell: None, senses_surface: false } } + + /// A bar or rail pane at an edge of the window: it paints the chrome surface over the whole pane and a divider + /// along its inner edge. A bar or rail inside that is smaller than the pane leaves no band of the backdrop, and the + /// pane meets the body at the rule. + pub fn chrome(pane: ShellPane) -> Self { + let mut region = Self::pane(pane); + region.props = region.props.surface(SurfaceKind::Chrome).edge_rule(true); + region + } } impl Component for ShellRegion { @@ -522,14 +532,12 @@ impl<'a, S> AppShell<'a, S> { let extent = placed.extent(&tokens); let Placed { slot, edge, named, add, title, .. } = placed; let pane = ShellPane::new(slot.key()).edge(*edge).extent(extent).at(rect_of(slot.key())); - let mut region = ShellRegion::pane(pane).id_salt(("slot", slot.key())); - // A bar is as high as its content and the slot as high as its token, so the slot paints the bar's - // surface under it, and the bar sits at the slot's centre line: no band of the backdrop shows - // between the bar and the body. + // Every slot but the title is a chrome pane: it paints the surface under its bar or rail and + // the rule toward the body. The title bar paints its own. + let mut region = if *title { ShellRegion::pane(pane) } else { ShellRegion::chrome(pane) }.id_salt(("slot", slot.key())); + // A bar is as high as its content and the slot as high as its token, so the bar sits at the + // slot's centre line. let centred = !*title && matches!(edge, PaneEdge::Top | PaneEdge::Bottom); - if centred { - region = region.surface(SurfaceKind::Chrome); - } if let Some(label) = slot.name().cloned().or_else(|| named.map(|name| name(&words))) { region = region.label(label); } @@ -544,7 +552,7 @@ impl<'a, S> AppShell<'a, S> { }; show_slots(ui, false, app); // Only a body-only shell paints behind its body (the scrim). Otherwise the body paints what it shows, and the gaps - // between its parts (the dock's gutters) are the window's own clear colour. + // between its parts (the dock's gutters) show the window's background. let pane = ShellPane::new("body"); let pane = if content_room.is_some() { pane.at_content_height(regions.body) } else { pane.at(regions.body) }; let mut center = ShellRegion::pane(pane).label(body_label.clone()); diff --git a/crates/ui-shell/src/shell/canvas_shell.rs b/crates/ui-shell/src/shell/canvas_shell.rs index 53bed3638..34e3f5e10 100644 --- a/crates/ui-shell/src/shell/canvas_shell.rs +++ b/crates/ui-shell/src/shell/canvas_shell.rs @@ -26,7 +26,7 @@ use super::words::ShellWords; use crate::contract::{BodyCx, NoValue, Outcome, PaneEdge, Props as _, ShellPane, ShowContainer as _}; use crate::primitives::{CheckerArea, paint_surround}; use crate::runtime::env::{BodyMode, Env, Label, ShellEntry}; -use crate::style::SurroundLook; +use crate::style::{SurfaceKind, SurroundLook}; use egui::{CornerRadius, Rect, Response, Ui}; /// The slot keys of the preset. @@ -118,12 +118,14 @@ impl<'a> CanvasPanel<'a> { let mut rail_rect = None; if let (Some((label, mut add)), true) = (rail, dock) { let out = - ShellRegion::pane(ShellPane::new("panel_rail").edge(PaneEdge::End)).id_salt("panel_rail").label(label).show(ui, |ui, cx| add(ui, cx)); + ShellRegion::chrome(ShellPane::new("panel_rail").edge(PaneEdge::End)).id_salt("panel_rail").label(label).show(ui, |ui, cx| add(ui, cx)); rail_rect = Some(out.response.rect); } let mut tabs_rect = None; if let (Some(mut add), true) = (tabs.map(|RegionBody(add)| add), tabs_shown) { + // The document tabs sit on the window's background, as tab strips do. let out = ShellRegion::pane(ShellPane::new("document_tabs").edge(PaneEdge::Top)) + .surface(SurfaceKind::Background) .id_salt("document_tabs") .label(words.document_tabs.clone()) .show(ui, |ui, cx| add(ui, cx)); diff --git a/crates/ui-shell/src/shell/regions.rs b/crates/ui-shell/src/shell/regions.rs index c1d16a5f7..b36c63450 100644 --- a/crates/ui-shell/src/shell/regions.rs +++ b/crates/ui-shell/src/shell/regions.rs @@ -45,7 +45,8 @@ impl SlotSize { } /// One bar or rail of the skeleton: its key, whether it shows, whether it shows in a reveal, its size and its AccessKit -/// name. The slot's body draws its own surface and edge. +/// name. The shell paints the chrome surface over the whole slot and a divider along its edge toward the body; the +/// title slot's bar paints its own. #[derive(Clone, Debug, PartialEq)] #[non_exhaustive] pub struct Slot {