diff --git a/crates/ui-panels/src/docking/config.rs b/crates/ui-panels/src/docking/config.rs
index 51c0a8886..5256837eb 100644
--- a/crates/ui-panels/src/docking/config.rs
+++ b/crates/ui-panels/src/docking/config.rs
@@ -38,7 +38,7 @@ impl DockSides {
/// How a dock behaves. The sizes of its drop bands and zones are `DockSizes`; the
/// look is the dock's style; the words are `DockWords`.
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct DockConfig {
/// The picture-frame profile: a group's side zones are `DockSizes::zone_depth` deep and the outer edge band
diff --git a/crates/ui-panels/src/docking/panels.rs b/crates/ui-panels/src/docking/panels.rs
index 1e17eb818..651924e42 100644
--- a/crates/ui-panels/src/docking/panels.rs
+++ b/crates/ui-panels/src/docking/panels.rs
@@ -16,8 +16,8 @@ use egui::{Context, Id, Ui};
/// 2. Otherwise `group_header` once, inside the group's header region before its tab strip, then `spec` for each of
/// its panels, then `body` for the panels whose bodies are shown. `panel_rows` runs when a panel's menu opens.
///
-/// A panel's `spec` is read every pass, so a host may change a label or a limit between passes. The dock's actions
-/// name a group by one of its panels.
+/// A panel's `spec` is read every pass, so a host may change a label or a limit between passes; a host whose chrome
+/// settles (`spec_version`) changes that version with it. The dock's actions name a group by one of its panels.
pub trait DockPanels
{
/// What the dock reads of `panel`.
fn spec(&self, panel: &P) -> PanelSpec;
@@ -42,6 +42,16 @@ pub trait DockPanels
{
None
}
+ /// The version of what the dock's chrome shows of the host's panels: every panel's `spec` (its name, icon and
+ /// limits), its `permissions` and what `group_header` shows. With one, each group's header and tab strip and each
+ /// column's bar settle (`Lazy::settles` with `Lazy::content`): they run only when this version, the arrangement,
+ /// their room or something the framework tracks in them changed, the pointer is over them or focus is in them, and
+ /// otherwise repaint their last run. A group settles only when its shown panel's body has a [`content`](Self::content)
+ /// version too. `None` (the default) runs the chrome every pass.
+ fn spec_version(&self) -> Option {
+ None
+ }
+
/// Takes the group holding `panels`, whose tab `active` is selected, in place of its tab strip and body: at
/// `GroupAt::Show(rect)` it shows its view in `ui`, which the dock holds to `rect` and clips to it; at
/// `GroupAt::Measure(width)` it measures that view at `width` the way it shows it. It returns the height the view
diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs
index 316b7e358..a860ab816 100644
--- a/crates/ui-patterns/src/patterns/dock/area.rs
+++ b/crates/ui-patterns/src/patterns/dock/area.rs
@@ -16,7 +16,7 @@ use crate::docking::{
frame, move_actions, stepped, with_area_rules,
};
use crate::menu::{GroupItem, MenuWords, PanelMenu, PanelRow};
-use crate::runtime::commands::{CommandRef, CommandSet as _, Commands as _, focus_within};
+use crate::runtime::commands::{CommandRef, CommandSet as _, CommandState, Commands as _, focus_within};
use crate::runtime::drag;
use crate::runtime::env::{Env, Label, RevealEdge, ShellCx, ShellEntry};
use crate::runtime::memory::Remember as _;
@@ -29,7 +29,7 @@ use craft_behavior::overlay::Side;
use craft_behavior::{CancelReason, DockSide, EditEvent, EditEvents, Flow, GestureId, GesturePhase, Mixed, Proposal};
use craft_host::target::WindowKind;
use egui::{Context, Id, Pos2, Rect, Response, Ui, UiBuilder, Vec2, ViewportId};
-use std::cell::{Cell, RefCell};
+use std::cell::{Cell, OnceCell, RefCell};
use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::Hash;
@@ -247,6 +247,9 @@ struct Scene<'s, P> {
rtl: bool,
/// The docked places floating panels left, for Dock Panel.
floated: &'s [(P, Location)],
+ /// The key of what every region of the chrome shows of the pass beyond its own room ([`chrome_key`]); `None` when
+ /// the host gives no [`DockPanels::spec_version`], and the chrome runs every pass.
+ chrome: Option,
}
/// The spec of `panel` in `specs`, or an unnamed one.
@@ -293,6 +296,15 @@ struct Look {
in_window: bool,
}
+/// What a group's header shows besides its panels' bodies: the tab titles, the panel menu's rows and whether the host
+/// gave any, and the panel commands' states.
+struct GroupParts {
+ titles: Vec,
+ menu: Vec,
+ hosted: bool,
+ states: Vec<(DockCommands, CommandState)>,
+}
+
/// A dock to show: its window edge, its columns and its rect.
struct DockPlan<'p, P> {
edge: DockEdge,
@@ -398,6 +410,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
hide,
maximized: maximized.as_ref(),
auto_collapse,
+ locked,
sizes,
rtl,
};
@@ -496,6 +509,7 @@ struct Input<'i, P> {
hide: HidePanels<'i, P>,
maximized: Option<&'i P>,
auto_collapse: bool,
+ locked: bool,
sizes: DockSizes,
rtl: bool,
}
@@ -522,7 +536,7 @@ fn show_area(
panels: &mut dyn DockPanels,
mut flyout: Option<&mut Bind<'_, Option
>>,
) -> Passed
{
- let Input { id, ctx, current, config, specs, hide, maximized, auto_collapse, sizes, rtl } = *input;
+ let Input { id, ctx, current, config, specs, hide, maximized, auto_collapse, locked, sizes, rtl } = *input;
let shell = body.shell();
let mut memory = body.memory::>().clone();
let keys: HashMap = current.layout.panels().into_iter().map(|panel| (PanelKey::of(panel), panel.clone())).collect();
@@ -531,6 +545,7 @@ fn show_area(
let layout: &Layout = &view.layout;
let bounds = shell.as_ref().map_or(body.rect, ShellCx::float_bounds);
let space = float_space(bounds, &sizes, config, specs);
+ let chrome = panels.spec_version().map(|version| chrome_key(layout, version, config, locked, auto_collapse));
let scene = Scene {
dock: id,
sizes,
@@ -544,6 +559,7 @@ fn show_area(
auto_collapse,
rtl,
floated: ¤t.floated,
+ chrome,
};
let open = open_of(&mut flyout, body, &memory);
let mut pass = Pass {
@@ -692,6 +708,94 @@ fn float_space(bounds: Rect, sizes: &DockSizes, config: &D
space
}
+/// The rows of the menu of `panel`'s group, and whether the host gave any (only then does the group show a menu
+/// button; a context request opens the menu either way): the host's rows, then the panel commands the config shows, with
+/// the Move Panel To submenu of the groups the panel can move to.
+fn panel_menu_rows(
+ scene: &Scene<'_, P>,
+ panels: &mut dyn DockPanels,
+ words: &MenuWords,
+ panel: &P,
+) -> (Vec, bool) {
+ let config = scene.config;
+ let command = |command: DockCommands| PanelRow::Command(CommandRef::from(command));
+ let floating = matches!(scene.layout.place(panel), Some(PanelPlace::Floating { .. }));
+ let mut group = vec![command(DockCommands::FloatPanel)];
+ if floating {
+ group.push(command(DockCommands::DockPanel));
+ }
+ let targets = scene.layout.move_targets(panel, |other| scene.permissions(other));
+ if scene.permissions(panel).movable && !targets.is_empty() {
+ let rows = targets.iter().enumerate().map(|(at, target)| PanelRow::Item(Entry::new(GroupItem::MoveTo(at), scene.spec(target).label)));
+ let name = Label::from(words.panel_move_to.as_str().to_owned());
+ group.push(PanelRow::Submenu(name, rows.collect()));
+ }
+ if config.close_menu_items {
+ group.extend([command(DockCommands::ClosePanel), command(DockCommands::CloseGroup)]);
+ }
+ if config.group_order_items && matches!(scene.layout.place(panel), Some(PanelPlace::Dock { .. })) {
+ group.extend([command(DockCommands::ToggleMinimized), command(DockCommands::StepGroupUp), command(DockCommands::StepGroupDown)]);
+ }
+ group.push(command(DockCommands::FloatGroup));
+ if config.close_others_item {
+ group.push(command(DockCommands::CloseOthers));
+ }
+ if config.maximize_item {
+ group.push(command(DockCommands::ToggleMaximize));
+ }
+ let mut rows = panels.panel_rows(panel);
+ let hosted = !rows.is_empty();
+ if hosted {
+ rows.push(PanelRow::Separator);
+ }
+ rows.extend(group);
+ (rows, hosted)
+}
+
+/// The key of what the chrome's regions show beyond their own room: the host's panel specs (`version`), the config,
+/// whether the workspace is locked, Auto-Collapse, and the shown arrangement: which panels each group, column and
+/// floating window holds, the shown tab, and the minimized, open, iconic and stepped states, which the panel menus'
+/// command states and move targets read across groups. Sizes are left out: a size reaches a region as its room.
+fn chrome_key(layout: &Layout, version: u64, config: &DockConfig, locked: bool, auto_collapse: bool) -> u64 {
+ use std::hash::Hasher;
+ fn column(column: &Column, hasher: &mut impl Hasher) {
+ (column.iconic, column.steps, column.groups.len()).hash(hasher);
+ for group in &column.groups {
+ (&group.panels, group.active, group.minimized).hash(hasher);
+ }
+ }
+ fn node(node: &Node, hasher: &mut impl Hasher) {
+ std::mem::discriminant(node).hash(hasher);
+ match node {
+ Node::Split { first, second, .. } => {
+ node(first, hasher);
+ node(second, hasher);
+ }
+ Node::Tabs { panels, active, .. } => (panels, active).hash(hasher),
+ Node::Stack { entries, .. } => {
+ for entry in entries {
+ (&entry.panel, entry.open).hash(hasher);
+ }
+ }
+ Node::Dock { side, columns, .. } => {
+ side.hash(hasher);
+ columns.iter().for_each(|one| column(one, hasher));
+ }
+ _ => {}
+ }
+ }
+ let mut hasher = std::collections::hash_map::DefaultHasher::new();
+ (version, config, locked, auto_collapse).hash(&mut hasher);
+ if let Some(root) = &layout.root {
+ node(root, &mut hasher);
+ }
+ for window in &layout.floating {
+ (window.id, window.edge).hash(&mut hasher);
+ column(&window.column, &mut hasher);
+ }
+ hasher.finish()
+}
+
/// Whether `spec` is a document's: its group shows its body edge to edge. Every other docked body fills its group's
/// body, inset from its edges by the panel padding: the group is the body's panel and its tab the body's title, so a
/// docked body pads and frames nothing itself.
@@ -735,44 +839,9 @@ impl Pass<'_, P> {
}
}
- /// The rows of the menu of `panel`'s group, and whether the host gave any (only then does the group show a menu
- /// button; a context request opens the menu either way): the host's rows, then the panel commands the config shows, with
- /// the Move Panel To submenu of the groups the panel can move to.
+ /// The rows of the menu of `panel`'s group, and whether the host gave any ([`panel_menu_rows`]).
fn menu_rows(&mut self, body: &BodyCx<'_>, panel: &P) -> (Vec, bool) {
- let scene = self.scene;
- let config = scene.config;
- let command = |command: DockCommands| PanelRow::Command(CommandRef::from(command));
- let floating = matches!(scene.layout.place(panel), Some(PanelPlace::Floating { .. }));
- let mut group = vec![command(DockCommands::FloatPanel)];
- if floating {
- group.push(command(DockCommands::DockPanel));
- }
- let targets = scene.layout.move_targets(panel, |other| scene.permissions(other));
- if scene.permissions(panel).movable && !targets.is_empty() {
- let rows = targets.iter().enumerate().map(|(at, target)| PanelRow::Item(Entry::new(GroupItem::MoveTo(at), scene.spec(target).label)));
- let name = Label::from(body.words::().panel_move_to.as_str().to_owned());
- group.push(PanelRow::Submenu(name, rows.collect()));
- }
- if config.close_menu_items {
- group.extend([command(DockCommands::ClosePanel), command(DockCommands::CloseGroup)]);
- }
- if config.group_order_items && matches!(scene.layout.place(panel), Some(PanelPlace::Dock { .. })) {
- group.extend([command(DockCommands::ToggleMinimized), command(DockCommands::StepGroupUp), command(DockCommands::StepGroupDown)]);
- }
- group.push(command(DockCommands::FloatGroup));
- if config.close_others_item {
- group.push(command(DockCommands::CloseOthers));
- }
- if config.maximize_item {
- group.push(command(DockCommands::ToggleMaximize));
- }
- let mut rows = self.panels.panel_rows(panel);
- let hosted = !rows.is_empty();
- if hosted {
- rows.push(PanelRow::Separator);
- }
- rows.extend(group);
- (rows, hosted)
+ panel_menu_rows(self.scene, &mut *self.panels, &body.words::(), panel)
}
/// Runs a panel command on `panel`: the event of a command the host carries out, else its actions. `source` is
@@ -836,25 +905,42 @@ impl Pass<'_, P> {
if let Some(height) = viewed {
return matches!(at, GroupAt::Measure(_)).then_some(height);
}
- let titles: Vec = members
- .iter()
- .map(|panel| PanelTitle::new(PanelKey::of(panel), scene.spec(panel).label).closable(scene.permissions(panel).closable))
- .collect();
let shown = &members[active];
- let (menu, hosted) = self.menu_rows(body, shown);
- let permissions = |panel: &P| scene.permissions(panel);
- let states = dock_states(&DockScene::new(scene.layout, scene.space, false, &permissions).floated(scene.floated), shown);
+ // The group settles when the host versions its specs and the shown body: it runs again when the pass's chrome
+ // key, the body's version or how the group shows changes.
+ let version = scene.chrome.zip(self.panels.content(shown)).map(|(chrome, content)| {
+ use std::hash::Hasher;
+ let mut hasher = std::collections::hash_map::DefaultHasher::new();
+ (chrome, content, members, active, look.minimized, look.section, look.in_window).hash(&mut hasher);
+ hasher.finish()
+ });
+ let words = body.words::();
let panels = RefCell::new(&mut *self.panels);
+ // The tab titles, the menu rows and the panel commands' states, built when the group runs.
+ let parts: OnceCell = OnceCell::new();
+ let parts_of = || {
+ parts.get_or_init(|| {
+ let titles = members
+ .iter()
+ .map(|panel| PanelTitle::new(PanelKey::of(panel), scene.spec(panel).label).closable(scene.permissions(panel).closable))
+ .collect();
+ let (menu, hosted) = panel_menu_rows(scene, &mut **panels.borrow_mut(), &words, shown);
+ let permissions = |panel: &P| scene.permissions(panel);
+ let states = dock_states(&DockScene::new(scene.layout, scene.space, false, &permissions).floated(scene.floated), shown);
+ GroupParts { titles, menu, hosted, states }
+ })
+ };
// The group with `members[at]` shown: as it shows, or as it is measured.
let make = |at: usize, minimized: bool| {
let panels = &panels;
- let mut group = DockGroup::new(anchor.clone(), &titles, PanelKey::of(&members[at]))
+ let GroupParts { titles, menu, hosted, states } = parts_of();
+ let mut group = DockGroup::new(anchor.clone(), titles, PanelKey::of(&members[at]))
.extra(move |ui, body| panels.borrow_mut().group_header(members, at, ui, body))
.dock(self.dock)
.zones(scene.config.zone_rule())
.movable(scene.permissions(shown).movable)
.menu(menu.clone())
- .panel_menu_shown(hosted)
+ .panel_menu_shown(*hosted)
.command_states(states.clone());
if look.in_window {
group = group.in_window();
@@ -879,7 +965,20 @@ impl Pass<'_, P> {
}
GroupAt::Show(rect) => rect,
};
- let output = make(active, look.minimized).show_at(ui, rect, |ui, body| panel_body(&panels, shown, ui, body)).output;
+ // One child `Ui` held to the group's rect, whether the group settles or not, so its contents keep their ids.
+ let key = ("dock group", PanelKey::of(anchor).0);
+ let lazy = Lazy::new(key, 0.0).settles(version.is_some());
+ let lazy = match version {
+ Some(version) => lazy.content(version),
+ None => lazy,
+ };
+ let output = ui
+ .scope_builder(UiBuilder::new().max_rect(rect).id_salt(key), |ui| {
+ lazy.show(ui, |ui| make(active, look.minimized).show_at(ui, rect, |ui, body| panel_body(&panels, shown, ui, body)).output)
+ })
+ .inner;
+ // A settled group replayed its last run: nothing reached it.
+ let output = output?;
// The size `panel` floats at out of this group: the group's width, and the height the group measures at with
// `panel` shown in a floating window's room, so content that fills the body takes that room.
let fitted = |ui: &Ui, panel: &P| {
@@ -1053,25 +1152,31 @@ impl Pass<'_, P> {
}
let opens = if edge == DockEdge::Start { Side::End } else { Side::Start };
let work = if column.iconic {
- let output = IconicColumn::new(name, dock, column, Bind::given(open), &spec)
+ let mut shown = IconicColumn::new(name, dock, column, Bind::given(open), &spec)
.edge(edge)
.opens(opens)
.bar(bar)
.within(within)
- .auto_collapse(scene.auto_collapse)
- .show_flyouts_at(ui, cell, |group, at, ui, body| self.group_of(ui, body, group, at, in_window));
+ .auto_collapse(scene.auto_collapse);
+ if let Some(chrome) = scene.chrome {
+ shown = shown.content(chrome);
+ }
+ let output = shown.show_flyouts_at(ui, cell, |group, at, ui, body| self.group_of(ui, body, group, at, in_window));
self.report.flyout.extend(output.edit.events);
ColumnWork { iconic: output.iconic, picked: output.picked, resized: Vec::new(), width: output.width, flyout: output.flyout }
} else {
- let output = DockColumn::new(name, dock, column, &spec)
+ let mut shown = DockColumn::new(name, dock, column, &spec)
.edge(edge)
.bar(bar)
.arrow(self.arrow_of(column))
.within(within)
- .auto_collapse(scene.auto_collapse)
- .show_groups_at(ui, cell, |group, rect, ui, body| {
- self.group_of(ui, body, group, GroupAt::Show(rect), in_window);
- });
+ .auto_collapse(scene.auto_collapse);
+ if let Some(chrome) = scene.chrome {
+ shown = shown.content(chrome);
+ }
+ let output = shown.show_groups_at(ui, cell, |group, rect, ui, body| {
+ self.group_of(ui, body, group, GroupAt::Show(rect), in_window);
+ });
ColumnWork { iconic: output.iconic, picked: output.picked, resized: output.resized, width: output.width, flyout: None }
};
self.column_work(column, work);