diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index 9ad29c1e5..80a8b4a76 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -8,7 +8,7 @@ use super::words::DockWords; use super::{PanelDrag, PanelKey, PanelTitle}; use crate::buttons::IconButton; use crate::contract::{ - Access, BodyCx, Common, Component, Container, ContainerProps, ContextMenuRequest, Cx, HeaderEdge, HeaderParts, HeaderRegion, ListDrag, MeasureCx, + Access, Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, ContextMenuRequest, Cx, HeaderEdge, HeaderParts, HeaderRegion, ListDrag, MeasureCx, Name, Outcome, OverlayUi, Overlays as _, PaintUi, PartsCx, Pointer as _, PopupKind, Props as _, Role, ShowCollection as _, ShowContainer as _, Sizing, WordSetCx as _, }; @@ -220,6 +220,8 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> { /// Only the header shows; the body and its drop spots are left out. #[prop(flag)] minimized: bool, + /// The open state the body step reads: closed while minimized, so no body runs. + open: Bind<'a, bool>, /// The grip drags the group. #[prop] movable: bool, @@ -266,6 +268,7 @@ impl<'a, P: Clone + Hash + Send + Sync + 'static> DockGroup<'a, P> { panels, active, minimized: false, + open: Bind::given(true), movable: true, closable: false, wheel_selects_tabs: false, @@ -409,6 +412,12 @@ impl Component for DockGroup<'_, P> { } impl Container for DockGroup<'_, P> { + /// Closed while minimized: the body step runs the header alone, and the body leaves no node, shape or stop. + fn open(&mut self) -> Option> { + self.open = Bind::given(!self.minimized); + Some(self.open.reborrow()) + } + /// The drag band, then the panel menu button when it shows, at the header's end edge. fn header_parts(&self, cx: &MeasureCx<'_, Self>) -> HeaderParts { let band = grip_width(cx.tokens); diff --git a/crates/ui-panels/tests/it/dock_group.rs b/crates/ui-panels/tests/it/dock_group.rs new file mode 100644 index 000000000..7ad349b83 --- /dev/null +++ b/crates/ui-panels/tests/it/dock_group.rs @@ -0,0 +1,35 @@ +//! A docked panel group. + +use craft_ui::buttons::Button; +use craft_ui::contract::{Show as _, ShowContainer as _}; +use craft_ui::docking::{DockGroup, PanelKey, PanelTitle}; +use craft_ui::testing::{Fixture, trial}; +use egui::{Pos2, Rect, Vec2}; +use std::cell::Cell; +use std::rc::Rc; + +// A minimized group shows its header alone: its body does not run, so it leaves no node and nothing a press could +// reach under the groups below it. Expanded, the same body shows. +#[trial] +fn a_minimized_group_runs_no_body() { + let body = |minimized: bool| { + let runs = Rc::new(Cell::new(0)); + let counted = Rc::clone(&runs); + let panels = vec![PanelTitle::new(PanelKey::new(1), "Color")]; + let mut fixture = Fixture::new(move |ui| { + let group = DockGroup::new(1usize, &panels, panels[0].key); + let group = if minimized { group.minimized() } else { group }; + let counted = Rc::clone(&counted); + group.show_at(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(240.0, 200.0)), move |ui, _| { + counted.set(counted.get() + 1); + Button::new("Body button").show(ui); + }); + }); + fixture.idle(4); + let found = fixture.by_label("Body button").is_some(); + (runs.get(), found) + }; + let (runs, found) = body(false); + assert!(runs > 0 && found, "an expanded group shows its body: {runs} runs, node {found}"); + assert_eq!(body(true), (0, false), "a minimized group runs no body and leaves no node"); +} diff --git a/crates/ui-panels/tests/it/main.rs b/crates/ui-panels/tests/it/main.rs index ba3b1d0fb..1a8ff8e60 100644 --- a/crates/ui-panels/tests/it/main.rs +++ b/crates/ui-panels/tests/it/main.rs @@ -6,6 +6,7 @@ extern crate craft_ui_panels as craft_ui; mod access; pub(crate) mod body; mod dialogs; +mod dock_group; // outer edit mod edit; // end of outer edit