Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Docking trial: one dock path, ui.docking, localized dock labels

aiongg5f5b6164c264
diff --git a/Cargo.lock b/Cargo.lock
index 7e9ae36d8..1e77d5344 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -849,7 +849,7 @@ dependencies = [
[[package]]
name = "craft-ui"
version = "0.1.0"
-source = "git+https://github.com/aiongg/craft-libs?rev=4bf11647adb05e1b6f5a49c1ae5f7105bf746c71#4bf11647adb05e1b6f5a49c1ae5f7105bf746c71"
+source = "git+https://github.com/aiongg/craft-libs?rev=c94ab4d313832ea9a84da721a6d3e7a7838dacef#c94ab4d313832ea9a84da721a6d3e7a7838dacef"
dependencies = [
"egui",
"serde",
diff --git a/Cargo.toml b/Cargo.toml
index 8f169d311..9ecd08b25 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -126,4 +126,4 @@ hayro-jbig2 = { git = "https://github.com/storytold/pdfcraft", rev = "b5467d93a0
# Docking trial: craft-ui from the craft-libs `docking` branch.
[patch."https://github.com/storytold/craft-libs"]
-craft-ui = { git = "https://github.com/aiongg/craft-libs", rev = "4bf11647adb05e1b6f5a49c1ae5f7105bf746c71" }
+craft-ui = { git = "https://github.com/aiongg/craft-libs", rev = "c94ab4d313832ea9a84da721a6d3e7a7838dacef" }
diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs
index 0df5361f9..1f865a3dc 100644
--- a/crates/ui-egui/src/chrome.rs
+++ b/crates/ui-egui/src/chrome.rs
@@ -1250,15 +1250,15 @@ mod tests {
h.run_steps(3);
h.get_by_label("Preflight Panel…").click();
h.run_steps(3);
- // Preflight is not a dock tab: `window.panel` shows it as its own panel.
- assert_eq!(h.state().app.ui.open_panel.as_deref(), Some("preflight"));
+ // Preflight is in the iconic column: `window.panel` shows it.
+ assert!(crate::panel_docking::showing(&h.state().app, "preflight"));
h.get_by_label("Preflight");
// With the panel already showing, the entry keeps it open.
h.get_by_label("No errors ▾").click();
h.run_steps(3);
h.get_by_label("Preflight Panel…").click();
h.run_steps(3);
- assert_eq!(h.state().app.ui.open_panel.as_deref(), Some("preflight"));
+ assert!(crate::panel_docking::showing(&h.state().app, "preflight"));
}
/// As in InDesign, double-clicking the preflight count (or its light) shows the panel.
@@ -1272,7 +1272,7 @@ mod tests {
count.click();
count.click();
h.run_steps(3);
- assert_eq!(h.state().app.ui.open_panel.as_deref(), Some("preflight"));
+ assert!(crate::panel_docking::showing(&h.state().app, "preflight"));
h.get_by_label("Preflight");
assert!(h.query_by_label("Preflight Panel…").is_none(), "the menu isn't left open");
// A double-click with the panel already showing keeps it open.
@@ -1280,7 +1280,7 @@ mod tests {
count.click();
count.click();
h.run_steps(3);
- assert_eq!(h.state().app.ui.open_panel.as_deref(), Some("preflight"));
+ assert!(crate::panel_docking::showing(&h.state().app, "preflight"));
}
/// A very long document name made its tab grow past the window, hiding the close button
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs
index 1cb7395c0..ea81c278e 100644
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@ -4,6 +4,7 @@
//! - `engine.execute {command, params}` / `ui.menu.invoke {command|id, params}`: run any command
//! - `engine.commands`: engine + UI commands with enablement
//! - `document.inspect`: document summary; `ui.inspect`: UI state
+//! - `ui.docking`: the panel layout in use and the focused panel
//! - `ui.menu.list`: flattened menu tree
//! - `ui.tool.select {tool}`, `ui.tool.list`
//! - `ui.pointer {events:[{kind: down|drag|up|move|doubleclick, x, y, space?: "doc"|"screen"}], mods?}`:
@@ -77,6 +78,7 @@ pub fn inspect(app: &DesignApp, ctx: &egui::Context) -> Value {
"ui": serde_json::to_value(&app.ui).unwrap_or_default(),
"view": app.view().map(|v| serde_json::to_value(v).unwrap_or_default()),
"canvasRect": app.canvas_rect.map(|c| json!([c.left(), c.top(), c.width(), c.height()])),
+ "docking": crate::panel_docking::inspect(app),
"window": [r.width(), r.height()],
"documents": app
.session
@@ -169,6 +171,7 @@ fn handle_request(app: &mut DesignApp, ctx: &egui::Context, req: &ControlRequest
"engine.commands" => ok(all_commands(app)),
"document.inspect" => wrap(app.run("document.inspect", json!({}))),
"ui.inspect" => ok(inspect(app, ctx)),
+ "ui.docking" => ok(crate::panel_docking::inspect(app)),
"ui.menu.list" => ok(serde_json::to_value(menus::MENUS).unwrap_or_default()),
"ui.tool.select" => wrap(app.run("tool.select", json!({"tool": s("tool").unwrap_or("")}))),
"ui.tool.list" => ok(serde_json::to_value(designcraft_tools::TOOL_GROUPS).unwrap_or_default()),
@@ -361,7 +364,7 @@ fn handle_request(app: &mut DesignApp, ctx: &egui::Context, req: &ControlRequest
r = crate::panel_docking::close_visible(app).map(|_| Value::Null);
}
if let Some(v) = p.get("dockExpanded").and_then(Value::as_bool) {
- app.ui.dock_expanded = v;
+ r = crate::panel_docking::set_iconic(app, !v);
}
wrap(r)
}
diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs
index fb9a7cf17..a825e3502 100644
--- a/crates/ui-egui/src/dock.rs
+++ b/crates/ui-egui/src/dock.rs
@@ -58,10 +58,8 @@ pub fn panel_label(id: &str) -> &'static str {
DOCK_TABS.iter().chain(ICON_PANELS).map(|p| (p.0, p.1)).chain(FLOATING_PANELS.iter().copied()).find(|p| p.0 == id).map_or("Panel", |p| p.1)
}
+/// The classic dock, replaced by the docking layout (`panel_docking::show`) and no longer drawn.
pub fn show(app: &mut DesignApp, ui: &mut egui::Ui) {
- if crate::panel_docking::show(app, ui) {
- return;
- }
let t = Tokens::get(ui.ctx());
// Expanded panel stack (outermost, 253 pt) — declared first so it sits at the far right.
if app.ui.dock_expanded {
@@ -331,7 +329,7 @@ pub fn float_panel(app: &mut DesignApp, id: &str, at: egui::Pos2) {
/// Put a floating panel back in the dock's icon column.
pub fn dock_panel(app: &mut DesignApp, id: &str) {
- if app.ui.docking.is_some() && !float_only(id) {
+ if !float_only(id) {
if let Some(Err(error)) = crate::panel_docking::command(app, "window.panel.dock", &serde_json::json!({"panel":id})) {
app.status(error);
}
@@ -342,11 +340,10 @@ pub fn dock_panel(app: &mut DesignApp, id: &str) {
/// Floating panels: movable, resizable windows; "Dock" returns one to the icon column.
pub fn floating(app: &mut DesignApp, ctx: &egui::Context) {
- // A customized layout draws its own floating groups; float-only panels are drawn here.
- let customized = app.ui.docking.is_some();
+ // The docking layout draws its own floating groups; float-only panels are drawn here.
let t = Tokens::get(ctx);
for (id, at) in app.ui.floating.clone() {
- if customized && !float_only(&id) {
+ if !float_only(&id) {
continue;
}
let label = crate::i18n::tr(&app.ui.language, panel_label(&id)).to_owned();
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index fcb764c5a..0a76e123c 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -259,11 +259,15 @@ pub struct UiState {
pub open_panel: Option<String>,
/// Panels torn off the dock into their own floating windows: (panel id, top-left position).
pub floating: Vec<(String, [f32; 2])>,
- /// Shared panel layout after the user customizes the legacy dock.
+ /// The panel layout once the user customizes it; `None` is the workspace's default layout
+ /// (`panel_docking::default_layout`).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub docking: Option<craft_ui::docking::Layout<String>>,
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub docking_hidden: std::collections::BTreeMap<String, craft_ui::docking::Location<String>>,
+ /// The panel (or the canvas) last clicked or selected in the docking layout.
+ #[serde(skip)]
+ pub docking_focused: Option<String>,
/// Invalidates in-flight gestures when a workspace is replaced.
#[serde(skip)]
pub docking_generation: u64,
@@ -404,6 +408,7 @@ impl Default for UiState {
docking_generation: 0,
docking_raise: None,
docking_opened: None,
+ docking_focused: None,
dock_expanded: true,
icon_groups: None,
units: Unit::Picas,
@@ -1488,6 +1493,63 @@ impl DesignApp {
raw.events.extend(events.drain(..n));
}
+ /// The document area: the start screen, or the document tabs over one or two canvas panes.
+ pub(crate) fn canvas_area(&mut self, ui: &mut egui::Ui, presenting: bool) {
+ let t = theme::Tokens::get(ui.ctx());
+ if self.session.active().is_none() {
+ chrome::start_screen(self, ui);
+ return;
+ }
+ if !presenting {
+ chrome::doc_tabs(self, ui);
+ }
+ let split_layout = (self.split && !presenting)
+ .then(|| {
+ craft_ui::layout::split_rect(
+ ui.available_rect_before_wrap(),
+ craft_ui::layout::SplitAxis::Horizontal,
+ craft_ui::layout::SplitSize::Ratio(0.5),
+ 2.0,
+ 0.0,
+ )
+ })
+ .flatten();
+ if let Some(layout) = split_layout {
+ // Two panes with a divider; each has its own view (zoom, scroll) and render cache.
+ ui.painter().rect_filled(layout.divider, 0.0, t.border);
+ // Resolve the clicked pane before either canvas handles this frame's keys.
+ if let Some(p) = ui.input(|i| i.pointer.any_pressed().then(|| i.pointer.interact_pos()).flatten()) {
+ if layout.first.contains(p) {
+ self.focus_pane = 0;
+ } else if layout.second.contains(p) {
+ self.focus_pane = 1;
+ }
+ }
+ for (k, half) in [layout.first, layout.second].into_iter().enumerate() {
+ self.switch_pane(k as u8);
+ // A new pane starts at the other pane's view.
+ if k == 1 && self.view().is_none() {
+ self.switch_pane(0);
+ let v = self.view().copied();
+ self.switch_pane(1);
+ if let (Some(mut v), Some(m)) = (v, self.view_mut()) {
+ v.fitted = false;
+ *m = v;
+ }
+ }
+ ui.scope_builder(egui::UiBuilder::new().max_rect(half), |ui| canvas::show(self, ui));
+ }
+ self.switch_pane(self.focus_pane);
+ } else {
+ self.switch_pane(0);
+ // With a second window, the main one takes the focus back when clicked.
+ if !self.second_window || (ui.input(|i| i.pointer.any_pressed()) && ui.ui_contains_pointer()) {
+ self.focus_pane = 0;
+ }
+ canvas::show(self, ui);
+ }
+ }
+
/// Lay out the whole window.
pub fn ui(&mut self, ui: &mut egui::Ui) {
let ctx = ui.ctx().clone();
@@ -1523,62 +1585,13 @@ impl DesignApp {
if self.ui.hidden_panels != 1 {
toolbar::show(self, ui);
}
- if self.ui.hidden_panels == 0 {
- dock::show(self, ui);
- }
}
egui::CentralPanel::default().frame(egui::Frame::NONE.fill(t.pasteboard)).show(ui, |ui| {
- if self.session.active().is_none() {
- chrome::start_screen(self, ui);
- return;
- }
- if !presenting {
- chrome::doc_tabs(self, ui);
- }
- let split_layout = (self.split && !presenting)
- .then(|| {
- craft_ui::layout::split_rect(
- ui.available_rect_before_wrap(),
- craft_ui::layout::SplitAxis::Horizontal,
- craft_ui::layout::SplitSize::Ratio(0.5),
- 2.0,
- 0.0,
- )
- })
- .flatten();
- if let Some(layout) = split_layout {
- // Two panes with a divider; each has its own view (zoom, scroll) and render cache.
- ui.painter().rect_filled(layout.divider, 0.0, t.border);
- // Resolve the clicked pane before either canvas handles this frame's keys.
- if let Some(p) = ui.input(|i| i.pointer.any_pressed().then(|| i.pointer.interact_pos()).flatten()) {
- if layout.first.contains(p) {
- self.focus_pane = 0;
- } else if layout.second.contains(p) {
- self.focus_pane = 1;
- }
- }
- for (k, half) in [layout.first, layout.second].into_iter().enumerate() {
- self.switch_pane(k as u8);
- // A new pane starts at the other pane's view.
- if k == 1 && self.view().is_none() {
- self.switch_pane(0);
- let v = self.view().copied();
- self.switch_pane(1);
- if let (Some(mut v), Some(m)) = (v, self.view_mut()) {
- v.fitted = false;
- *m = v;
- }
- }
- ui.scope_builder(egui::UiBuilder::new().max_rect(half), |ui| canvas::show(self, ui));
- }
- self.switch_pane(self.focus_pane);
+ // The panel layout holds the canvas as its protected `canvas` panel.
+ if presenting || self.ui.hidden_panels != 0 {
+ self.canvas_area(ui, presenting);
} else {
- self.switch_pane(0);
- // With a second window, the main one takes the focus back when clicked.
- if !self.second_window || (ui.input(|i| i.pointer.any_pressed()) && ui.ui_contains_pointer()) {
- self.focus_pane = 0;
- }
- canvas::show(self, ui);
+ panel_docking::show(self, ui);
}
});
// New Window: pane 1 in a window of its own.
@@ -1618,7 +1631,6 @@ impl DesignApp {
}
// Tab, Shift+Tab and Presentation hide the floating panels with the docked ones.
if !presenting && self.ui.hidden_panels == 0 {
- dock::flyout(self, &ctx);
dock::floating(self, &ctx);
}
story_editor::show(self, &ctx);
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 382e259af..3558be93a 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -1826,11 +1826,6 @@ fn run_ui_inner(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Value
Ok(json!({"url": url}))
}
"window.toolsDoubleColumn" => flag(&mut app.ui.tools_double_column),
- "window.collapseToIcons" => {
- app.ui.dock_expanded = false;
- app.ui.open_panel = None;
- Ok(Value::Null)
- }
"window.newWorkspace" => {
let Some(name) = p.get("name").and_then(Value::as_str).map(str::trim).filter(|n| !n.is_empty()) else {
app.ui.dialog =
@@ -4003,8 +3998,9 @@ mod tests {
out.textures_delta.clear();
}
};
- // The icon column's flyout (the classic dock) and a floating panel group (the docking layout).
- let flyout = egui::LayerId::new(egui::Order::Foreground, egui::Id::new("panel_flyout"));
+ // The docked panel's tab and a floating panel group.
+ let tab = egui::Id::new("designcraft-panel-docking").with(("tab", &"preflight".to_string()));
+ let docked = || ctx.read_response(tab).is_some();
let group = egui::LayerId::new(egui::Order::Middle, egui::Id::new("designcraft-panel-docking").with(("floating", "preflight")));
let shown = |layer: egui::LayerId| ctx.memory(|m| m.areas().is_visible(&layer));
let toggles = [
@@ -4014,14 +4010,14 @@ mod tests {
];
app.run("window.panel", json!({"panel": "preflight"})).unwrap();
frame(&mut app);
- assert!(app.ui.docking.is_none() && shown(flyout));
+ assert!(docked());
for (id, hide, show) in &toggles {
app.run(id, hide.clone()).unwrap();
frame(&mut app);
- assert!(!shown(flyout), "{id} hides the flyout");
+ assert!(!docked(), "{id} hides the dock");
app.run(id, show.clone()).unwrap();
frame(&mut app);
- assert!(shown(flyout), "{id} again brings it back");
+ assert!(docked(), "{id} again brings it back");
}
app.run("window.floatPanel", json!({"panel": "preflight", "x": 400, "y": 200})).unwrap();
frame(&mut app);
@@ -5055,7 +5051,7 @@ mod tests {
let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
activate(&mut app, "app.characterPanel", &Value::Null);
- assert_eq!(app.ui.open_panel.as_deref(), Some("character"));
+ assert!(crate::panel_docking::showing(&app, "character"));
// Paragraph Styles opens floating, grouped with Character Styles, as in InDesign.
activate(&mut app, "app.paragraphStylesPanel", &Value::Null);
let layout = app.ui.docking.as_ref().unwrap();
@@ -5132,7 +5128,10 @@ mod tests {
assert_eq!(checked(&app, "window.workspace", &json!({"name": "Essentials"})), Some(false));
// Window › Pages opens Pages from its icon group, not the Properties stack.
run_ui(&mut app, "window.panel", &json!({"panel": "pages"})).unwrap().unwrap();
- assert_eq!((app.ui.open_panel.as_deref(), app.ui.dock_expanded), (Some("pages"), false));
+ assert!(crate::panel_docking::showing(&app, "pages"));
+ let layout = app.ui.docking.clone().unwrap();
+ assert!(!layout.contains(&"properties".to_string()));
+ assert_eq!(crate::panel_docking::tab_group(&layout, "pages"), ["pages", "layers", "links"]);
// A workspace saved from it keeps the groups.
run_ui(&mut app, "window.newWorkspace", &json!({"name": "Mine"})).unwrap().unwrap();
run_ui(&mut app, "window.workspace", &json!({"name": "Essentials"})).unwrap().unwrap();
@@ -5154,8 +5153,8 @@ mod tests {
assert_eq!(groups[5], ["character", "characterStyles"]);
for panel in ["pages", "paragraphStyles", "characterStyles"] {
run_ui(&mut app, "window.panel", &json!({"panel":panel})).unwrap().unwrap();
- assert_eq!(app.ui.open_panel.as_deref(), Some(panel));
- assert!(!app.ui.dock_expanded);
+ assert!(crate::panel_docking::showing(&app, panel), "{panel}");
+ assert!(app.ui.docking.as_ref().unwrap().floating.is_empty(), "{panel} opens from its icon group");
}
run_ui(&mut app, "window.resetWorkspace", &json!({})).unwrap().unwrap();
assert_eq!(app.ui.icon_groups, Some(groups));
diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs
index 4be709b70..393c977e5 100644
--- a/crates/ui-egui/src/panel_docking.rs
+++ b/crates/ui-egui/src/panel_docking.rs
@@ -1,6 +1,10 @@
//! Application-owned panel IDs and commands around the shared docking layout.
+//!
+//! The window's panels and the canvas are one craft-ui layout: a horizontal split of the
+//! protected `canvas` panel and a dock at the logical end edge (the right in left-to-right
+//! languages, the left in right-to-left ones).
-use craft_ui::docking::{Action, Floating, Layout, Node, Placement, Target, Zone};
+use craft_ui::docking::{Action, Column, Floating, Group, Layout, Node, Permissions, Placement, Side, Target, Zone};
use serde_json::{Value, json};
use crate::DesignApp;
@@ -43,35 +47,144 @@ fn normalize(raw: &str) -> Option<&'static str> {
.map(|(id, _, _)| *id)
}
+/// The panel that holds the document area. It never moves, floats, closes or takes tabs.
+pub(crate) const CANVAS: &str = "canvas";
+/// Width of an expanded dock column.
+const COLUMN_WIDTH: f32 = 260.0;
+/// Width of an iconic column of bare icons, and of one whose groups show their names.
+const ICON_WIDTH: f32 = 37.0;
+const NAMED_ICON_WIDTH: f32 = 150.0;
+/// Height of the group a workspace opens below Properties · Pages · Layers.
+const OPEN_PANEL_HEIGHT: f32 = 260.0;
+
+fn registered(id: &str) -> bool {
+ id == CANVAS || normalize(id) == Some(id)
+}
+
+/// The policy commands and the renderer apply: the canvas is protected.
+fn model_permissions(id: &String) -> Permissions {
+ if id == CANVAS { Permissions::PROTECTED } else { Permissions::default() }
+}
+
pub(crate) fn valid(layout: &Layout<String>) -> bool {
- layout.validate().is_ok() && layout.panels().iter().all(|id| normalize(id) == Some(id.as_str()))
+ layout.validate().is_ok()
+ && layout.panels().iter().all(|id| registered(id))
+ && Layout { root: layout.root.clone(), floating: Vec::new() }.contains(&CANVAS.to_string())
}
-fn legacy(app: &DesignApp) -> Layout<String> {
- let panels: Vec<String> = crate::dock::DOCK_TABS.iter().map(|p| p.0.to_string()).collect();
- let active = panels.iter().position(|p| p == &app.ui.dock_tab).unwrap_or(0);
- let mut layout = Layout { root: Some(Node::Tabs { panels, active }), floating: Vec::new() };
- for (id, at) in &app.ui.floating {
- if normalize(id).is_some() && !layout.contains(id) && at.iter().all(|v| v.is_finite()) {
- layout.floating.push(Floating::single(vec![id.clone()], 0, [at[0], at[1], 280.0, 360.0]));
+/// The layout of a workspace that has not been customized, from its panel settings: the
+/// canvas beside a dock whose outer column is the Properties · Pages · Layers group (with an
+/// open flyout panel stacked below it) and whose inner column is iconic. Essentials Classic
+/// and Typography (`icon_groups`) have the iconic column only.
+pub(crate) fn default_layout(ui: &crate::UiState) -> Layout<String> {
+ let mut placed: Vec<String> = Vec::new();
+ let take = |id: &str, placed: &mut Vec<String>| -> Option<String> {
+ let id = normalize(id)?;
+ (!placed.iter().any(|p| p == id)).then(|| {
+ placed.push(id.to_string());
+ id.to_string()
+ })
+ };
+ let mut floating = Vec::new();
+ for (id, at) in &ui.floating {
+ if at.iter().all(|v| v.is_finite())
+ && let Some(id) = take(id, &mut placed)
+ {
+ floating.push(Floating::single(vec![id], 0, [at[0], at[1], 280.0, 360.0]));
}
}
- if let Some(id) = &app.ui.open_panel
- && normalize(id).is_some()
- && !layout.contains(id)
- {
- // Preserve the visible flyout when the first unrelated docking gesture succeeds.
- if let Some(Node::Tabs { panels, active }) = &mut layout.root {
- panels.push(id.clone());
- *active = panels.len().saturating_sub(1);
+ let mut columns = Vec::new();
+ match &ui.icon_groups {
+ Some(groups) => {
+ let groups: Vec<Group<String>> = groups
+ .iter()
+ .map(|g| g.iter().filter_map(|id| take(id, &mut placed)).collect::<Vec<_>>())
+ .filter(|panels| !panels.is_empty())
+ .map(|panels| Group::new(panels, 0))
+ .collect();
+ if !groups.is_empty() {
+ columns.push(Column { groups, width: COLUMN_WIDTH, iconic: true, iconic_width: Some(NAMED_ICON_WIDTH) });
+ }
+ }
+ None => {
+ let panels: Vec<String> = crate::dock::DOCK_TABS.iter().filter_map(|p| take(p.0, &mut placed)).collect();
+ let active = panels.iter().position(|p| p == &ui.dock_tab).unwrap_or(0);
+ let mut groups = Vec::new();
+ if !panels.is_empty() {
+ groups.push(Group::new(panels, active));
+ }
+ // The panel a workspace opens (Printing and Proofing: Swatches) goes below at a fixed
+ // height, so Properties keeps most of the column.
+ if let Some(id) = ui.open_panel.as_deref().and_then(|id| take(id, &mut placed)) {
+ groups.push(Group { height: Some(OPEN_PANEL_HEIGHT), ..Group::new(vec![id], 0) });
+ }
+ if !groups.is_empty() {
+ columns.push(Column { groups, width: COLUMN_WIDTH, iconic: !ui.dock_expanded, iconic_width: Some(ICON_WIDTH) });
+ }
+ // Window › Styles opens the style panels as a floating group, so they start outside.
+ let icons: Vec<Group<String>> = crate::dock::ICON_PANELS
+ .iter()
+ .filter(|p| !FLOATING_GROUPS.iter().any(|g| g.contains(&p.0)))
+ .filter_map(|p| take(p.0, &mut placed))
+ .map(|id| Group::new(vec![id], 0))
+ .collect();
+ if !icons.is_empty() {
+ columns.push(Column { groups: icons, width: COLUMN_WIDTH, iconic: true, iconic_width: Some(ICON_WIDTH) });
+ }
}
}
- layout
+ let width: f32 = columns.iter().map(|c| if c.iconic { c.iconic_width.unwrap_or(ICON_WIDTH) } else { c.width }).sum();
+ Layout {
+ root: Some(Node::Split {
+ axis: craft_ui::layout::SplitAxis::Horizontal,
+ size: craft_ui::layout::SplitSize::FixedSecond(width),
+ first: Box::new(Node::Tabs { panels: vec![CANVAS.to_string()], active: 0 }),
+ second: Box::new(Node::Dock { side: Side::End, columns }),
+ }),
+ floating,
+ }
+}
+
+/// The layout in use: the customized one, or the workspace's default.
+fn layout_of(app: &DesignApp) -> Layout<String> {
+ app.ui.docking.clone().unwrap_or_else(|| default_layout(&app.ui))
+}
+
+/// Is `panel` showing: in front of its group, and not in a column collapsed to icons?
+pub(crate) fn showing(app: &DesignApp, panel: &str) -> bool {
+ layout_of(app).panel_state(&panel.to_string()) == craft_ui::docking::PanelState::Front
+}
+
+/// Is `panel` in a dock column collapsed to icons?
+fn in_iconic_column(layout: &Layout<String>, panel: &str) -> bool {
+ dock_columns(layout).iter().any(|c| c.iconic && c.groups.iter().any(|g| g.panels.iter().any(|p| p == panel)))
+}
+
+/// Every dock column, from each dock's window edge inwards.
+fn dock_columns(layout: &Layout<String>) -> Vec<&Column<String>> {
+ let mut out = Vec::new();
+ let mut visit: Vec<&Node<String>> = layout.root.iter().collect();
+ let mut seen = 0usize;
+ while let Some(node) = visit.pop() {
+ seen = seen.saturating_add(1);
+ if seen > 2 * craft_ui::docking::MAX_PANELS {
+ break;
+ }
+ match node {
+ Node::Split { first, second, .. } => {
+ visit.push(second);
+ visit.push(first);
+ }
+ Node::Dock { columns, .. } => out.extend(columns),
+ _ => {}
+ }
+ }
+ out
}
/// The panels tabbed with `panel`: its floating group, or its tab group in the dock. A panel in
/// an accordion, or not in the layout, is a group of its own.
-fn tab_group(layout: &Layout<String>, panel: &str) -> Vec<String> {
+pub(crate) fn tab_group(layout: &Layout<String>, panel: &str) -> Vec<String> {
if let Some(group) = layout.floating.iter().flat_map(|w| &w.groups).find(|g| g.panels.iter().any(|p| p == panel)) {
return group.panels.clone();
}
@@ -124,14 +237,26 @@ fn open_in_stack(layout: &Layout<String>, panel: &str) -> bool {
false
}
-fn first_root(layout: &Layout<String>, except: &str) -> Option<String> {
- let root = Layout { root: layout.root.clone(), floating: Vec::new() };
- root.panels().into_iter().find(|p| p.as_str() != except).cloned()
+/// Where a panel with no other destination goes: a panel of the first expanded dock column,
+/// else of any column, else of the root.
+fn first_dock_panel(layout: &Layout<String>, except: &str) -> Option<String> {
+ let usable = |p: &&String| p.as_str() != except && p.as_str() != CANVAS;
+ let columns = dock_columns(layout);
+ let in_columns =
+ |iconic: bool| columns.iter().filter(|c| c.iconic == iconic).flat_map(|c| &c.groups).flat_map(|g| &g.panels).find(usable).cloned();
+ in_columns(false).or_else(|| in_columns(true)).or_else(|| {
+ let root = Layout { root: layout.root.clone(), floating: Vec::new() };
+ root.panels().into_iter().find(usable).cloned()
+ })
}
fn ensure(layout: &mut Layout<String>, panel: &str) -> Result<(), String> {
- let anchor = first_root(layout, panel);
- layout.apply(Action::Open { panel: panel.into(), anchor }).map_err(|e| e.to_string())
+ let anchor = first_dock_panel(layout, panel);
+ apply(layout, Action::Open { panel: panel.into(), anchor })
+}
+
+fn apply(layout: &mut Layout<String>, action: Action<String>) -> Result<(), String> {
+ layout.apply_with_permissions(action, model_permissions).map_err(|e| e.to_string())
}
fn number(params: &Value, key: &str, default: f32) -> Result<f32, String> {
@@ -145,7 +270,33 @@ fn number(params: &Value, key: &str, default: f32) -> Result<f32, String> {
}
}
-fn placement(params: &Value) -> Result<Placement<String>, String> {
+/// The side of the dock holding `panel`, if a dock column holds it.
+fn dock_side(layout: &Layout<String>, panel: &str) -> Option<Side> {
+ let mut visit: Vec<&Node<String>> = layout.root.iter().collect();
+ let mut seen = 0usize;
+ while let Some(node) = visit.pop() {
+ seen = seen.saturating_add(1);
+ if seen > 2 * craft_ui::docking::MAX_PANELS {
+ break;
+ }
+ match node {
+ Node::Split { first, second, .. } => {
+ visit.push(first);
+ visit.push(second);
+ }
+ Node::Dock { side, columns } if columns.iter().flat_map(|c| &c.groups).any(|g| g.panels.iter().any(|p| p == panel)) => {
+ return Some(*side);
+ }
+ _ => {}
+ }
+ }
+ None
+}
+
+/// The placement a `zone` names beside `anchor`. In a dock column or a floating window, top and
+/// bottom add a group above or below the anchor's group; in a dock column, left and right add a
+/// column on that side of the anchor's. Elsewhere the sides split the anchor's group.
+fn placement(params: &Value, layout: &Layout<String>, anchor: &str, rtl: bool) -> Result<Placement<String>, String> {
if let Some(before) = params.get("before") {
let id = before.as_str().and_then(normalize).ok_or("before must name a panel")?;
return Ok(Placement::Tab { before: Some(id.into()) });
@@ -154,9 +305,18 @@ fn placement(params: &Value) -> Result<Placement<String>, String> {
None => "tab",
Some(value) => value.as_str().ok_or("zone must be a string")?,
};
+ let side = dock_side(layout, anchor);
+ let floating = layout.floating.iter().any(|w| w.contains(anchor));
Ok(match zone {
"tab" => Placement::Tab { before: None },
"center" => Placement::Split(Zone::Center),
+ "top" | "bottom" if side.is_some() || floating => Placement::Group { below: zone == "bottom" },
+ "left" | "right" if floating => return Err("a floating window has no columns; use top, bottom or tab".into()),
+ "left" | "right" if let Some(side) = side => {
+ // Columns count from the window edge inwards; `after` is away from the edge.
+ let edge_is_right = (side == Side::End) != rtl;
+ Placement::Column { after: (zone == "right") != edge_is_right }
+ }
"left" => Placement::Split(Zone::Left),
"right" => Placement::Split(Zone::Right),
"top" => Placement::Split(Zone::Top),
@@ -166,10 +326,11 @@ fn placement(params: &Value) -> Result<Placement<String>, String> {
}
pub(crate) fn command(app: &mut DesignApp, id: &str, params: &Value) -> Option<Result<Value, String>> {
- if id == "app.tablePanel" && app.ui.docking.is_some() {
- let panel = "table".to_string();
- let visible = app.ui.docking.as_ref().is_some_and(|layout| layout.contains(&panel));
- return Some(change(app, if visible { "close" } else { "activate" }, &json!({"panel": panel})));
+ if id == "app.tablePanel" {
+ return Some(change(app, if showing(app, "table") { "close" } else { "activate" }, &json!({"panel": "table"})));
+ }
+ if id == "window.collapseToIcons" {
+ return Some(set_iconic(app, true));
}
if id == "window.panel.closeGroup" {
return Some(close_group(app, params));
@@ -194,7 +355,8 @@ pub(crate) fn command(app: &mut DesignApp, id: &str, params: &Value) -> Option<R
"window.panel.dock" | "window.dockPanel" => "dock",
"window.panel.activate" => "activate",
"window.panel.close" => "close",
- "window.panel" if app.ui.docking.is_some() => "activate",
+ // Float-only panels (Type › Tabs) are not in the layout.
+ "window.panel" if params.get("panel").and_then(Value::as_str).and_then(normalize).is_some() => "activate",
_ => return None,
};
Some(change(app, operation, params))
@@ -203,7 +365,7 @@ pub(crate) fn command(app: &mut DesignApp, id: &str, params: &Value) -> Option<R
// UI output and automation share this atomic dispatcher. The application owns the registry
// and saved return locations; craft-ui owns tree validation and structural changes.
fn apply_action(app: &mut DesignApp, action: Action<String>) -> Result<Value, String> {
- let registered = |id: &String| normalize(id) == Some(id.as_str());
+ let registered = |id: &String| self::registered(id);
let known = match &action {
Action::Move { panel, anchor, placement } | Action::OpenAt { panel, anchor, placement } => {
registered(panel)
@@ -251,28 +413,25 @@ fn apply_action(app: &mut DesignApp, action: Action<String>) -> Result<Value, St
if app.ui.docking.as_ref().is_some_and(|layout| !valid(layout)) {
return Err("saved panel layout is invalid; reset the workspace first".into());
}
- let mut layout = app.ui.docking.clone().unwrap_or_else(|| legacy(app));
+ let mut layout = layout_of(app);
+ let closed = layout.closed_by(&action).map_err(|e| e.to_string())?;
// Window › a closed panel, and Dock Panel after a float, bring it back where it was.
let returning: Vec<_> = match &action {
Action::Float { panel, .. } => {
layout.location(panel).ok().filter(|location| location.floating.is_none()).map(|location| (panel.clone(), location)).into_iter().collect()
}
- _ => layout
- .closed_by(&action)
- .unwrap_or_default()
- .into_iter()
- .filter_map(|panel| layout.location(&panel).ok().map(|location| (panel, location)))
- .collect(),
+ _ => closed.iter().filter_map(|panel| layout.location(panel).ok().map(|location| (panel.clone(), location))).collect(),
};
let reveal = match &action {
Action::Activate { panel } | Action::Open { panel, .. } | Action::OpenAt { panel, .. } => Some(panel.clone()),
_ => None,
};
- layout.apply(action).map_err(|error| error.to_string())?;
+ apply(&mut layout, action)?;
for (panel, location) in returning {
app.ui.docking_hidden.insert(panel, location);
}
app.ui.docking = Some(layout);
+ release_closed(app, &closed);
sync_legacy(app);
if let Some(panel) = reveal {
app.ui.docking_opened = Some(panel.clone());
@@ -355,7 +514,7 @@ fn open_floating_group(app: &mut DesignApp, params: &Value) -> Option<Result<Val
if group.iter().any(|p| app.ui.docking_hidden.get(*p).is_some_and(|l| l.floating.is_none())) {
return None;
}
- let layout = app.ui.docking.clone().unwrap_or_else(|| legacy(app));
+ let layout = layout_of(app);
if group.iter().any(|p| layout.contains(&p.to_string())) {
return None;
}
@@ -390,7 +549,7 @@ fn change(app: &mut DesignApp, operation: &str, params: &Value) -> Result<Value,
if app.ui.docking.as_ref().is_some_and(|layout| !valid(layout)) {
return Err("saved panel layout is invalid; reset the workspace first".into());
}
- let mut layout = app.ui.docking.clone().unwrap_or_else(|| legacy(app));
+ let mut layout = layout_of(app);
let mut hidden: std::collections::BTreeMap<_, _> =
app.ui.docking_hidden.iter().filter(|(id, _)| normalize(id).is_some()).take(64).map(|(id, at)| (id.clone(), at.clone())).collect();
let mut restored = false;
@@ -403,7 +562,7 @@ fn change(app: &mut DesignApp, operation: &str, params: &Value) -> Result<Value,
{
let mut candidate = layout.clone();
if candidate.contains(&panel.to_string()) {
- candidate.apply(Action::Close { panel: panel.into() }).map_err(|e| e.to_string())?;
+ apply(&mut candidate, Action::Close { panel: panel.into() })?;
}
if candidate.restore(panel.into(), location).is_ok() {
layout = candidate;
@@ -421,7 +580,7 @@ fn change(app: &mut DesignApp, operation: &str, params: &Value) -> Result<Value,
{
hidden.insert(panel.into(), location);
}
- layout.apply(Action::Float { panel: panel.into(), rect }).map_err(|e| e.to_string())?;
+ apply(&mut layout, Action::Float { panel: panel.into(), rect })?;
}
"move" | "dock" => {
if operation == "move" && params.get("anchor").or_else(|| params.get("onto")).is_none() {
@@ -429,24 +588,24 @@ fn change(app: &mut DesignApp, operation: &str, params: &Value) -> Result<Value,
}
let anchor = match params.get("anchor").or_else(|| params.get("onto")) {
Some(v) => Some(v.as_str().and_then(normalize).ok_or("anchor must name a registered panel")?.to_string()),
- None => first_root(&layout, panel),
+ None => first_dock_panel(&layout, panel),
};
- let placement = placement(params)?;
if let Some(anchor) = anchor {
+ let placement = placement(params, &layout, &anchor, crate::i18n::is_rtl(&app.ui.language))?;
ensure(&mut layout, panel)?;
- layout.apply(Action::Move { panel: panel.into(), anchor, placement }).map_err(|e| e.to_string())?;
+ apply(&mut layout, Action::Move { panel: panel.into(), anchor, placement })?;
} else if operation == "dock" {
if layout.contains(&panel.to_string()) {
- layout.apply(Action::Close { panel: panel.into() }).map_err(|e| e.to_string())?;
+ apply(&mut layout, Action::Close { panel: panel.into() })?;
}
- layout.apply(Action::Open { panel: panel.into(), anchor: None }).map_err(|e| e.to_string())?;
+ apply(&mut layout, Action::Open { panel: panel.into(), anchor: None })?;
} else {
return Err("move requires an existing destination panel".into());
}
}
"close" => {
hidden.insert(panel.into(), layout.location(&panel.to_string()).map_err(|e| e.to_string())?);
- layout.apply(Action::Close { panel: panel.into() }).map_err(|e| e.to_string())?;
+ apply(&mut layout, Action::Close { panel: panel.into() })?;
}
_ => {
if !layout.contains(&panel.to_string())
@@ -457,10 +616,17 @@ fn change(app: &mut DesignApp, operation: &str, params: &Value) -> Result<Value,
}
ensure(&mut layout, panel)?;
hidden.remove(panel);
+ // Iconic columns open no flyouts yet, so showing a panel there expands its column.
+ if in_iconic_column(&layout, panel) {
+ apply(&mut layout, Action::SetIconic { panel: panel.into(), iconic: false })?;
+ }
}
}
app.ui.docking = Some(layout);
app.ui.docking_hidden = hidden;
+ if operation == "close" {
+ release_closed(app, &[panel.to_owned()]);
+ }
sync_legacy(app);
app.ui.open_panel = None;
app.ui.docking_opened = if operation == "close" { None } else { Some(panel.to_owned()) };
@@ -471,7 +637,40 @@ fn change(app: &mut DesignApp, operation: &str, params: &Value) -> Result<Value,
Ok(json!({"panel": panel, "floating": app.ui.floating.iter().map(|(id, _)| id).collect::<Vec<_>>(), "layout": app.ui.docking}))
}
-pub(crate) fn show(app: &mut DesignApp, ui: &mut egui::Ui) -> bool {
+/// Forget what DesignCraft keeps about panels that just closed: the focus, the panel last
+/// opened (for `ui.set closePanel`) and a pending raise.
+fn release_closed(app: &mut DesignApp, closed: &[String]) {
+ for slot in [&mut app.ui.docking_focused, &mut app.ui.docking_opened, &mut app.ui.docking_raise] {
+ if slot.as_ref().is_some_and(|panel| closed.contains(panel)) {
+ *slot = None;
+ }
+ }
+}
+
+/// Window › Collapse to Icons collapses every dock column; `iconic: false` (the control
+/// channel's `dockExpanded`) expands the outer column.
+pub(crate) fn set_iconic(app: &mut DesignApp, iconic: bool) -> Result<Value, String> {
+ if app.ui.docking.as_ref().is_some_and(|layout| !valid(layout)) {
+ return Err("saved panel layout is invalid; reset the workspace first".into());
+ }
+ let mut layout = layout_of(app);
+ let columns = dock_columns(&layout);
+ let firsts = |c: &&Column<String>| c.groups.first().and_then(|g| g.panels.first()).cloned();
+ let targets: Vec<String> = if iconic {
+ columns.iter().filter(|c| !c.iconic).filter_map(firsts).collect()
+ } else {
+ columns.first().filter(|c| c.iconic).and_then(firsts).into_iter().collect()
+ };
+ for panel in targets {
+ apply(&mut layout, Action::SetIconic { panel, iconic })?;
+ }
+ app.ui.docking = Some(layout);
+ app.ui.dock_expanded = !iconic;
+ app.ui.open_panel = None;
+ Ok(Value::Null)
+}
+
+pub(crate) fn show(app: &mut DesignApp, ui: &mut egui::Ui) {
let area = egui::Id::new("designcraft-panel-docking");
let changed_workspace = ui.ctx().data_mut(|data| {
let previous = data.get_temp::<u64>(area.with("generation"));
@@ -482,22 +681,11 @@ pub(crate) fn show(app: &mut DesignApp, ui: &mut egui::Ui) -> bool {
craft_ui::docking::cancel_drag::<String>(ui.ctx(), area);
ui.ctx().data_mut(|data| data.remove::<LegacyDrag>(area.with("legacy-origin")));
}
-
- let cancelled =
- ui.input(|input| !input.focused || input.key_pressed(egui::Key::Escape) || (!input.pointer.primary_down() && !input.pointer.any_released()));
- if cancelled && cancel_legacy_drag(app, ui.ctx()) && app.ui.docking.is_none() {
- return false;
- }
- let Some(layout) = app.ui.docking.as_ref() else { return false };
- if !valid(layout) {
+ if app.ui.docking.as_ref().is_some_and(|layout| !valid(layout)) {
app.ui.docking = None;
app.status(crate::i18n::tr(&app.ui.language, "Invalid panel layout; restored the default dock"));
- return false;
- }
- let mut layout = layout.clone();
- if !app.ui.dock_expanded {
- layout.root = None;
}
+ let layout = layout_of(app);
let raise = app.ui.docking_raise.take();
let mut blocked = Vec::new();
if app.ui.dialog.is_some() || app.ui.about || app.ui.palette.is_some() || egui::Popup::is_any_open(ui.ctx()) {
@@ -507,79 +695,87 @@ pub(crate) fn show(app: &mut DesignApp, ui: &mut egui::Ui) -> bool {
let rect = ui.ctx().memory(|m| m.area_rect(egui::Id::new("story_editor"))).unwrap_or_else(|| ui.ctx().content_rect());
blocked.push(rect);
}
- let t = crate::theme::Tokens::get(ui.ctx());
- let language = app.ui.language.clone();
- let mut draw = |ui: &mut egui::Ui| {
- let mut style = craft_ui::docking::DockStyle::from_ui(ui);
- style.tab_height = 27.0;
- style.background = t.panel;
- style.tab_background = t.tab_strip;
- style.active_background = t.panel;
- style.text = t.text_strong;
- style.inactive_text = t.text_dim;
- style.border = egui::Stroke::new(1.0, t.border);
- style.accent = t.accent;
- style.float_label = crate::i18n::tr(&language, "Float Panel").to_owned();
- style.close_label = crate::i18n::tr(&language, "Close Panel").to_owned();
- style.move_label = crate::i18n::tr(&language, "Group with").to_owned();
- style.panels_label = crate::i18n::tr(&language, "Panels").to_owned();
- style.resize_label = crate::i18n::tr(&language, "Resize panels").to_owned();
- style.resize_window_label = crate::i18n::tr(&language, "Resize panel window").to_owned();
- let mut area = craft_ui::docking::DockArea::new(egui::Id::new("designcraft-panel-docking")).blocked_rects(&blocked);
- if let Some(panel) = &raise {
- area = area.raise_panel(panel.clone());
- }
- area.show_customized(
- ui,
- &layout,
- &style,
- |id| {
- crate::i18n::tr(
- &language,
- crate::dock::DOCK_TABS.iter().chain(crate::dock::ICON_PANELS).find(|p| p.0 == id).map(|p| p.1).unwrap_or(id),
- )
- .to_owned()
- },
- // Close comes from the panel's own tab commands, so the surface doesn't add another.
- |_| craft_ui::docking::Permissions { closable: false, ..Default::default() },
- |_| craft_ui::docking::PanelLimits { min: egui::vec2(220.0, 80.0), ..Default::default() },
- &mut PanelContent(app),
- )
- };
- let output = if layout.root.is_some() {
- egui::Panel::right("shared-panel-dock")
- .default_size(310.0)
- .size_range(220.0..=720.0)
- .resizable(true)
- .frame(egui::Frame::NONE.fill(t.panel))
- .show(ui, &mut draw)
- .inner
- } else {
- draw(ui)
- };
+ let style = dock_style(ui, &app.ui.language);
+ let mut dock = craft_ui::docking::DockArea::new(area).blocked_rects(&blocked);
+ if let Some(panel) = raise {
+ dock = dock.raise_panel(panel);
+ }
+ let mut content = PanelContent(app, Vec::new());
+ let output = dock.show_content(ui, &layout, &style, &mut content);
+ let floats = content.1;
if let Some(panel) = output.focused {
- app.ui.docking_opened = Some(panel);
+ if panel != CANVAS {
+ app.ui.docking_opened = Some(panel.clone());
+ }
+ app.ui.docking_focused = Some(panel);
}
if let Some(error) = output.error {
app.ui.status = error.to_string();
}
- if ui.input(|input| input.pointer.any_released()) {
- if !output.actions.iter().any(|action| matches!(action, Action::Move { .. } | Action::Float { .. } | Action::MoveGroup { .. }))
- && cancel_legacy_drag(app, ui.ctx())
- {
- return app.ui.docking.is_some();
- }
- ui.ctx().data_mut(|data| data.remove::<LegacyDrag>(egui::Id::new("designcraft-panel-docking").with("legacy-origin")));
- }
- for action in output.actions {
+ for action in output.actions.into_iter().chain(floats) {
if let Err(error) = app.run("window.panel.layout", json!({"action": action})) {
app.ui.status = error;
}
}
- icon_rail(app, ui);
- true
}
+/// What the control channel reports: the layout in use (craft-ui's serialized `Layout`),
+/// whether it is the workspace's default, the panel (or `canvas`) last clicked or selected, and
+/// the panels closed with a remembered place.
+pub(crate) fn inspect(app: &DesignApp) -> Value {
+ json!({
+ "layout": layout_of(app),
+ "customized": app.ui.docking.is_some(),
+ "focused": app.ui.docking_focused,
+ "rightToLeft": crate::i18n::is_rtl(&app.ui.language),
+ "hidden": app.ui.docking_hidden.keys().collect::<Vec<_>>(),
+ })
+}
+
+fn dock_style(ui: &egui::Ui, language: &str) -> craft_ui::docking::DockStyle {
+ let t = crate::theme::Tokens::get(ui.ctx());
+ let mut style = craft_ui::docking::DockStyle::from_ui(ui);
+ style.tab_height = 27.0;
+ style.background = t.panel;
+ style.tab_background = t.tab_strip;
+ style.active_background = t.panel;
+ style.text = t.text_strong;
+ style.inactive_text = t.text_dim;
+ style.border = egui::Stroke::new(1.0, t.border);
+ style.accent = t.accent;
+ style.right_to_left = crate::i18n::is_rtl(language);
+ style.localized(|key| DOCK_LABELS.iter().find(|(k, _)| *k == key).map(|(_, english)| crate::i18n::tr(language, english).to_owned()))
+}
+
+/// DesignCraft's wording of craft-ui's docking labels, translated through `i18n::tr`.
+const DOCK_LABELS: &[(&str, &str)] = &[
+ ("dock.float", "Float Panel"),
+ ("dock.close", "Close"),
+ ("dock.move", "Group with"),
+ ("dock.panels", "Panels"),
+ ("dock.resize", "Resize panels"),
+ ("dock.resizeWindow", "Resize panel window"),
+ ("dock.moveGroup", "Move Tab Group"),
+ ("dock.closeGroup", "Close Tab Group"),
+ ("dock.minimize", "Minimize"),
+ ("dock.expand", "Expand"),
+ ("dock.floatGroup", "Float Tab Group"),
+ ("dock.groupWith", "Group Tab Group with"),
+ ("dock.moveColumn", "Move Panel Column"),
+ ("dock.collapseToIcons", "Collapse to Icons"),
+ ("dock.expandPanels", "Expand Panels"),
+ ("dock.moveWindow", "Move Panel Window"),
+ ("dock.closeWindow", "Close Panel Window"),
+ ("dock.undock", "Undock Panel"),
+ ("dock.undockGroup", "Undock Panel Group"),
+ ("dock.closePanelGroup", "Close Panel Group"),
+ ("dock.closeOthers", "Close Other Panels in Group"),
+ ("dock.maximize", "Maximize Frame"),
+ ("dock.restoreFrame", "Restore Frame Size"),
+ ("dock.newWindow", "Move Panel to New Window"),
+];
+
+#[allow(dead_code)] // The classic icon rail; removed with the classic dock.
fn icon_rail(app: &mut DesignApp, ui: &mut egui::Ui) {
let t = crate::theme::Tokens::get(ui.ctx());
let column = egui::Panel::right("shared-panel-icons")
@@ -616,7 +812,7 @@ pub(crate) fn legacy_tab(app: &mut DesignApp, ui: &mut egui::Ui, panel: &str, re
if response.drag_started()
&& let Some(id) = normalize(panel)
{
- let mut layout = app.ui.docking.clone().unwrap_or_else(|| legacy(app));
+ let mut layout = layout_of(app);
let bounds = ui.max_rect();
let source = egui::Rect::from_min_size(
egui::pos2(bounds.left(), response.rect.top()),
@@ -705,9 +901,51 @@ fn floating_size(panel: &str) -> egui::Vec2 {
}
}
-struct PanelContent<'a>(&'a mut DesignApp);
+/// The panels' content, and the floats released over the canvas this frame.
+struct PanelContent<'a>(&'a mut DesignApp, Vec<Action<String>>);
impl craft_ui::docking::DockContent<String> for PanelContent<'_> {
+ /// A panel or group released over the document area floats there, as in InDesign, instead of
+ /// splitting the canvas. The window's edge bands still make new docks and root splits.
+ fn resolve_drag(
+ &mut self,
+ _: &egui::Context,
+ style: &craft_ui::docking::DockStyle,
+ request: &craft_ui::docking::DropRequest<'_, String>,
+ ) -> Option<craft_ui::docking::DropFeedback> {
+ let pointer = request.pointer;
+ let over_canvas = request.targets.iter().rev().find(|t| t.rect.contains(pointer)).is_some_and(|t| t.anchor == CANVAS);
+ let band = style.edge_band.max(style.new_dock_band);
+ if !over_canvas || !request.workspace.shrink(band).contains(pointer) {
+ return None;
+ }
+ // A floating window moving live has no float rect; it moves as before.
+ if request.whole_group && request.floating_rect.is_none() {
+ return None;
+ }
+ if request.released
+ && let Some(r) = request.floating_rect
+ {
+ let rect = [r.left(), r.top(), r.width(), r.height()];
+ let panel = request.panel.clone();
+ self.1.push(if request.whole_group {
+ Action::MoveGroup { panel, to: Target::Float { rect: Some(rect) } }
+ } else {
+ Action::Float { panel, rect }
+ });
+ }
+ Some(craft_ui::docking::DropFeedback { preview: request.floating_rect, insertion: None })
+ }
fn body(&mut self, ui: &mut egui::Ui, id: &String) {
+ if id == CANVAS {
+ let fill = crate::theme::Tokens::get(ui.ctx()).pasteboard;
+ ui.painter().rect_filled(ui.max_rect(), 0.0, fill);
+ // A bare panel has no tab to report focus through, so the canvas reports its own.
+ if ui.input(|i| i.pointer.any_pressed()) && ui.ui_contains_pointer() {
+ self.0.ui.docking_focused = Some(CANVAS.to_string());
+ }
+ self.0.canvas_area(ui, false);
+ return;
+ }
egui::Frame::NONE.inner_margin(egui::Margin::same(8)).show(ui, |ui| {
if crate::dock::scrolls_itself(id) {
crate::dock::panel_body(self.0, ui, id);
@@ -719,17 +957,23 @@ impl craft_ui::docking::DockContent<String> for PanelContent<'_> {
.show(ui, |ui| crate::dock::panel_body(self.0, ui, id));
});
}
- fn panel_menu(&mut self, ui: &mut egui::Ui, id: &String) {
- // The docking surface adds Float Panel and Group with after these, so a tab's menu lists
- // what the classic dock's does.
- if let Some(panel) = normalize(id) {
- tab_commands(self.0, ui, panel);
- ui.separator();
- }
+ fn logical_label(&self, id: &String) -> String {
+ let english = crate::dock::DOCK_TABS.iter().chain(crate::dock::ICON_PANELS).find(|p| p.0 == id).map_or(id.as_str(), |p| p.1);
+ crate::i18n::tr(&self.0.ui.language, english).to_owned()
+ }
+ fn permissions(&self, id: &String) -> Permissions {
+ model_permissions(id)
+ }
+ fn limits(&self, id: &String) -> craft_ui::docking::PanelLimits {
+ let min = if id == CANVAS { egui::vec2(200.0, 120.0) } else { egui::vec2(220.0, 80.0) };
+ craft_ui::docking::PanelLimits { min, ..Default::default() }
}
fn floating_size(&self, id: &String) -> Option<egui::Vec2> {
Some(floating_size(id))
}
+ fn bare(&self, id: &String) -> bool {
+ id == CANVAS
+ }
fn group_header_width(&self, _: &[String], _: &String, _: bool) -> f32 {
24.0
}
@@ -750,7 +994,7 @@ impl craft_ui::docking::DockContent<String> for PanelContent<'_> {
/// closed with Close.
fn close_group(app: &mut DesignApp, params: &Value) -> Result<Value, String> {
let panel = params.get("panel").and_then(Value::as_str).and_then(normalize).ok_or("panel must name a registered panel")?;
- let layout = app.ui.docking.clone().unwrap_or_else(|| legacy(app));
+ let layout = layout_of(app);
let group = tab_group(&layout, panel);
for p in &group {
change(app, "close", &json!({"panel": p}))?;
@@ -758,8 +1002,9 @@ fn close_group(app: &mut DesignApp, params: &Value) -> Result<Value, String> {
Ok(json!({"closed": group}))
}
-/// InDesign's commands on a panel tab (and at the end of its panel menu): Close, Close Tab Group,
-/// Minimize (an open accordion entry) and Collapse to Icons.
+/// InDesign's panel tab commands at the end of a panel's three-line menu: Close, Close Tab Group,
+/// Minimize (an open accordion entry) and Collapse to Icons. A tab's own context menu is
+/// craft-ui's, which lists the same commands.
fn tab_commands(app: &mut DesignApp, ui: &mut egui::Ui, panel: &'static str) {
let language = app.ui.language.clone();
let tr = |s: &str| crate::i18n::tr(&language, s).to_owned();
@@ -775,26 +1020,24 @@ fn tab_commands(app: &mut DesignApp, ui: &mut egui::Ui, panel: &'static str) {
if ui.button(crate::rtl::widget(ui, tr("Close Tab Group"))).clicked() {
run(app, ui, "window.panel.closeGroup", json!({"panel": panel}));
}
- let layout = app.ui.docking.clone().unwrap_or_else(|| legacy(app));
+ let layout = layout_of(app);
let minimizable = open_in_stack(&layout, panel);
if ui.add_enabled(minimizable, egui::Button::new(crate::rtl::widget(ui, tr("Minimize")))).clicked() {
run(app, ui, "window.panel.layout", json!({"action": {"SetStackOpen": {"panel": panel, "open": false}}}));
}
ui.separator();
- if ui.add_enabled(app.ui.dock_expanded, egui::Button::new(crate::rtl::widget(ui, tr("Collapse to Icons")))).clicked() {
+ let expanded = dock_columns(&layout).iter().any(|c| !c.iconic);
+ if ui.add_enabled(expanded, egui::Button::new(crate::rtl::widget(ui, tr("Collapse to Icons")))).clicked() {
run(app, ui, "window.collapseToIcons", json!({}));
}
}
/// Close the last explicitly opened panel through the same validated layout transaction.
pub(crate) fn close_visible(app: &mut DesignApp) -> Result<(), String> {
- if app.ui.docking.is_some() {
- if let Some(panel) = app.ui.docking_opened.clone() {
- change(app, "close", &json!({"panel": panel}))?;
- }
- } else {
- app.ui.open_panel = None;
+ if let Some(panel) = app.ui.docking_opened.clone() {
+ change(app, "close", &json!({"panel": panel}))?;
}
+ app.ui.open_panel = None;
Ok(())
}
diff --git a/crates/ui-egui/src/panel_docking_tests.rs b/crates/ui-egui/src/panel_docking_tests.rs
index 8d8e34fdd..abbcf1391 100644
--- a/crates/ui-egui/src/panel_docking_tests.rs
+++ b/crates/ui-egui/src/panel_docking_tests.rs
@@ -59,8 +59,7 @@ fn harness(app: DesignApp, size: egui::Vec2) -> Harness<'static, DesignApp> {
ready = true;
return;
}
- crate::dock::show(app, ui);
- egui::CentralPanel::default().show(ui, |_| {});
+ egui::CentralPanel::default().frame(egui::Frame::NONE).show(ui, |ui| crate::panel_docking::show(app, ui));
},
app,
);
@@ -188,7 +187,7 @@ fn capture_custom_panel_docking_visual_fixtures() {
}
#[test]
-fn escape_cancels_the_first_drag_without_replacing_the_legacy_workspace() {
+fn escape_cancels_a_tab_drag_without_customizing_the_workspace() {
let mut h = harness(app(), vec2(1280.0, 800.0));
let source = h.query_all_by_label("Layers").find(|node| node.rect().height() <= 45.0).unwrap().rect().center();
h.event(Event::PointerMoved(source));
@@ -197,7 +196,6 @@ fn escape_cancels_the_first_drag_without_replacing_the_legacy_workspace() {
h.run_steps(1);
h.event(Event::PointerMoved(source - vec2(90.0, 0.0)));
h.run_steps(2);
- assert!(h.state().ui.docking.is_some());
h.event(Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
h.run_steps(1);
assert!(h.state().ui.docking.is_none());
@@ -235,27 +233,26 @@ fn serialized_layout_actions_cover_geometry_reorder_accordion_and_atomic_rejecti
assert_eq!(app.ui.docking, before);
assert_eq!(app.ui.docking_hidden, hidden);
}
+ let stack = Node::Stack { entries: vec![craft_ui::docking::StackEntry { panel: "layers".into(), open: true, height: Some(100.0) }] };
app.ui.docking = Some(Layout {
- root: Some(Node::Stack { entries: vec![craft_ui::docking::StackEntry { panel: "layers".into(), open: true, height: Some(100.0) }] }),
+ root: Some(Node::Split {
+ axis: craft_ui::layout::SplitAxis::Horizontal,
+ size: craft_ui::layout::SplitSize::Ratio(0.7),
+ first: Box::new(Node::Tabs { panels: vec![CANVAS.into()], active: 0 }),
+ second: Box::new(stack),
+ }),
floating: Vec::new(),
});
app.run("window.panel.layout", json!({"action":{"SetStackOpen":{"panel":"layers","open":false}}})).unwrap();
app.run("window.panel.layout", json!({"action":{"ResizeStack":{"panel":"layers","height":150}}})).unwrap();
- let Some(Node::Stack { entries }) = &app.ui.docking.as_ref().unwrap().root else { panic!("expected stack") };
+ let Some(Node::Split { second, .. }) = &app.ui.docking.as_ref().unwrap().root else { panic!("expected split") };
+ let Node::Stack { entries } = &**second else { panic!("expected stack") };
assert!(!entries[0].open);
assert_eq!(entries[0].height, Some(150.0));
}
fn group_members_for_test(layout: &Layout<String>, panel: &str) -> Vec<String> {
- let mut pending: Vec<_> = layout.root.iter().collect();
- while let Some(node) = pending.pop() {
- match node {
- Node::Tabs { panels, .. } if panels.iter().any(|p| p == panel) => return panels.clone(),
- Node::Split { first, second, .. } => pending.extend([first.as_ref(), second.as_ref()]),
- _ => {}
- }
- }
- Vec::new()
+ tab_group(layout, panel)
}
#[test]
@@ -309,7 +306,7 @@ fn properties_stroke_link_opens_the_stroke_panel_in_a_custom_workspace() {
app.run("window.panel.float", json!({"panel":"layers"})).unwrap();
// Floating Layers leaves Pages the active tab beside Properties.
app.run("window.panel", json!({"panel":"properties"})).unwrap();
- assert!(!app.ui.docking.as_ref().unwrap().contains(&"stroke".into()));
+ assert!(in_iconic_column(app.ui.docking.as_ref().unwrap(), "stroke"));
let mut h = Harness::builder().with_size(vec2(1280.0, 800.0)).build_ui_state(
|ui, app: &mut DesignApp| {
app.logic(ui.ctx());
@@ -326,7 +323,7 @@ fn properties_stroke_link_opens_the_stroke_panel_in_a_custom_workspace() {
h.run_steps(1);
}
h.run_steps(2);
- assert!(h.state().ui.docking.as_ref().unwrap().contains(&"stroke".into()));
+ assert!(!in_iconic_column(h.state().ui.docking.as_ref().unwrap(), "stroke"));
assert_eq!(h.state().ui.docking_opened.as_deref(), Some("stroke"));
}
@@ -628,7 +625,7 @@ fn capture_legacy_panel_menu_visual_fixture() {
}
#[test]
-fn legacy_dock_menu_button_opens_the_active_panel_menu() {
+fn dock_menu_button_opens_the_active_panel_menu() {
let mut app = app();
app.run("file.new", json!({})).unwrap();
app.ui.dock_tab = "pages".into();
@@ -636,8 +633,8 @@ fn legacy_dock_menu_button_opens_the_active_panel_menu() {
let mut h = harness(app, vec2(1280.0, 800.0));
assert!(h.state().ui.docking.is_none());
let tab = h.query_all_by_label("Pages").find(|node| node.rect().height() <= 45.0).unwrap().rect();
- let dock = egui::containers::panel::PanelState::load(&h.ctx, egui::Id::new("dock")).unwrap().outer_rect;
- let at = egui::pos2(dock.right() - 15.0, tab.center().y);
+ // The outer dock column is at the window's right edge; the ≡ ends its tab strip.
+ let at = egui::pos2(1280.0 - 12.0, tab.center().y);
h.event(Event::PointerMoved(at));
h.run_steps(1);
for pressed in [true, false] {
@@ -697,9 +694,11 @@ fn a_tabs_context_menu_lists_indesigns_tab_commands_and_close_works() {
h.run_steps(1);
h.event(Event::PointerButton { pos: tab, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE });
h.run_steps(2);
+ // The column bar's » button is also labelled Collapse to Icons.
for item in ["Close", "Close Tab Group", "Minimize", "Collapse to Icons", "Float Panel"] {
- assert!(h.query_by_label(item).is_some(), "{item}");
+ assert!(h.query_all_by_label(item).next().is_some(), "{item}");
}
+ assert_eq!(h.query_all_by_label("Minimize").count(), 1, "the tab menu lists Minimize once");
h.get_by_label("Close").click();
h.run_steps(2);
assert!(!h.state().ui.docking.as_ref().unwrap().contains(&"layers".to_string()));
@@ -716,7 +715,7 @@ fn paragraph_styles_open_floating_with_character_styles() {
assert_eq!(group.panels, ["characterStyles", "paragraphStyles"]);
assert_eq!(group.panels[group.active], "paragraphStyles", "the one chosen is in front");
// The dock still shows Properties in front.
- assert!(matches!(&layout.root, Some(craft_ui::docking::Node::Tabs { panels, active }) if panels[*active] == "properties"), "{:?}", layout.root);
+ assert!(front_tabs(&layout).iter().any(|p| p == "properties"), "{:?}", layout.root);
// Other panels from Window leave it open.
app.run("window.panel", json!({"panel":"color"})).unwrap();
app.run("window.panel", json!({"panel":"links"})).unwrap();
@@ -768,8 +767,7 @@ fn pages_keeps_its_panel_menu_in_the_docking_layout() {
assert!(app.ui.docking.is_some());
let mut h = harness(app, vec2(1280.0, 800.0));
let tab = h.query_all_by_label("Pages").find(|node| node.rect().height() <= 45.0).unwrap().rect();
- let dock = egui::containers::panel::PanelState::load(&h.ctx, egui::Id::new("shared-panel-dock")).unwrap().outer_rect;
- click(&mut h, egui::pos2(dock.right() - 12.0, tab.center().y), PointerButton::Primary);
+ click(&mut h, egui::pos2(1280.0 - 12.0, tab.center().y), PointerButton::Primary);
assert!(egui::Popup::is_any_open(&h.ctx), "the three-line button must open a menu");
for item in ["Numbering & Section Options…", "Close Tab Group", "Float Panel"] {
assert!(h.query_by_label(item).is_some(), "{item}");
@@ -797,6 +795,11 @@ fn group_with<'a>(layout: &'a Layout<String>, panel: &str) -> (bool, &'a [String
match node {
Node::Split { first, second, .. } => visit.extend([&**first, &**second]),
Node::Tabs { panels, active } if panels.iter().any(|p| p == panel) => return (false, panels, *active),
+ Node::Dock { columns, .. } => {
+ if let Some(g) = columns.iter().flat_map(|c| &c.groups).find(|g| g.panels.iter().any(|p| p == panel)) {
+ return (false, &g.panels, g.active);
+ }
+ }
_ => {}
}
}
@@ -814,7 +817,7 @@ fn drag_bar(h: &Harness<'static, DesignApp>, first: &str) -> egui::Rect {
fn dragging_a_docked_group_by_its_bar_moves_every_tab() {
let mut app = app();
app.run("window.panel", json!({"panel":"paragraphStyles"})).unwrap();
- let below = json!({"MoveGroup": {"panel": "characterStyles", "to": {"At": {"anchor": "properties", "placement": {"Split": "Bottom"}}}}});
+ let below = json!({"MoveGroup": {"panel": "characterStyles", "to": {"At": {"anchor": "properties", "placement": {"Group": {"below": true}}}}}});
app.run("window.panel.layout", json!({"action": below})).unwrap();
let styles = ["characterStyles", "paragraphStyles"];
assert_eq!(group_with(app.ui.docking.as_ref().unwrap(), "characterStyles"), (false, &styles.map(String::from)[..], 1));
@@ -837,3 +840,81 @@ fn dragging_a_docked_group_by_its_bar_moves_every_tab() {
assert_eq!(panels[active], "paragraphStyles");
assert!(layout.floating.is_empty(), "{:?}", layout.floating);
}
+
+fn dock_of(layout: &Layout<String>) -> (Side, &[Column<String>]) {
+ let Some(Node::Split { first, second, .. }) = &layout.root else { panic!("root is not a split: {layout:?}") };
+ assert!(matches!(&**first, Node::Tabs { panels, .. } if panels == &[CANVAS.to_string()]), "{layout:?}");
+ let Node::Dock { side, columns } = &**second else { panic!("second is not a dock: {layout:?}") };
+ (*side, columns)
+}
+
+#[test]
+fn default_workspaces_are_the_canvas_beside_an_end_dock() {
+ let mut app = app();
+ let layout = default_layout(&app.ui);
+ assert!(valid(&layout));
+ let (side, columns) = dock_of(&layout);
+ assert_eq!(side, Side::End);
+ let [outer, icons] = columns else { panic!("{columns:?}") };
+ assert!(!outer.iconic);
+ assert_eq!(outer.groups.len(), 1);
+ assert_eq!(outer.groups[0].panels, ["properties", "pages", "layers"]);
+ assert!(icons.iconic);
+ assert!(icons.groups.iter().all(|g| g.panels.len() == 1));
+ assert!(!layout.contains(&"paragraphStyles".to_string()), "Window › Styles opens the styles floating");
+ // Essentials Classic: only its named icon groups, in one iconic column.
+ app.run("window.workspace", json!({"name": "Essentials Classic"})).unwrap();
+ let layout = default_layout(&app.ui);
+ assert!(valid(&layout));
+ let (_, columns) = dock_of(&layout);
+ let [column] = columns else { panic!("{columns:?}") };
+ assert!(column.iconic);
+ let expected: Vec<Vec<String>> = app.ui.icon_groups.clone().unwrap();
+ let groups: Vec<Vec<String>> = column.groups.iter().map(|g| g.panels.clone()).collect();
+ assert_eq!(groups.len(), expected.len());
+ assert!(groups.iter().flatten().all(|p| expected.iter().flatten().any(|e| e == p)));
+}
+
+#[test]
+fn the_dock_is_at_the_right_in_english_and_the_left_in_arabic() {
+ let tab = |h: &Harness<'static, DesignApp>| {
+ h.ctx.read_response(egui::Id::new("designcraft-panel-docking").with(("tab", &"properties".to_string()))).map(|r| r.rect).unwrap()
+ };
+ let h = harness(app(), vec2(1280.0, 800.0));
+ assert!(tab(&h).left() > 640.0, "{:?}", tab(&h));
+ let mut arabic = app();
+ arabic.ui.language = "ar".into();
+ let h = harness(arabic, vec2(1280.0, 800.0));
+ assert!(tab(&h).right() < 640.0, "{:?}", tab(&h));
+}
+
+#[test]
+fn ui_docking_reports_the_layout_and_the_focused_panel() {
+ let mut h = harness(app(), vec2(1280.0, 800.0));
+ let ctx = h.ctx.clone();
+ let docking = |app: &mut DesignApp| {
+ let (req, _rx) = crate::control::ControlRequest::new("ui.docking", json!({}));
+ match crate::control::handle(app, &ctx, &req) {
+ crate::control::Outcome::Done(v) => v,
+ crate::control::Outcome::Screenshot { .. } => panic!("ui.docking took a screenshot"),
+ }
+ };
+ let v = docking(h.state_mut());
+ assert_eq!(v["ok"], true, "{v}");
+ let result = &v["result"];
+ assert_eq!(result["customized"], false);
+ assert_eq!(result["rightToLeft"], false);
+ assert!(result["focused"].is_null());
+ let layout: Layout<String> = serde_json::from_value(result["layout"].clone()).unwrap();
+ assert_eq!(layout, default_layout(&h.state().ui));
+ let at = h.ctx.read_response(egui::Id::new("designcraft-panel-docking").with(("tab", &"layers".to_string()))).unwrap().rect.center();
+ click(&mut h, at, PointerButton::Primary);
+ let v = docking(h.state_mut());
+ assert_eq!(v["result"]["focused"], "layers", "{v}");
+ // Closing the focused panel releases the focus.
+ h.state_mut().run("window.panel.close", json!({"panel": "layers"})).unwrap();
+ let v = docking(h.state_mut());
+ assert!(v["result"]["focused"].is_null(), "{v}");
+ assert_eq!(v["result"]["customized"], true);
+ assert_eq!(v["result"]["hidden"], json!(["layers"]));
+}
diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rs
index 7c40f3b1b..42755d75d 100644
--- a/crates/ui-egui/src/panels/mod.rs
+++ b/crates/ui-egui/src/panels/mod.rs
@@ -741,6 +741,15 @@ mod font_menu_ui_tests {
for k in 0..count {
h.state_mut().app.run("type.char", json!({"attrs": {"fontFamily": designcraft_fonts::DEFAULT_FAMILY}})).unwrap();
h.run_steps(4);
+ // A short Properties group (below it, the workspace's open panel) scrolls to the field.
+ let mut nodes: Vec<_> = h
+ .query_all_by(|n| n.role() == egui::accesskit::Role::ComboBox && n.value().as_deref() == Some(designcraft_fonts::DEFAULT_FAMILY))
+ .collect();
+ nodes.sort_by(|a, b| a.rect().min.y.total_cmp(&b.rect().min.y).then(a.rect().min.x.total_cmp(&b.rect().min.x)));
+ if let Some(node) = nodes.get(k) {
+ node.scroll_to_me();
+ }
+ h.run_steps(4);
let at = fields(&h, designcraft_fonts::DEFAULT_FAMILY)[k];
search_in_menu(&mut h, at, &format!("{name}, field {k}"));
assert_eq!(family(&mut h), "Source Sans 3", "{name}, field {k}");
diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs
index fded030b9..79cf2f0e7 100644
--- a/crates/ui-egui/src/panels/properties.rs
+++ b/crates/ui-egui/src/panels/properties.rs
@@ -1173,7 +1173,7 @@ fn text_style_section(app: &mut DesignApp, ui: &mut Ui) {
)
.clicked()
{
- app.ui.open_panel = Some(if tab == 0 { "paragraphStyles" } else { "characterStyles" }.into());
+ show_panel(app, if tab == 0 { "paragraphStyles" } else { "characterStyles" });
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.spacing_mut().item_spacing.x = 12.0;
@@ -1191,7 +1191,7 @@ fn text_style_section(app: &mut DesignApp, ui: &mut Ui) {
let _ = app.run("style.paragraph.apply", json!({"name": cur, "clearOverrides": true}));
}
if icon_toggle(ui, "style-load", false, crate::i18n::tr(&app.ui.language, "Styles panel")).clicked() {
- app.ui.open_panel = Some(if tab == 0 { "paragraphStyles" } else { "characterStyles" }.into());
+ show_panel(app, if tab == 0 { "paragraphStyles" } else { "characterStyles" });
}
});
});
diff --git a/docs/control-protocol.md b/docs/control-protocol.md
index 1dc0eed49..78ef44fa3 100644
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@ -35,7 +35,8 @@ so only enable it while you use it. Transport: `apps/designcraft/src/control_ser
| `engine.execute` / `ui.menu.invoke` | `{command, params}` | Run any engine or UI command (see `engine.commands`). `ui.menu.invoke` without `params` acts like choosing the menu item: a command labelled "…" that takes parameters opens its dialog. A key the command's params description doesn't name is an error (`unknown parameter …`), not ignored |
| `engine.commands` | — | Every command: id, label, menu path, shortcut, params doc, enabled |
| `document.inspect` | — | Pages, spreads, items, stories (overset), styles, swatches, selection |
-| `ui.inspect` | — | Tool, UI state, view (zoom/origin), canvas rect, perf |
+| `ui.inspect` | — | Tool, UI state, view (zoom/origin), canvas rect, panel layout (`docking`), perf |
+| `ui.docking` | — | The panel layout in use and the focused panel (see Shared panel docking) |
| `ui.menu.list` / `ui.tool.list` | — | Menu tree / Tools panel groups |
| `ui.tool.select` | `{tool}` | Select a tool (`selection`, `type`, `rectangleFrame`, …) |
| `ui.pointer` | `{events:[{kind: down\|drag\|up\|move\|doubleclick, x, y, space?: "screen"\|"canvas", clicks?}], mods?}` | Drive the active tool through the same code path as the mouse; `clicks` on a `down` is the press count (3 = triple click); returns the selection, the tool and its cursor at the last event (e.g. `LoadedText`, `ThreadLink`, `Unthread`) |
@@ -77,18 +78,30 @@ Panel arrangements support tab grouping and reordering, horizontal and vertical
and movable, resizable floating groups inside the application window. Drag a panel tab,
or use its context menu. Floating groups remain within the application viewport.
-The shared layout begins with the existing workspace on the first docking operation.
-Workspace saves retain its groups, active tabs, split sizes, floating geometry, and the
-positions of hidden panels. Resetting a built-in workspace restores its default dock.
+The window is one panel layout: the protected `canvas` panel (the document area) beside a
+dock at the logical end edge, the right in left-to-right languages and the left in
+right-to-left ones. Each built-in workspace has a default layout. Essentials and most others
+have an outer column with the Properties · Pages · Layers group and an iconic column with the
+other panels; Essentials Classic and Typography have their named iconic groups only. A panel a
+workspace opens (Printing and Proofing: Swatches) is a group below Properties · Pages · Layers.
+The `canvas` panel never moves, floats, closes or takes tabs; a panel or tab group dropped
+over it floats there. Workspace saves retain its groups, active tabs, split sizes, floating
+geometry, and the positions of hidden panels. Resetting a built-in workspace restores its
+default dock.
- `window.panel.move {panel, anchor, zone?, before?}` moves a panel into the target group.
`zone` is `tab` (default), `center`, `left`, `right`, `top`, or `bottom`; `before` reorders
- tabs by panel ID. The destination must already be visible.
+ tabs by panel ID. The destination must already be visible. Beside a panel in a dock column,
+ `top` and `bottom` add a group above or below its group and `left` and `right` add a column
+ on that side; in a floating window, `top` and `bottom` add a group and `left` and `right`
+ are errors.
- `window.panel.float {panel, x?, y?, width?, height?}` detaches a panel.
- `window.panel.dock {panel, anchor?, zone?, before?}` returns a panel to its previous
dock placement when possible, or to the supplied destination.
-- `window.panel.activate {panel}` reveals and selects a panel, restoring its saved
- position when possible. `window.panel.close {panel}` hides it.
+- `window.panel.activate {panel}` (and `window.panel {panel}`) reveals and selects a panel,
+ restoring its saved position when possible; a panel in an iconic column expands that
+ column. `window.panel.close {panel}` hides it.
+- `window.collapseToIcons` collapses every dock column to icons.
Panel IDs are stable across themes. Invalid IDs, non-finite or invalid geometry, and
invalid destinations return an error without changing the arrangement.
@@ -102,8 +115,26 @@ resizes the root divider (`false`/`true` path entries select first/second childr
The UI dispatches these same commands. Unknown panel IDs, invalid geometry, and stale
split paths return an error without changing the workspace.
-After panel customization, `app.tablePanel` (including Shift+F9) still toggles the
-Table panel. `ui.set` with `closePanel` closes the last explicitly opened panel;
-`dockExpanded:false` hides the root dock while floating groups remain visible.
-The icon rail can reopen a collapsed dock through any root panel. Activating a
-floating panel also raises its group. These operations change only UI layout.
+`app.tablePanel` (including Shift+F9) toggles the Table panel. `ui.set` with `closePanel`
+closes the last explicitly opened panel; `dockExpanded:false` collapses every dock column
+to icons and `dockExpanded:true` expands the outer column. Activating a floating panel also
+raises its group. These operations change only UI layout.
+
+`ui.docking` returns the panel layout in use; `ui.inspect` includes the same object as
+`docking`:
+
+```json
+{"layout": {"root": {"Split": {"axis": "Horizontal", "size": {"FixedSecond": 297.0},
+ "first": {"Tabs": {"panels": ["canvas"], "active": 0}},
+ "second": {"Dock": {"side": "End", "columns": [
+ {"groups": [{"panels": ["properties", "pages", "layers"], "active": 0}], "width": 260.0,
+ "iconic": false, "iconic_width": 37.0},
+ {"groups": [{"panels": ["stroke"], "active": 0}, …], "width": 260.0, "iconic": true,
+ "iconic_width": 37.0}]}}}},
+ "floating": []},
+ "customized": false, "focused": "canvas", "rightToLeft": false, "hidden": []}
+```
+
+`layout` is craft-ui's serialized `Layout`; `customized` is false while the workspace's
+default layout is in use; `focused` is the panel (or `canvas`) last clicked or selected, or
+null; `hidden` lists closed panels that remember their place.