From 9f1b8d6d20a7226c92ecd69ab8ec0f4facb2bb00 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Wed, 25 Nov 2026 10:10:33 +0700 Subject: [PATCH] dock: Flyout::docked stands a flyout as a docked column does, square on surface.panel with the column's line.border frame and no shadow; the flyouts of a flush dock's columns (DockConfig::flush_docks) take it, the others stay raised popups --- crates/ui-panels/src/docking/flyout.rs | 27 ++++++++++-- crates/ui-panels/src/docking/iconic.rs | 2 +- crates/ui-panels/src/docking/iconic/trials.rs | 44 +++++++++++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/crates/ui-panels/src/docking/flyout.rs b/crates/ui-panels/src/docking/flyout.rs index 645360fbc5..af380bbe65 100644 --- a/crates/ui-panels/src/docking/flyout.rs +++ b/crates/ui-panels/src/docking/flyout.rs @@ -2,9 +2,10 @@ use crate::contract::overlay::{Anchor, Dismiss, FloatPlace, Outside, Place, PlacementChange, ResizeEdges}; use crate::contract::{ - BodyCx, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, Overlay, OverlayUi, Pad, PopupHandle, Role, SizeLimits, Sizing, + BodyCx, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, Overlay, OverlayUi, Pad, PaintUi, PopupHandle, Role, + SizeLimits, Sizing, }; -use crate::style::{ComponentStyle, StyleCx, SurfaceKind}; +use crate::style::{ComponentStyle, Corners, StyleCx, SurfaceKind}; use craft_behavior::overlay::Side; use craft_behavior::{Metrics, Sense}; use egui::{Pos2, Rect, Response, Ui, Vec2}; @@ -72,6 +73,8 @@ 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, + /// The flyout stands as a docked column does: [`docked`](Flyout::docked). + docked: bool, placed: Option, } @@ -80,7 +83,19 @@ 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, docked: false, placed: None } + } + + /// The flyout stands as a docked column does, in place of a popup's raised surface: square on `surface.panel`, with + /// the column's `line.border` frame and no shadow (the flyouts of a flush dock's columns, + /// [`DockConfig::flush_docks`](super::DockConfig::flush_docks)). + #[must_use] + pub fn docked(mut self, on: bool) -> Self { + if on { + self.props = self.props.surface(SurfaceKind::Panel); + } + self.docked = on; + self } /// The layer the flyout shows in, its top left at `top_left`: placed by the caller, resizable on every edge but @@ -155,6 +170,12 @@ impl Component for Flyout { Sense::empty() } + fn paint_over(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { + if self.docked { + ui.draw().surface(cx.rect, SurfaceKind::Frame, Corners::None); + } + } + fn finish(self, cx: Cx<'_, Self>) -> FlyoutOutput { FlyoutOutput { response: cx.response.clone(), placed: self.placed } } diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index 802aefd8f5..86845fa6ea 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -772,7 +772,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).docked(self.framed).show_popup( ui, popup.at(at), Anchor::Point(top_left), diff --git a/crates/ui-panels/src/docking/iconic/trials.rs b/crates/ui-panels/src/docking/iconic/trials.rs index ce509305da..35cec1d12d 100644 --- a/crates/ui-panels/src/docking/iconic/trials.rs +++ b/crates/ui-panels/src/docking/iconic/trials.rs @@ -727,3 +727,47 @@ fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() { fixture.release_at(icon.center() + Vec2::new(RAIL * 2.0, 0.0)).settle(); } } + +/// The surface shapes painted around the open flyout of a column that is `framed` (a flush dock's): the rects whose +/// rect holds the flyout's body. +fn flyout_surfaces(framed: bool) -> Vec { + let shown: Rc>> = Rc::default(); + let seen = Rc::clone(&shown); + let mut fixture = Fixture::new(move |ui| { + let column = Column::new(vec![Group::new(vec![0, 1], 0)]); + let mut open = Some(0_u8); + IconicColumn::new("Panels", global("iconic column", "docked flyout"), &column, Bind::bound(&mut open), &spec).framed(framed).show_flyouts( + ui, + |_, at, ui, _| { + let GroupAt::Show(rect) = at else { return None }; + seen.set(Some(rect)); + Panel::new("Flyout").show_at(ui, rect, |_, _| ()); + None + }, + ); + }); + fixture.room(Vec2::new(RAIL, 300.0)).settle(); + let body = shown.get().expect("the flyout shows"); + fixture + .frame_shapes() + .into_iter() + .filter_map(|shape| match shape { + egui::Shape::Rect(rect) if rect.rect.expand(EPS).contains_rect(body) && rect.rect.width() < body.width() + RAIL => Some(rect), + _ => None, + }) + .collect() +} + +/// The flyout of a flush dock's column (`DockConfig::flush_docks`, VectorCraft's) stands as a docked column does: +/// square, with no shadow; a column of another dock opens a raised popup with rounded corners. +#[trial] +fn a_flush_docks_flyout_stands_square_with_no_shadow() { + let raised = flyout_surfaces(false); + assert!(raised.iter().any(|rect| rect.corner_radius != egui::CornerRadius::ZERO), "the popup flyout is rounded: {raised:?}"); + let docked = flyout_surfaces(true); + assert!(!docked.is_empty(), "the docked flyout paints its surface"); + for rect in &docked { + assert_eq!(rect.corner_radius, egui::CornerRadius::ZERO, "the docked flyout's surface is square: {rect:?}"); + assert!(rect.blur_width <= 0.0, "the docked flyout casts no shadow: {rect:?}"); + } +}