diff --git a/crates/ui-contract/src/contract/body/placement.rs b/crates/ui-contract/src/contract/body/placement.rs index 311fe446b3..daf996135d 100644 --- a/crates/ui-contract/src/contract/body/placement.rs +++ b/crates/ui-contract/src/contract/body/placement.rs @@ -163,12 +163,8 @@ pub(super) fn measure_layer(props: &ContainerProps, id: Id, ui: &Ui) -> areas::L let area = sub(id, "area"); match &props.mount { Mount::Viewport { .. } if windows::mount_window(ui.ctx(), id) => ui.layer_id(), - Mount::Layer(overlay) | Mount::Viewport { fallback: overlay, .. } => { - areas::layer_of(crate::runtime::overlay::layer_tier(ui.ctx(), overlay.rank), area) - } - Mount::FullWindow => { - areas::layer_of(crate::runtime::overlay::layer_tier(ui.ctx(), crate::contract::Overlay::full_window(props.focus).rank), area) - } + Mount::Layer(overlay) | Mount::Viewport { fallback: overlay, .. } => areas::layer_of(overlay.tier(ui.ctx()), area), + Mount::FullWindow => areas::layer_of(crate::contract::Overlay::full_window(props.focus).tier(ui.ctx()), area), _ => ui.layer_id(), } } diff --git a/crates/ui-contract/src/contract/overlay.rs b/crates/ui-contract/src/contract/overlay.rs index 5974d4d2c7..f056b55e78 100644 --- a/crates/ui-contract/src/contract/overlay.rs +++ b/crates/ui-contract/src/contract/overlay.rs @@ -3,7 +3,7 @@ //! One host (`host`) creates the egui layer through `runtime::egui::areas` and applies rank, backdrop, fit, scroll, //! dismissal and the focus scope. `OverlayUi::show` and the tooltip and toast hosts run it. -pub use crate::runtime::overlay::{LayerRole, OpenFilter, any_open, close_popups, family, is_open, request_close, top}; +pub use crate::runtime::overlay::{LayerRole, OpenFilter, PopupLayer, any_open, close_popups, family, is_open, request_close, top}; pub(crate) mod container_open; mod dismissal; diff --git a/crates/ui-contract/src/contract/overlay/host.rs b/crates/ui-contract/src/contract/overlay/host.rs index 25ebaa196e..3acfdf2829 100644 --- a/crates/ui-contract/src/contract/overlay/host.rs +++ b/crates/ui-contract/src/contract/overlay/host.rs @@ -161,7 +161,7 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U if let Some(nudge) = &nudge { placed.at += nudge.offset(); } - let tier = overlay::layer_tier(ctx, overlay.rank); + let tier = overlay.tier(ctx); if (sized || layer.size.is_some()) && areas::layer_rect(ctx, area).is_none() { areas::seed_area(ctx, areas::layer_of(tier, area), placed.at, placed.room); } @@ -251,6 +251,7 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U entry.exiting = layer.exiting; entry.cover = cover; entry.region = layer.region; + entry.below_windows = overlay.rank == Rank::Popup && tier == areas::Tier::Window; entry.scoped = scope.is_some(); entry.absorbs = overlay.dismiss.outside == Outside::Absorb; entry.closes_on_commands = overlay.dismiss.commands; @@ -300,7 +301,7 @@ fn host_in_popup(ctx: &Context, layer: &Layer<'_>, popup: PopupRoom, body: &mut let measured = layer.size.map(|size| egui::vec2(size.x.max(min_width), size.y)); let unplaced = placement(ctx, layer, covers, measured, bounds, anchor); let parent = overlay::drawing_parent(ctx); - let tier = overlay::layer_tier(ctx, overlay.rank); + let tier = overlay.tier(ctx); let scope = (overlay.focus != FocusPolicy::NONE).then_some(overlay.focus); if overlay.rank.is_modal() && appears { overlay::close_popups_outside(ctx, &[layer.id]); @@ -358,7 +359,7 @@ fn show_in_popup( let overlay = layer.overlay; let window = ctx.content_rect(); let area = area_id(layer.id); - let tier = overlay::layer_tier(&ctx, overlay.rank); + let tier = overlay.tier(&ctx); let cover = match overlay.rank { Rank::Modal { backdrop } => { let scrim = match backdrop { @@ -518,8 +519,7 @@ pub(crate) fn host_window(ctx: &Context, layer: &Layer<'_>, rect: Rect) -> Layer let overlay = layer.overlay; let mut memory = recall(layer, ctx); let scope = (overlay.focus != FocusPolicy::NONE).then_some(overlay.focus); - let mut entry = - OpenEntry::new(layer.id, overlay.rank, overlay.keys, rect, areas::layer_of(overlay::layer_tier(ctx, overlay.rank), area_id(layer.id))); + let mut entry = OpenEntry::new(layer.id, overlay.rank, overlay.keys, rect, areas::layer_of(overlay.tier(ctx), area_id(layer.id))); entry.scoped = scope.is_some(); entry.window = true; overlay::record(ctx, entry); diff --git a/crates/ui-contract/src/contract/overlay/props.rs b/crates/ui-contract/src/contract/overlay/props.rs index a01d00a92f..b91e77ec6a 100644 --- a/crates/ui-contract/src/contract/overlay/props.rs +++ b/crates/ui-contract/src/contract/overlay/props.rs @@ -5,12 +5,12 @@ use super::place::{Anchor, FloatPlace, OverlayFit, Place, Resize, ResizeEdges, S use crate::runtime::access::PopupKind; use crate::runtime::focus::{FocusPolicy, Initial}; use crate::runtime::motion::{MotionSpec, spec}; -use crate::runtime::overlay::{Backdrop, LayerRole, Rank}; +use crate::runtime::overlay::{Backdrop, LayerRole, PopupLayer, Rank}; use crate::runtime::windows::ResizeEdge; use craft_behavior::overlay::{Align, MinWidth, Side}; use craft_behavior::{GesturePhase, OwnerClass}; use egui::emath::TSTransform; -use egui::{Align2, Id, Pos2, Rect, Response, Vec2}; +use egui::{Align2, Context, Id, Pos2, Rect, Response, Vec2}; use std::borrow::Cow; /// What a press outside the layer and its anchor does. @@ -159,6 +159,9 @@ pub struct Overlay { pub continue_move: Option, /// What the layer is for; a progress window is left out of `any_open`. pub role: LayerRole, + /// Where a popup stands against the floating windows: above them (the default), or below them when it is opened + /// outside every layer, as a dock column's flyout ([`PopupLayer::BelowWindows`]). Read only for `Rank::Popup`. + pub popup_layer: PopupLayer, /// Set only by [`Overlay::full_window`]. full_window: bool, } @@ -199,6 +202,7 @@ impl Overlay { moved_by_app: false, continue_move: None, role: LayerRole::default(), + popup_layer: PopupLayer::default(), full_window: false, } } @@ -467,6 +471,18 @@ impl Overlay { self } + /// Sets where a popup stands against the floating windows ([`Overlay::popup_layer`]). + pub fn popup_layer(mut self, layer: PopupLayer) -> Overlay { + self.popup_layer = layer; + self + } + + /// The egui tier the layer opened now shows in: its rank's, raised to that of the layer it is opened inside, and + /// the windows' for a popup that stands below them. + pub(crate) fn tier(&self, ctx: &Context) -> crate::runtime::egui::areas::Tier { + crate::runtime::overlay::layer_tier(ctx, self.rank, self.popup_layer) + } + /// Sets whether the move band moves the OS window the layer is shown in, in place of the layer. pub fn moves_window(mut self, on: bool) -> Overlay { self.moves_window = on; diff --git a/crates/ui-contract/src/runtime/egui/areas.rs b/crates/ui-contract/src/runtime/egui/areas.rs index 2de7e26257..4a23d5179b 100644 --- a/crates/ui-contract/src/runtime/egui/areas.rs +++ b/crates/ui-contract/src/runtime/egui/areas.rs @@ -219,7 +219,8 @@ pub type LayerKey = egui::LayerId; /// How an overlay layer ranks among egui's orders, bottom to top: the one place the runtime chooses an `Order`. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub(crate) enum Tier { - /// Floating windows and panels. + /// Floating windows and panels, and below them the popups that stand below the windows + /// (`overlay::PopupLayer::BelowWindows`). Window, /// Toasts, popups, modals and their chrome. Foreground, diff --git a/crates/ui-contract/src/runtime/overlay.rs b/crates/ui-contract/src/runtime/overlay.rs index 5046e20d53..bdf3e4f7d2 100644 --- a/crates/ui-contract/src/runtime/overlay.rs +++ b/crates/ui-contract/src/runtime/overlay.rs @@ -26,7 +26,8 @@ pub enum Backdrop { Scrim, } -/// An overlay's place in the order. `Rank` is the only place a layer's egui order is chosen. +/// An overlay's place in the order. `Rank` is the only place a layer's egui order is chosen, with a popup's +/// [`PopupLayer`]. #[derive(Clone, Copy, Debug, PartialEq)] #[non_exhaustive] pub enum Rank { @@ -108,6 +109,20 @@ pub enum CloseReason { AnchorGone, } +/// Where a popup stands against the floating windows of its window. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum PopupLayer { + /// Above every floating window, as menus, dropdowns and popovers stand. + #[default] + AboveWindows, + /// Below the floating windows and above the window's own content, for a popup opened outside every layer (a dock + /// column's flyout, which floating panels stay above): it shows in the windows' tier under all of them, so a window + /// over it is drawn above it and takes the presses there. It still takes keys, Escape and its dismissal as a popup, + /// and the layers opened from it stand above the windows. A popup opened inside a layer stands above the windows. + BelowWindows, +} + /// What a layer is for, beyond its rank. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] @@ -183,6 +198,8 @@ pub struct OpenEntry { pub(crate) place: Option, /// The dialog of a dialog host the layer shows for (`stack_place`). dialog: Option, + /// A popup shown in the windows' tier below them ([`PopupLayer::BelowWindows`]): listed under every window. + pub(crate) below_windows: bool, } /// A replay moves the entry's screen rects with its record; the rest stays. @@ -233,6 +250,7 @@ impl OpenEntry { region: None, place: None, dialog: None, + below_windows: false, } } @@ -521,10 +539,15 @@ pub fn drawing_parent(ctx: &Context) -> Option { /// The tier a layer of `rank` opened now shows in: the higher of its rank's and that of the layer whose body is /// running. egui sorts layers by tier before the family order, so a floating window opened inside a modal's family -/// shows in the modal's tier, above its parent, and takes input. -pub(crate) fn layer_tier(ctx: &Context, rank: Rank) -> Tier { +/// shows in the modal's tier, above its parent, and takes input. A popup that stands below the windows (`stands`) and +/// is opened outside every layer shows in the windows' tier. +pub(crate) fn layer_tier(ctx: &Context, rank: Rank, stands: PopupLayer) -> Tier { let parent = with_pass(ctx, |pass| pass.drawing.last().map(|(_, tier)| *tier)); - parent.map_or(rank.tier(), |parent| parent.max(rank.tier())) + match parent { + None if rank == Rank::Popup && stands == PopupLayer::BelowWindows => Tier::Window, + None => rank.tier(), + Some(parent) => parent.max(rank.tier()), + } } /// Whether the layer `id`, open in this pass, faded out in the last one: it opens anew. @@ -889,27 +912,39 @@ pub(crate) fn end_pass(ctx: &Context) { persist.raised.retain(|id, _| roots.contains(id)); persist.appeared.retain(|id, _| current.iter().any(|entry| entry.id == *id)); let before = families(¤t, &persist.raised); - if let Some(point) = pressed - && let Some(hit) = before - .iter() - .rev() - .find(|members| members.iter().filter(live).filter(|entry| entry.interactable()).any(|entry| entry.rect.contains(point))) - && let Some(root) = hit.first() - { - stamp(root.id, persist); + if let Some(point) = pressed { + // A popup below the windows takes a press only where no other layer lies over it. + let hit = |below: bool| { + before.iter().rev().find(|members| { + members + .iter() + .filter(live) + .filter(|entry| entry.interactable() && entry.below_windows == below) + .any(|entry| entry.rect.contains(point)) + }) + }; + if let Some(root) = hit(false).or_else(|| hit(true)).and_then(|members| members.first()) { + stamp(root.id, persist); + } } let families = families(¤t, &persist.raised); + // The popups below the windows are listed first: egui orders the layers of one tier as listed, so every window + // lies over them, while their families keep their place in the stack for keys and presses. let mut order: Vec = Vec::new(); + let mut below: Vec = Vec::new(); persist.stack.clear(); for members in &families { for member in members { - if !member.window { + if member.below_windows { + below.push(member.layer); + } else if !member.window { order.extend(member.cover); order.push(member.layer); } persist.stack.push(member.id); } } + let order: Vec = below.into_iter().chain(order).collect(); persist.modal = current.iter().any(|entry| entry.blocks_window() && !entry.exiting); persist.top_modal = current.iter().rev().find(|entry| entry.blocks_window() && !entry.exiting).map(|entry| TopModal { id: entry.id, cover: entry.cover }); diff --git a/crates/ui-panels/src/docking/config.rs b/crates/ui-panels/src/docking/config.rs index d3b885867a..5afe7c129e 100644 --- a/crates/ui-panels/src/docking/config.rs +++ b/crates/ui-panels/src/docking/config.rs @@ -3,6 +3,7 @@ use super::IconicMode; use super::targets::ZoneRule; +use crate::contract::overlay::PopupLayer; use crate::tabs::PanelTabLook; use craft_behavior::{DockSide, IconId}; @@ -115,6 +116,12 @@ pub struct DockConfig { /// What the icons of a docked column collapsed to icons open: flyouts, or with [`IconicMode::Rail`] the column /// itself, whose icons then stay beside it while it is expanded. Floating windows' icons open flyouts. pub iconic_mode: IconicMode, + /// Where the flyouts of docked columns collapsed to icons stand against the floating windows: above them + /// ([`PopupLayer::AboveWindows`], the default), or below them ([`PopupLayer::BelowWindows`]), so a floating window + /// stays in front of a docked column's open flyout it overlaps, is drawn over it and takes the presses there. A + /// flyout below the windows still closes as before, and the menus opened from it stand above everything. A + /// floating window's own flyouts stand above it either way. + pub flyout_layer: PopupLayer, } impl Default for DockConfig { @@ -141,6 +148,7 @@ impl Default for DockConfig { panel_menu_always: false, panel_menu_icon: IconId::new("more"), iconic_mode: IconicMode::Flyouts, + flyout_layer: PopupLayer::AboveWindows, } } } @@ -153,6 +161,13 @@ impl DockConfig { self } + /// Where docked columns' flyouts stand against the floating windows ([`flyout_layer`](Self::flyout_layer)). + #[must_use] + pub fn flyout_layer(mut self, layer: PopupLayer) -> Self { + self.flyout_layer = layer; + self + } + /// The Minimize and Move Group Up and Down items of docked groups' menus on or off. #[must_use] pub fn group_order_items(mut self, on: bool) -> Self { diff --git a/crates/ui-panels/src/docking/flyout.rs b/crates/ui-panels/src/docking/flyout.rs index 645360fbc5..6b3dd497ce 100644 --- a/crates/ui-panels/src/docking/flyout.rs +++ b/crates/ui-panels/src/docking/flyout.rs @@ -1,6 +1,6 @@ //! `Flyout`: the panel an icon of an iconic column opens beside the column. -use crate::contract::overlay::{Anchor, Dismiss, FloatPlace, Outside, Place, PlacementChange, ResizeEdges}; +use crate::contract::overlay::{Anchor, Dismiss, FloatPlace, Outside, Place, PlacementChange, PopupLayer, ResizeEdges}; use crate::contract::{ BodyCx, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, Overlay, OverlayUi, Pad, PopupHandle, Role, SizeLimits, Sizing, }; @@ -56,6 +56,10 @@ impl Outcome for FlyoutOutput { /// The user resizes it by its top and bottom edges, the edge away from the column and the two corners there; the /// column side stays. The flyout keeps no rect of its own: each step comes back in [`FlyoutShown::placed`] and the /// caller places the next pass from it. +/// +/// It stands above the floating windows as a popup does, or below them with `popup_layer` set to +/// `PopupLayer::BelowWindows` when it is opened outside every layer: a window over it is drawn above it and takes the +/// presses there, and the menus opened from it still stand above everything. #[derive(crate::contract::Component, crate::contract::Props)] #[component(container, unregistered)] pub struct Flyout { @@ -72,6 +76,9 @@ pub struct Flyout { /// The least size a resize leaves the flyout. #[prop(quantity = "least room a resize leaves, from the dock's measured sizes, in points")] least: Vec2, + /// Where the flyout stands against the floating windows: above them (the default) or below them. + #[prop] + popup_layer: PopupLayer, placed: Option, } @@ -80,7 +87,17 @@ impl Flyout { /// `Side::End`), closing on a press outside it and when the focus leaves it if `auto_collapse`. pub fn new(opens: Side, size: Vec2, auto_collapse: bool) -> Self { let props = ContainerProps::new().surface(SurfaceKind::Popup).pad(Pad::None).sizing(Sizing::Content); - Flyout { common: Common::new(), props, opens, size, auto_collapse, within: Rect::EVERYTHING, least: Vec2::ZERO, placed: None } + Flyout { + common: Common::new(), + props, + opens, + size, + auto_collapse, + within: Rect::EVERYTHING, + least: Vec2::ZERO, + popup_layer: PopupLayer::AboveWindows, + placed: None, + } } /// The layer the flyout shows in, its top left at `top_left`: placed by the caller, resizable on every edge but @@ -102,7 +119,8 @@ impl Flyout { .focus_left(self.auto_collapse) .commands(false), ) - .body_scroll(false); + .body_scroll(false) + .popup_layer(self.popup_layer); if bounded { overlay.bounds(self.within) } else { overlay } } diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index 42e0c7f4d2..fec17faa0e 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -8,7 +8,7 @@ use super::dock_column::{ use super::group::GripMarks; use super::{DockSizes, DockSpot, DockTargets, DockWords, DragUnit, Flyout, GroupAt, PanelKey, PanelSpec, Splitter, start_icon_drag}; use crate::buttons::IconButton; -use crate::contract::overlay::Anchor; +use crate::contract::overlay::{Anchor, PopupLayer}; use crate::contract::{ Access, Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, Edit as _, EditResponse, HeaderEdge, HeaderParts, HeaderRegion, MeasureCx, Name, Outcome, OverlayUi, Overlays as _, Pad, PaintUi, PartsCx, Pointer as _, Props as _, Role, ShowContainer as _, Sizing, @@ -185,6 +185,8 @@ pub struct IconicColumnStyle { /// size. The flyout's top is level with its group's icons, shifted by the group's `flyout_offset`, inside `within`. /// The user resizes it by its top and bottom edges and the edge away from the column; each step comes back in /// [`IconicColumnOutput::flyout`], which the host keeps in the group (`flyout_width`, `height`, `flyout_offset`). +/// The flyouts stand above the floating windows as popups do, or below them with `flyout_layer` set to +/// `PopupLayer::BelowWindows`, which a dock area sets for its docked columns from `DockConfig::flyout_layer`. /// /// In a floating window ([`ColumnBar::Window`]) the window's title row is the column's bar and the window's sides set /// its width: the column shows its icons under it, with no divider on its inner edge, and registers no edge bands. @@ -220,6 +222,10 @@ pub struct IconicColumn<'a, P: Value + Hash + 'static> { /// What the icons open: flyouts, or the column itself as a rail. #[prop] mode: IconicMode, + /// Where its flyouts stand against the floating windows: above them (the default), or below them, so a floating + /// window over a docked column's flyout stays in front ([`Flyout`]'s `popup_layer`). + #[prop] + flyout_layer: PopupLayer, /// The rect the dock may grow within, which bounds how wide its inner edge can make the column, and the rect its /// flyouts open in. Unset, the flyouts take the room layers opened there have (`overlay::layer_room`): around a /// palette window, the work area. @@ -290,6 +296,7 @@ impl<'a, P: Value + Hash + Debug + 'static> IconicColumn<'a, P> { bar: ColumnBar::Own, auto_collapse: false, mode: IconicMode::Flyouts, + flyout_layer: PopupLayer::AboveWindows, within: Rect::NOTHING, card: None, open, @@ -699,7 +706,7 @@ impl Component for IconicColumn<'_, P> { } let popup = cx.popup("flyout"); let sizes = cx.style.sizes.column; - let (opens, auto_collapse, column) = (self.opens, self.auto_collapse, cx.rect); + let (opens, auto_collapse, layer, column) = (self.opens, self.auto_collapse, self.flyout_layer, cx.rect); // The screen side the flyouts open on, mirrored in a right-to-left layout. let right = (opens == Side::End) != cx.flow.is_rtl(); let within = if self.within.is_positive() { self.within } else { crate::contract::overlay::layer_room(&cx.core.ctx) }; @@ -717,7 +724,7 @@ impl Component for IconicColumn<'_, P> { let mut resized = None; for (at, plan) in plans.into_iter().enumerate() { let Some(FlyoutPlan { group, top_left, size, fixed, icons_top }) = plan else { continue }; - let shown = Flyout::new(opens, size, auto_collapse).within(bounds).least(least).show_popup( + let shown = Flyout::new(opens, size, auto_collapse).within(bounds).least(least).popup_layer(layer).show_popup( ui, popup.at(at), Anchor::Point(top_left), diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index c8f50a75ab..6ff5377fe5 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -3,7 +3,7 @@ use super::hide::{self, PruneKey}; use crate::contract::Revision; -use crate::contract::overlay::{PlacementChange, PlacementKind}; +use crate::contract::overlay::{PlacementChange, PlacementKind, PopupLayer}; use crate::contract::{ Bind, BindMut, BodyCx, Cx, Entry, Gap, MemoKey, MemoProps, MemoView, NoValue, Outbox, Outcome, Pad, Pointer as _, Props as _, Show as _, ShowContainer as _, Sizing, Tracked, WordSetCx as _, @@ -1339,8 +1339,9 @@ impl Pass<'_, P> { DockTargets::

::register_room(ui.ctx(), dock, cell); } let opens = if edge == DockEdge::Start { Side::End } else { Side::Start }; - // Only a docked column's icons are a rail; a floating window's open flyouts. + // Only a docked column's icons are a rail; a floating window's open flyouts, which stand above its window. let mode = if in_window { IconicMode::Flyouts } else { scene.config.iconic_mode }; + let flyout_layer = if in_window { PopupLayer::AboveWindows } else { scene.config.flyout_layer }; // The width the user gives a column by its inner edge leaves out its card's inset. let inset = card.unwrap_or(0.0); let mut icons = |cell: Rect, open: Option

, card: Option| { @@ -1353,7 +1354,8 @@ impl Pass<'_, P> { .bar(bar) .within(within) .auto_collapse(scene.auto_collapse) - .mode(mode); + .mode(mode) + .flyout_layer(flyout_layer); let shown = match card { Some(inset) => shown.card(inset), None => shown, diff --git a/crates/ui-patterns/tests/it/docking/columns.rs b/crates/ui-patterns/tests/it/docking/columns.rs index 217f91ad0c..18168744b2 100644 --- a/crates/ui-patterns/tests/it/docking/columns.rs +++ b/crates/ui-patterns/tests/it/docking/columns.rs @@ -2,6 +2,8 @@ use craft_behavior::Axis; use craft_behavior::dock::{Action, Column, DockEdge, Floating, Group, Layout, Node, Permissions, SplitSize, Workspace, node_at}; +use craft_ui::buttons::Button; +use craft_ui::contract::overlay::PopupLayer; use craft_ui::contract::{Bind, BodyCx, PlainData, Role, Show as _, SizeLimits, Tracked}; use craft_ui::display::Text; use craft_ui::docking::{ @@ -421,6 +423,91 @@ fn rail_icons_stay_beside_the_expanded_column_and_the_open_panels_icon_collapses assert!(!shown(&fixture, "Alpha body"), "and its panel no longer shows"); } +/// How tall the flyout of [`UnderWindow`]'s Alpha group measures. +const FLYOUT_HEIGHT: f32 = 300.0; + +/// Panels for a docked flyout under a floating window: Alpha's group, in the flyout, is a view that measures +/// [`FLYOUT_HEIGHT`] and records the rect it shows in; Beta, in the window, shows a button that counts its clicks. +struct UnderWindow { + flyout: Rc>>, + clicks: Rc>, +} + +impl DockPanels for UnderWindow { + fn body(&mut self, panel: &u32, ui: &mut Ui, _: &mut BodyCx<'_>) { + if *panel == 11 { + self.clicks.set(self.clicks.get() + Button::new("Beta button").show(ui).clicks); + } + } + + fn group_view(&mut self, panels: &[u32], _: usize, _: &mut Ui, at: GroupAt, _: &mut BodyCx<'_>) -> Option { + if !panels.contains(&10) { + return None; + } + Some(match at { + GroupAt::Measure(_) => FLYOUT_HEIGHT, + GroupAt::Show(rect) => { + self.flyout.set(Some(rect)); + rect.height() + } + }) + } +} + +/// A start dock whose column, collapsed to icons, holds Alpha, beside the canvas, and a floating window holding Beta +/// at `window`. +fn flyout_dock(window: Option) -> Arc> { + let side = Column::new(vec![Group::new(vec![10], 0)]).with_iconic(true); + let root = Node::split(Axis::X, SplitSize::Ratio(0.4), Node::dock(DockEdge::Start, vec![side]), Node::tabs(vec![1], 0)); + let windows = window.map(|at| Floating::new(100, Column::new(vec![Group::new(vec![11], 0)]), at)).into_iter().collect(); + Arc::new(Workspace::new(Layout::new(Some(root), windows))) +} + +/// What shows where a floating window lies over part of Alpha's open flyout, with docked flyouts standing at `layer`: +/// whether the layer on top there is the flyout's, whether it stands above the flyout's in egui's layer order, and how +/// many clicks a click there gave the window's button. +fn flyout_under_window(layer: PopupLayer) -> (bool, bool, u32) { + let workspace = Rc::new(RefCell::new(flyout_dock(None))); + let (flyout, clicks) = (Rc::new(Cell::new(None)), Rc::new(Cell::new(0))); + let mut panels = UnderWindow { flyout: Rc::clone(&flyout), clicks: Rc::clone(&clicks) }; + let (held, specs) = (Rc::clone(&workspace), Tracked::new(Sides)); + let mut fixture = Fixture::new(move |ui| { + let config = DockConfig::default().native_windows(false).flyout_layer(layer); + let shown = Bind::given(Arc::clone(&held.borrow())); + DockArea::new("Flyout dock", shown, &specs, &mut panels, config).flyout(Bind::given(Some(10))).show(ui); + }); + fixture.room(Vec2::new(900.0, 600.0)).settle(); + let open = flyout.get().expect("Alpha's flyout shows its group"); + // The window covers the flyout's end two thirds from its top and reaches past its end edge. + let window = Rect::from_min_size(open.min + Vec2::new(open.width() / 3.0, 0.0), Vec2::new(open.width() + 100.0, 220.0)); + *workspace.borrow_mut() = flyout_dock(Some(window)); + fixture.settle(); + let button = fixture.by_label("Beta button").expect("the floating window shows Beta's button").center(); + assert!(open.contains(button), "the window's button lies over the flyout: {button:?} in {open:?}"); + let alone = Pos2::new(open.left() + open.width() / 6.0, open.center().y); + let ctx = fixture.ctx().clone(); + let flyout_layer = ctx.layer_id_at(alone).expect("the flyout is on top beside the window"); + let top = ctx.layer_id_at(button).expect("a layer lies under the button"); + let place = |layer: egui::LayerId| ctx.memory(|memory| memory.layer_ids().position(|listed| listed == layer)); + let above = place(top) > place(flyout_layer); + fixture.click_at(button).settle(); + (top == flyout_layer, above, clicks.get()) +} + +/// A docked column's open flyout stands above a floating window over it, as popups do: it is drawn over the window +/// and takes the press there. With `DockConfig::flyout_layer(PopupLayer::BelowWindows)` the window stays in front: its +/// layer lies above the flyout's and the press reaches its button. +#[trial] +fn a_floating_window_stays_above_a_docked_flyout_that_stands_below_the_windows() { + let (flyout_on_top, _, clicks) = flyout_under_window(PopupLayer::AboveWindows); + assert!(flyout_on_top, "by default the flyout is on top where it overlaps the window"); + assert_eq!(clicks, 0, "and the press there does not reach the window"); + + let (flyout_on_top, window_above, clicks) = flyout_under_window(PopupLayer::BelowWindows); + assert!(!flyout_on_top && window_above, "below the windows, the window's layer lies above the flyout's"); + assert_eq!(clicks, 1, "and the press where they overlap reaches the window's button"); +} + #[derive(PlainData)] struct RailWithMenu; diff --git a/docs/contract-api.md b/docs/contract-api.md index 30983c458b..7ffd5459c3 100644 --- a/docs/contract-api.md +++ b/docs/contract-api.md @@ -2403,7 +2403,7 @@ The component traits, context types, `PaintUi`, `Looks`, the pipeline and its st - `fn unshown(response: Response) -> Option where Self: Sized,`. The output of a layer-like container that shows nothing this pass (closed, past its exit fade): `response` is - `fn value_text(&self) -> Option<&str>`. The shown value as the component words it to assistive technology; `None` for a component that gives none. - `fn story_facts(&self) -> crate::testing::StoryOutput`. The facts a story reports about this output: its id, click, edit kinds, collection kinds and visible range. -- `craft_ui::contract::Overlay`: `pub struct Overlay { pub place: Place, pub fit: OverlayFit, pub min_width: MinWidth, pub movable: bool, pub resize: Resize, pub rank: Rank, pub keys: OwnerClass, pub focus: FocusPolicy, pub dismiss: Dismiss, pub motion: MotionSpec, pub opener: Option, pub popup: PopupKind, pub size: Option, pub size_limits: SizeLimits, pub placed: Option, pub placed_at: Option, pub bounds: Option, pub opacity: f32, pub body_scroll: bool, pub moves_window: bool, pub moved_by_app: bool, pub continue_move: Option, pub role: LayerRole }`. Data describing an egui layer. Presets fill focus and dismissal; builders change single fields. +- `craft_ui::contract::Overlay`: `pub struct Overlay { pub place: Place, pub fit: OverlayFit, pub min_width: MinWidth, pub movable: bool, pub resize: Resize, pub rank: Rank, pub keys: OwnerClass, pub focus: FocusPolicy, pub dismiss: Dismiss, pub motion: MotionSpec, pub opener: Option, pub popup: PopupKind, pub size: Option, pub size_limits: SizeLimits, pub placed: Option, pub placed_at: Option, pub bounds: Option, pub opacity: f32, pub body_scroll: bool, pub moves_window: bool, pub moved_by_app: bool, pub continue_move: Option, pub role: LayerRole, pub popup_layer: PopupLayer }`. Data describing an egui layer. Presets fill focus and dismissal; builders change single fields. - `pub fn popover() -> Overlay`. A popover: a popup anchored below, from its content, at least as wide as its anchor and capped by the window, - `pub fn dropdown() -> Overlay`. A dropdown list: from its content, at least as wide as its anchor and capped, focus stays on the anchor. It - `pub fn menu() -> Overlay`. A menu: a popup the arrow keys move through. A press outside closes it and goes no further. @@ -2434,6 +2434,7 @@ The component traits, context types, `PaintUi`, `Looks`, the pipeline and its st - `pub fn min_width(mut self, min_width: MinWidth) -> Overlay`. Sets the narrowest width. - `pub fn movable(mut self, on: bool) -> Overlay`. Sets whether the user may move it. - `pub fn role(mut self, role: LayerRole) -> Overlay`. Sets what the layer is for ([`Overlay::role`]). + - `pub fn popup_layer(mut self, layer: PopupLayer) -> Overlay`. Sets where a popup stands against the floating windows ([`Overlay::popup_layer`]). - `pub fn moves_window(mut self, on: bool) -> Overlay`. Sets whether the move band moves the OS window the layer is shown in, in place of the layer. - `pub fn moved_by_app(mut self) -> Overlay`. The app moves the OS window from the move band ([`Overlay::moved_by_app`]). - `pub fn continue_move(mut self, grab: Vec2) -> Overlay`. The move band takes over the held primary press in this pass, with the pointer at `grab` inside the layer @@ -2725,7 +2726,7 @@ Chapter 15: the `Overlay` data, its presets, popup handles, `OverlayUi` and the - `craft_ui::contract::overlay::OpenFilter`: re-export of `craft_ui::runtime::overlay::OpenFilter`. - `craft_ui::contract::overlay::Opener`: `pub struct Opener { pub id: Id, pub rect: Rect, pub layer: areas::Layer, pub trigger: Trigger, pub enabled: bool, pub anchor: Option, pub others: Vec }`. A component that opens a free-standing popup, and how. A layer with several openers keeps the first as its - `craft_ui::contract::overlay::Outside`: `pub enum Outside { Close, Keep, Absorb }`. What a press outside the layer and its anchor does. -- `craft_ui::contract::overlay::Overlay`: `pub struct Overlay { pub place: Place, pub fit: OverlayFit, pub min_width: MinWidth, pub movable: bool, pub resize: Resize, pub rank: Rank, pub keys: OwnerClass, pub focus: FocusPolicy, pub dismiss: Dismiss, pub motion: MotionSpec, pub opener: Option, pub popup: PopupKind, pub size: Option, pub size_limits: SizeLimits, pub placed: Option, pub placed_at: Option, pub bounds: Option, pub opacity: f32, pub body_scroll: bool, pub moves_window: bool, pub moved_by_app: bool, pub continue_move: Option, pub role: LayerRole }`. Data describing an egui layer. Presets fill focus and dismissal; builders change single fields. +- `craft_ui::contract::overlay::Overlay`: `pub struct Overlay { pub place: Place, pub fit: OverlayFit, pub min_width: MinWidth, pub movable: bool, pub resize: Resize, pub rank: Rank, pub keys: OwnerClass, pub focus: FocusPolicy, pub dismiss: Dismiss, pub motion: MotionSpec, pub opener: Option, pub popup: PopupKind, pub size: Option, pub size_limits: SizeLimits, pub placed: Option, pub placed_at: Option, pub bounds: Option, pub opacity: f32, pub body_scroll: bool, pub moves_window: bool, pub moved_by_app: bool, pub continue_move: Option, pub role: LayerRole, pub popup_layer: PopupLayer }`. Data describing an egui layer. Presets fill focus and dismissal; builders change single fields. - `pub fn popover() -> Overlay`. A popover: a popup anchored below, from its content, at least as wide as its anchor and capped by the window, - `pub fn dropdown() -> Overlay`. A dropdown list: from its content, at least as wide as its anchor and capped, focus stays on the anchor. It - `pub fn menu() -> Overlay`. A menu: a popup the arrow keys move through. A press outside closes it and goes no further. @@ -2756,6 +2757,7 @@ Chapter 15: the `Overlay` data, its presets, popup handles, `OverlayUi` and the - `pub fn min_width(mut self, min_width: MinWidth) -> Overlay`. Sets the narrowest width. - `pub fn movable(mut self, on: bool) -> Overlay`. Sets whether the user may move it. - `pub fn role(mut self, role: LayerRole) -> Overlay`. Sets what the layer is for ([`Overlay::role`]). + - `pub fn popup_layer(mut self, layer: PopupLayer) -> Overlay`. Sets where a popup stands against the floating windows ([`Overlay::popup_layer`]). - `pub fn moves_window(mut self, on: bool) -> Overlay`. Sets whether the move band moves the OS window the layer is shown in, in place of the layer. - `pub fn moved_by_app(mut self) -> Overlay`. The app moves the OS window from the move band ([`Overlay::moved_by_app`]). - `pub fn continue_move(mut self, grab: Vec2) -> Overlay`. The move band takes over the held primary press in this pass, with the pointer at `grab` inside the layer @@ -2797,6 +2799,7 @@ Chapter 15: the `Overlay` data, its presets, popup handles, `OverlayUi` and the - `pub fn changed(self, cx: &mut Cx<'_, C>) -> bool`. Whether a toggle, `open` or `close` queued in this pass leaves the popup's open state different from the - `pub fn bind_open(self, cx: &mut Cx<'_, C>, mut open: BindMut<'_, bool>) -> bool`. Binds the popup's open state to `open`: call it in `update`, after the toggles and closes the component - `pub fn is_open(self, cx: &mut Cx<'_, C>) -> bool`. Whether the popup is open in this pass: valid from step 8, with the changes queued so far applied. +- `craft_ui::contract::overlay::PopupLayer`: re-export of `craft_ui::runtime::overlay::PopupLayer`. - `craft_ui::contract::overlay::PopupRegion`: `pub struct PopupRegion(pub Option)`. The screen rect the popups opened in an env are contained in, and the popups opened from those: the menus of a menu - `pub fn new(region: Option) -> Self`. Popups contained in `region`; `None` lets them take the whole safe rect. - `craft_ui::contract::overlay::Resize`: `pub struct Resize { pub edges: ResizeEdges, pub by_caller: bool }`. How the user may resize a layer. @@ -4249,7 +4252,8 @@ The layer stack (15.2): the record of the egui layers shown, their order and the - `craft_ui::runtime::overlay::CloseReason`: `pub enum CloseReason { Requested, Escape, Outside, FocusLeft(crate::runtime::focus::FocusMove), Activated, Enter, Timeout, AnchorGone }`. Why a layer closes. - `craft_ui::runtime::overlay::LayerRole`: `pub enum LayerRole { Plain, Progress, InPlaceEditor }`. What a layer is for, beyond its rank. - `craft_ui::runtime::overlay::OpenFilter`: `pub enum OpenFilter { Any, Modal, Keys }`. What `any_open` counts. -- `craft_ui::runtime::overlay::Rank`: `pub enum Rank { Window, Toast, Popup, Modal { backdrop: Backdrop }, ModalChrome, Tooltip }`. An overlay's place in the order. `Rank` is the only place a layer's egui order is chosen. +- `craft_ui::runtime::overlay::PopupLayer`: `pub enum PopupLayer { AboveWindows, BelowWindows }`. Where a popup stands against the floating windows of its window. +- `craft_ui::runtime::overlay::Rank`: `pub enum Rank { Window, Toast, Popup, Modal { backdrop: Backdrop }, ModalChrome, Tooltip }`. An overlay's place in the order. `Rank` is the only place a layer's egui order is chosen, with a popup's - `pub const fn modal(backdrop: Backdrop) -> Rank`. A modal rank with `backdrop`. - `craft_ui::runtime::overlay::any_open`: `pub fn any_open(ctx: &Context, filter: OpenFilter) -> bool`. Whether any layer of the running viewport that `filter` counts was shown last frame. - `craft_ui::runtime::overlay::close_popups`: `pub fn close_popups(ctx: &Context)`. Queues a close of every popup layer of the running viewport shown last frame: its menus, dropdowns and lists. The diff --git a/docs/glossary.md b/docs/glossary.md index 317b2a8587..13ddc3563b 100644 --- a/docs/glossary.md +++ b/docs/glossary.md @@ -216,6 +216,7 @@ One row per name in the author table (Overview) and per `pub` item a component a | `PointerButton`, `Buttons` | Pointer buttons, egui-free | craft-behavior | 8.1 | | `Politeness` | An announcement's or live region's urgency | `craft_ui::runtime::access` | 12.1 | | `PopupHandle` | A `Copy` id and name for one of a component's own popups, from `cx.popup(name)`, with `trigger`, `open`, `close` and `is_open` | `craft_ui::contract` | 15.5 | +| `PopupLayer` | Where a popup stands against the floating windows: above them, or below them for one opened outside every layer (a dock column's flyout) | `craft_ui::runtime` (layer stack) | 15.2 | | Prelude | The stable surface of a crate | each crate | 1.11 | | Press-target rule | Exactly one root starts each press: on the topmost layer under it, the root whose press-taking shape is painted on top there; none when egui's hit test names a raw egui widget | `craft_ui::primitives` (sensing core) | 8.3 | | `PressPhase`, `PressState` | A press lifecycle's phase, and its state with mods, sample and capture | craft-behavior | 8.2 | diff --git a/docs/ui-docking.md b/docs/ui-docking.md index 081948655d..ab8b4518cb 100644 --- a/docs/ui-docking.md +++ b/docs/ui-docking.md @@ -105,6 +105,7 @@ The host handles these `DockEvent`s: | `panel_menu_always` | off | Every group shows its panel menu button, with the dock's own rows when the shown panel has none. Off: only a panel with rows of its own (`DockPanels::panel_rows`) gets the button. | | `panel_menu_icon` | `more` | The panel menu button's icon; `menu` gives the three-line mark. | | `native_windows` | on | Floating windows open as OS windows where the window host opens them and reports their positions (not on Wayland) and `PanelSpec::allow_native` allows. | +| `flyout_layer` | `PopupLayer::AboveWindows` | Where docked columns' flyouts stand against the floating windows. `PopupLayer::BelowWindows` keeps a floating window in front of a docked flyout it overlaps: drawn over it and taking the presses there. The flyout still closes by its rules, and menus opened from it stand above everything. A floating window's own flyouts stand above it either way. | The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords` holds the words.