A minimized dock group is closed: the body step runs its header alone, and its body leaves no node or hit record

This commit is contained in:
aiongg
2026-11-17 04:29:30 +00:00
parent 33b48b72a7
commit f34f115a9a
3 changed files with 46 additions and 1 deletions
+10 -1
View File
@@ -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<P: Clone + Hash + Send + Sync + 'static> Component for DockGroup<'_, P> {
}
impl<P: Clone + Hash + Send + Sync + 'static> 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<BindMut<'_, bool>> {
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);
+35
View File
@@ -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");
}
+1
View File
@@ -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