Merge pull request #8666 from storytold/train/carry7652

Tools: add an optional compact layout (#7652)
This commit is contained in:
BFlat
2026-11-19 15:21:03 +07:00
committed by GitHub
13 changed files with 449 additions and 16 deletions
+6
View File
@@ -571,6 +571,12 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"{double?: bool, toolbar?: name} show the toolbar's tools (with `toolbar`, that toolbar made with New Toolbar's) in two columns (true), one (false) or toggle (omitted), as the double arrow at the top of the toolbar does; returns the new state",
),
("window.toolbarAdvanced", "Toolbar: Advanced / Basic", "", "{}"),
(
"window.toolbarCompact",
"Compact Tools",
"",
"{on?: bool} use smaller tool cells and a narrower main Tools panel (true), restore its regular spacing (false), or toggle (omitted or null); the choice starts off and is kept with the workspace, independently of one/two columns and Basic/Advanced or edited tools. Tool icons and footer controls keep their size; tool flyouts, torn-off groups and named custom toolbars keep their spacing. A value other than true, false or null is an error and changes nothing; returns the new state",
),
(
"window.toolsBesideCanvas",
"Keep Tools Beside the Canvas",
+4 -2
View File
@@ -686,14 +686,16 @@ pub fn sync(ui: &UiState) {
}
}
/// Window › Toolbars: Advanced, Double Column and Keep Tools Beside the Canvas, the toolbars made
/// with New Toolbar (each checked while it shows), New Toolbar… and Manage Toolbars….
/// Window › Toolbars: Advanced, Double Column, Compact Tools and Keep Tools Beside the Canvas,
/// the toolbars made with New Toolbar (each checked while it shows), New Toolbar… and Manage
/// Toolbars….
pub fn menu_items() -> Vec<crate::menus::Item> {
use crate::menus::Item;
let c = |label: &'static str, id: &'static str| Item::Cmd(label, id, Value::Null);
let mut v = vec![
c("Advanced", "window.toolbarAdvanced"),
c("Double Column", "window.toolbarColumns"),
c("Compact Tools", "window.toolbarCompact"),
c("Keep Tools Beside the Canvas", "window.toolsBesideCanvas"),
Item::Sep,
];
+5
View File
@@ -576,6 +576,11 @@ fn run_ui_part5(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<
}
}
"window.toolbar" => flag(&mut app.ui.toolbar),
"window.toolbarCompact" => opt_bool(p, "on").map(|on| {
let on = on.unwrap_or(!app.ui.toolbar_compact);
app.ui.toolbar_compact = on;
json!(on)
}),
"window.toolbarColumns" => {
let toolbar = match crate::custom_toolbars::target(&app.ui, p) {
Ok(t) => t,
+1
View File
@@ -73,6 +73,7 @@ pub fn checked(app: &VectorcraftApp, id: &str, p: &Value) -> Option<bool> {
.is_some_and(|g| crate::chrome::CONTROL_BAR_GROUPS.contains(&g) && !app.ui.control_bar_hidden_groups.contains(g)),
"window.toolbar" => app.ui.toolbar,
"window.toolbarAdvanced" => app.ui.toolbar_advanced,
"window.toolbarCompact" => app.ui.toolbar_compact,
"window.toolsBesideCanvas" => app.ui.tools_beside_canvas,
"window.toolbarColumns" => match p.get("toolbar").and_then(Value::as_str) {
None => app.ui.toolbar_double,
+6
View File
@@ -572,6 +572,12 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"{double?: bool, toolbar?: name} show the toolbar's tools (with `toolbar`, that toolbar made with New Toolbar's) in two columns (true), one (false) or toggle (omitted), as the double arrow at the top of the toolbar does; returns the new state",
),
("window.toolbarAdvanced", "Toolbar: Advanced / Basic", "", "{}"),
(
"window.toolbarCompact",
"Compact Tools",
"",
"{on?: bool} use smaller tool cells and a narrower main Tools panel (true), restore its regular spacing (false), or toggle (omitted or null); the choice starts off and is kept with the workspace, independently of one/two columns and Basic/Advanced or edited tools. Tool icons and footer controls keep their size; tool flyouts, torn-off groups and named custom toolbars keep their spacing. A value other than true, false or null is an error and changes nothing; returns the new state",
),
(
"window.toolsBesideCanvas",
"Keep Tools Beside the Canvas",
+4
View File
@@ -473,6 +473,9 @@ pub struct UiState {
pub control_bar_hidden_groups: std::collections::BTreeSet<String>,
pub toolbar: bool,
pub toolbar_double: bool,
/// Smaller cells and panel width for the main Tools panel, independent of its column count.
#[serde(default)]
pub toolbar_compact: bool,
/// Advanced toolbar (every tool group) instead of the categorized Basic toolbar.
#[serde(default)]
pub toolbar_advanced: bool,
@@ -1236,6 +1239,7 @@ impl Default for UiState {
control_bar_hidden_groups: Default::default(),
toolbar: true,
toolbar_double: false,
toolbar_compact: false,
toolbar_advanced: false,
task_bar: true,
task_bar_place: TaskBarPlace::default(),
+24 -9
View File
@@ -112,8 +112,22 @@ pub(crate) fn docked_rect_id() -> egui::Id {
egui::Id::unique("toolbar-docked-rect")
}
fn panel_width(ui: &crate::state::UiState) -> f32 {
if ui.toolbar_double { 80.0 } else { WIDTH }
/// Geometry of the main Tools panel only; flyouts and custom toolbars keep their own metrics.
struct ToolsMetrics {
cell: egui::Vec2,
well: egui::Vec2,
panel_width: f32,
}
fn main_metrics(ui: &crate::state::UiState) -> ToolsMetrics {
let (cell, well) = if ui.toolbar_compact { (vec2(30.0, 25.0), vec2(26.0, 23.0)) } else { (vec2(36.0, PITCH - 1.0), vec2(30.0, 27.5)) };
let panel_width = match (ui.toolbar_compact, ui.toolbar_double) {
(false, false) => WIDTH,
(false, true) => 80.0,
(true, false) => 44.0,
(true, true) => 76.0,
};
ToolsMetrics { cell, well, panel_width }
}
/// Space reserved inside the protected canvas panel for a visible Tools panel docked beside the
@@ -121,7 +135,7 @@ fn panel_width(ui: &crate::state::UiState) -> f32 {
/// none while Tools docks at the window's left edge.
pub(crate) fn docked_width(ui: &crate::state::UiState) -> f32 {
if (ui.tools_beside_canvas || ui.toolbar_right) && ui.toolbar && ui.screen_mode < 3 && ui.toolbar_pos.is_none() {
panel_width(ui) + 6.0
main_metrics(ui).panel_width + 6.0
} else {
0.0
}
@@ -157,9 +171,9 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let t = Tokens::get(ui.ctx());
// The user's choice alone: a window too short for the tools scrolls them.
let cols = if app.ui.toolbar_double { 2 } else { 1 };
// Two 36 pt buttons with 2 pt either side inside the border and separator line (at 76 they
// overran the right border).
let w = panel_width(&app.ui);
// Regular: two 36 pt cells need 80 pt to fit the frame. Compact: 30 pt cells fit in 76 pt,
// leaving room for the unchanged 66 pt drawing-mode footer and the frame.
let w = main_metrics(&app.ui).panel_width;
match app.ui.toolbar_pos {
None => {
// The card's outer gap faces the edge it docks at.
@@ -219,6 +233,7 @@ pub fn show_custom(app: &mut VectorcraftApp, ctx: &egui::Context) {
fn body(app: &mut VectorcraftApp, ui: &mut Ui, cols: usize, floating: Option<egui::Pos2>) {
let t = Tokens::get(ui.ctx());
let all = slots(app);
let metrics = main_metrics(&app.ui);
let bounds = ui.max_rect();
let editing = app.ui.tools_drawer && app.ui.drawer_toolbar.is_none();
ui.spacing_mut().item_spacing = vec2(0.0, 0.0);
@@ -292,14 +307,14 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui, cols: usize, floating: Option<egu
// Centred on the panel's inside (`bounds`: within its border and, docked, the
// separator line egui reserves on its right), not on `WIDTH`, which sat them 2½ pt
// right of centre docked; nor on this row, which the scroll area starts ½ pt in.
ui.add_space((bounds.center().x - cols as f32 * 18.0 - ui.cursor().min.x).max(0.0));
ui.add_space((bounds.center().x - cols as f32 * (metrics.cell.x / 2.0) - ui.cursor().min.x).max(0.0));
for &k in &row {
let slot = &all[k].1;
let Some(shown) = tool_info(shown_tool(app, slot)).or_else(|| tool_info(slot[0])) else { continue };
let is_active = slot.contains(&active);
let (rect, resp) = ui.allocate_exact_size(vec2(36.0, PITCH - 1.0), Sense::click_and_drag());
let (rect, resp) = ui.allocate_exact_size(metrics.cell, Sense::click_and_drag());
crate::palette::note_spot(ui, rect, || crate::palette::SpotAt::Slot(None, slot.iter().map(|s| s.to_string()).collect()));
let well = egui::Rect::from_center_size(rect.center(), vec2(30.0, 27.5));
let well = egui::Rect::from_center_size(rect.center(), metrics.well);
if is_active {
ui.painter().rect_filled(well, CornerRadius::same(6), t.tool_active);
} else if resp.hovered() {
+4
View File
@@ -38,6 +38,8 @@ pub struct Workspace {
pub rulers: bool,
pub toolbar: bool,
pub toolbar_double: bool,
/// Compact main Tools spacing (built-in and older workspaces: regular).
pub toolbar_compact: bool,
pub toolbar_advanced: bool,
pub task_bar: bool,
pub dock: bool,
@@ -203,6 +205,7 @@ pub fn capture(ui: &UiState, name: &str) -> Workspace {
rulers: ui.view.rulers,
toolbar: ui.toolbar,
toolbar_double: ui.toolbar_double,
toolbar_compact: ui.toolbar_compact,
toolbar_advanced: ui.toolbar_advanced,
task_bar: ui.task_bar,
dock: ui.dock,
@@ -241,6 +244,7 @@ pub fn apply(ui: &mut UiState, w: &Workspace) {
ui.view.rulers = w.rulers;
ui.toolbar = w.toolbar;
ui.toolbar_double = w.toolbar_double;
ui.toolbar_compact = w.toolbar_compact;
ui.toolbar_advanced = w.toolbar_advanced;
ui.task_bar = w.task_bar;
ui.dock = w.dock;
+384
View File
@@ -0,0 +1,384 @@
//! Optional compact main Tools layout preserves the tools while using less room.
// Tests may unwrap/panic (AGENTS.md, Robustness).
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use std::sync::Mutex;
use egui::{Event, Pos2, Rect, vec2};
use serde_json::json;
use vectorcraft_engine::Session;
use vectorcraft_ui_egui::{UiState, VectorcraftApp, i18n, theme, toolbar};
static CASE: Mutex<()> = Mutex::new(());
struct Language(i18n::Lang);
impl Language {
fn english() -> Self {
let previous = Self(i18n::current());
i18n::set_current(i18n::Lang::from_code("en").unwrap());
previous
}
}
impl Drop for Language {
fn drop(&mut self) {
i18n::set_current(self.0);
}
}
fn near(a: f32, b: f32) -> bool {
(a - b).abs() < 0.01
}
fn main_toolbar_app(double: bool, compact: Option<bool>) -> VectorcraftApp {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 300, "profile": null})).unwrap();
app.run("prefs.set", json!({"key": "toolGroupLabels", "value": false})).unwrap();
let mut state = serde_json::to_value(&app.ui).unwrap();
state["toolbar_double"] = json!(double);
match compact {
Some(on) => state["toolbar_compact"] = json!(on),
None => {
state.as_object_mut().unwrap().remove("toolbar_compact");
}
}
// The old UiState reader ignores this future field; no future Rust field is referenced.
app.ui = serde_json::from_value::<UiState>(state).unwrap();
app
}
#[derive(Clone, Debug)]
struct ToolbarGeometry {
tools: Vec<String>,
cells: Vec<Rect>,
row_pitch: Option<f32>,
column_pitch: Option<f32>,
panel_width: f32,
}
fn pitch(mut centers: Vec<f32>) -> Option<f32> {
centers.sort_by(f32::total_cmp);
centers.dedup_by(|a, b| near(*a, *b));
centers.windows(2).map(|p| p[1] - p[0]).filter(|d| *d > 0.01).min_by(f32::total_cmp)
}
fn tool_ids(nodes: &[egui::accesskit::Node]) -> Vec<String> {
let mut ids: Vec<String> = nodes
.iter()
.filter(|n| n.role() == egui::accesskit::Role::Button && n.toggled().is_some())
.filter_map(|n| {
let label = n.label()?;
vectorcraft_tools::TOOL_GROUPS
.iter()
.flat_map(|group| group.iter())
.find_map(|tool| (label == tool.label || label.starts_with(&format!("{} (", tool.label))).then(|| tool.id.to_string()))
})
.collect();
ids.sort();
ids
}
struct ToolbarFrames {
app: VectorcraftApp,
ctx: egui::Context,
time: f64,
height: f32,
nodes: Vec<egui::accesskit::Node>,
}
impl ToolbarFrames {
fn new(app: VectorcraftApp, height: f32) -> Self {
let ctx = egui::Context::default();
ctx.enable_accesskit();
theme::install_fonts(&ctx);
theme::apply(&ctx, theme::Brightness::MediumDark);
Self { app, ctx, time: 0.0, height, nodes: vec![] }
}
fn frame(&mut self, events: Vec<Event>) -> ToolbarGeometry {
self.time += 0.05;
let input = egui::RawInput {
time: Some(self.time),
events,
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(400.0, self.height))),
..Default::default()
};
let ctx = self.ctx.clone();
let mut panel_width = 0.0;
let mut output = ctx.run_ui(input, |ui| {
let before = ui.available_rect_before_wrap();
toolbar::show(&mut self.app, ui);
panel_width = before.width() - ui.available_rect_before_wrap().width();
});
if let Some(update) = output.platform_output.accesskit_update.take() {
self.nodes = update.nodes.into_iter().map(|(_, node)| node).collect();
}
output.textures_delta.clear();
// These are actual allocated widgets, not computed layout expectations. Both sizes are
// accepted so old source can finish every requested measurement before primary assertions.
let mut cells: Vec<Rect> = ctx.viewport(|vp| {
vp.prev_pass
.widgets
.layers()
.flat_map(|(_, widgets)| widgets.iter())
.filter(|w| {
let s = w.rect.size();
(near(s.x, 36.0) && near(s.y, 29.0)) || (near(s.x, 30.0) && near(s.y, 25.0))
})
.map(|w| w.rect)
.collect()
});
cells.sort_by(|a, b| a.top().total_cmp(&b.top()).then(a.left().total_cmp(&b.left())));
ToolbarGeometry {
tools: tool_ids(&self.nodes),
row_pitch: pitch(cells.iter().map(|r| r.center().y).collect()),
column_pitch: pitch(cells.iter().map(|r| r.center().x).collect()),
cells,
panel_width,
}
}
fn settled(&mut self) -> ToolbarGeometry {
self.frame(vec![]);
self.frame(vec![]);
self.frame(vec![])
}
}
#[test]
fn compact_tools_reduce_both_axes_and_reserved_panel_width() {
let _case = CASE.lock().unwrap_or_else(|e| e.into_inner());
let _language = Language::english();
let mut observations = vec![];
for double in [false, true] {
let regular = ToolbarFrames::new(main_toolbar_app(double, Some(false)), 1600.0).settled();
let compact = ToolbarFrames::new(main_toolbar_app(double, Some(true)), 1600.0).settled();
observations.push((double, regular, compact));
}
// Both one/two-column layouts have actually drawn before a missing feature can fail.
println!("actual regular/compact main Tools geometry: {observations:#?}");
for (double, regular, compact) in observations {
assert!(regular.cells.len() > 10 && !regular.tools.is_empty(), "actual Tools widgets and IDs were measured: {regular:?}");
assert_eq!(compact.tools, regular.tools, "the same usual tools remain, double={double}");
assert_eq!(compact.cells.len(), regular.cells.len(), "tool-button count, double={double}");
assert!(compact.row_pitch.unwrap() < regular.row_pitch.unwrap(), "compact must reduce vertical pitch, double={double}: {compact:?}");
if double {
assert!(compact.column_pitch.unwrap() < regular.column_pitch.unwrap(), "compact must reduce the inter-column pitch: {compact:?}");
} else {
assert!(compact.column_pitch.is_none());
}
assert!(compact.panel_width < regular.panel_width, "compact must reserve less real panel width, double={double}: {compact:?}");
assert!(compact.cells.iter().all(|r| near(r.width(), 30.0) && near(r.height(), 25.0)));
}
}
#[test]
fn compact_tools_default_and_explicit_false_keep_the_comfortable_layout() {
let _case = CASE.lock().unwrap_or_else(|e| e.into_inner());
let _language = Language::english();
for double in [false, true] {
let missing = ToolbarFrames::new(main_toolbar_app(double, None), 1600.0).settled();
let off = ToolbarFrames::new(main_toolbar_app(double, Some(false)), 1600.0).settled();
assert!(missing.cells.len() > 10 && !missing.tools.is_empty());
assert_eq!(missing.tools, off.tools);
assert_eq!(missing.cells, off.cells, "omitted and false keep exactly the same button geometry");
assert!(missing.cells.iter().all(|r| near(r.width(), 36.0) && near(r.height(), 29.0)));
assert!(near(missing.row_pitch.unwrap(), 29.0), "{missing:?}");
assert_eq!(missing.column_pitch.is_some(), double);
if double {
assert!(near(missing.column_pitch.unwrap(), 36.0), "{missing:?}");
}
assert!(near(missing.panel_width, if double { 86.0 } else { 54.0 }), "the current panel plus its 6pt outer frame: {missing:?}");
assert!(near(missing.panel_width, off.panel_width));
}
}
// Additional public controls. The root-formatted two-case baseline above remains an exact prefix.
fn compact_value(app: &VectorcraftApp) -> bool {
serde_json::to_value(&app.ui).unwrap()["toolbar_compact"].as_bool().unwrap_or(false)
}
fn access_rect(node: &egui::accesskit::Node) -> Option<Rect> {
let r = node.bounds()?;
Some(Rect::from_min_max(egui::pos2(r.x0 as f32, r.y0 as f32), egui::pos2(r.x1 as f32, r.y1 as f32)))
}
impl ToolbarFrames {
fn named_rect(&self, label: &str) -> Rect {
self.nodes.iter().find(|n| n.label() == Some(label)).and_then(access_rect).unwrap_or_else(|| panic!("{label} is drawn"))
}
fn tool_rect(&self, tool: &str) -> Rect {
let name = vectorcraft_tools::tool_info(tool).unwrap().label;
self.nodes
.iter()
.find(|n| {
n.role() == egui::accesskit::Role::Button
&& n.toggled().is_some()
&& n.label().is_some_and(|l| l == name || l.starts_with(&format!("{name} (")))
})
.and_then(access_rect)
.unwrap_or_else(|| panic!("tool {tool} is drawn"))
}
fn click_at(&mut self, at: Pos2, button: egui::PointerButton) {
let event = |pressed| Event::PointerButton { pos: at, button, pressed, modifiers: egui::Modifiers::NONE };
self.frame(vec![Event::ModifiersChanged(egui::Modifiers::NONE), Event::PointerMoved(at), event(true)]);
self.frame(vec![event(false)]);
self.frame(vec![]);
}
}
#[test]
fn compact_tools_toggle_roundtrip_and_columns_keep_the_selected_tool() {
let _case = CASE.lock().unwrap_or_else(|e| e.into_inner());
let _language = Language::english();
let mut app = main_toolbar_app(false, None);
app.select_tool("pen");
assert_eq!(app.run("window.toolbarCompact", json!({})).unwrap(), true);
assert!(compact_value(&app));
assert_eq!(app.run("window.toolbarCompact", json!({"on": true})).unwrap(), true);
app.run("window.toolbarColumns", json!({"double": true})).unwrap();
assert!(compact_value(&app) && app.ui.toolbar_double);
assert_eq!(app.session.tool_id(), "pen");
app.ui = serde_json::from_value::<UiState>(serde_json::to_value(&app.ui).unwrap()).unwrap();
assert!(compact_value(&app) && app.ui.toolbar_double, "saved preferences keep both independent choices");
let mut frames = ToolbarFrames::new(app, 1600.0);
let compact = frames.settled();
assert!(compact.cells.iter().all(|r| near(r.width(), 30.0) && near(r.height(), 25.0)));
assert_eq!(frames.app.session.tool_id(), "pen");
assert_eq!(frames.app.run("window.toolbarCompact", json!({})).unwrap(), false);
assert!(!compact_value(&frames.app));
assert_eq!(frames.app.run("window.toolbarCompact", json!({"on": false})).unwrap(), false);
let regular = frames.settled();
assert!(regular.cells.iter().all(|r| near(r.width(), 36.0) && near(r.height(), 29.0)));
assert_eq!(compact.tools, regular.tools);
assert!(frames.app.ui.toolbar_double);
assert_eq!(frames.app.session.tool_id(), "pen");
}
#[test]
fn compact_tools_actual_buttons_flyout_and_short_window_footer_work() {
let _case = CASE.lock().unwrap_or_else(|e| e.into_inner());
let _language = Language::english();
let mut frames = ToolbarFrames::new(main_toolbar_app(true, Some(true)), 1000.0);
frames.settled();
let pen = frames.tool_rect("pen").center();
frames.click_at(pen, egui::PointerButton::Primary);
assert_eq!(frames.app.session.tool_id(), "pen", "an actual compact tool hit target selects the tool");
let rectangle = frames.tool_rect("rectangle").center();
frames.click_at(rectangle, egui::PointerButton::Secondary);
assert!(frames.app.ui.flyout.is_some());
let flyout = frames.ctx.memory(|m| m.area_rect(egui::Id::unique("tool-flyout"))).unwrap();
assert!(flyout.width() > 30.0 && flyout.height() > 25.0, "the actual grouped-tool flyout is drawn");
// A separate normal short window avoids retaining the flyout over the footer interaction.
let mut short = ToolbarFrames::new(main_toolbar_app(true, Some(true)), 420.0);
let top = short.settled();
let before = short.named_rect("Edit Toolbar");
assert!(before.bottom() > short.height, "this ordinary window actually needs scrolling: {before:?}");
short.frame(vec![
Event::PointerMoved(top.cells[0].center()),
Event::MouseWheel {
unit: egui::MouseWheelUnit::Point,
delta: vec2(0.0, -2000.0),
phase: egui::TouchPhase::Move,
modifiers: egui::Modifiers::NONE,
source: egui::MouseWheelSource::Unknown,
},
]);
for _ in 0..24 {
short.frame(vec![]);
}
let edit = short.named_rect("Edit Toolbar");
assert!(edit.top() >= 0.0 && edit.bottom() <= short.height, "the actual footer scrolls into view: {edit:?}");
let header = short.named_rect("Toggle single/double column");
for label in ["Draw Normal (Shift+D)", "Draw Behind (Shift+D)", "Draw Inside (Shift+D)"] {
let r = short.named_rect(label);
assert!(
r.left() >= header.left() - 0.01 && r.right() <= header.right() + 0.01,
"footer fits within compact panel: {label} {r:?} in {header:?}"
);
}
let behind = short.named_rect("Draw Behind (Shift+D)").center();
short.click_at(behind, egui::PointerButton::Primary);
assert_eq!(short.app.session.draw_mode, vectorcraft_engine::DrawMode::Behind);
let edit = short.named_rect("Edit Toolbar").center();
short.click_at(edit, egui::PointerButton::Primary);
assert!(short.app.ui.tools_drawer, "the real footer button opens Edit Toolbar");
}
#[test]
fn compact_tools_advanced_and_edited_layouts_keep_their_tool_sets() {
let _case = CASE.lock().unwrap_or_else(|e| e.into_inner());
let _language = Language::english();
for advanced in [true, false] {
let mut observations = vec![];
for compact in [false, true] {
let mut app = main_toolbar_app(true, Some(compact));
if advanced {
app.run("window.toolbarAdvanced", json!({})).unwrap();
} else {
app.run("toolbar.removeTool", json!({"tool": "selection"})).unwrap();
}
observations.push(ToolbarFrames::new(app, 1600.0).settled());
}
let regular = &observations[0];
let compact = &observations[1];
assert_eq!(regular.tools, compact.tools, "same Advanced/edited tool IDs, advanced={advanced}");
assert_eq!(regular.cells.len(), compact.cells.len());
assert!(compact.row_pitch.unwrap() < regular.row_pitch.unwrap());
assert!(compact.column_pitch.unwrap() < regular.column_pitch.unwrap());
assert!(compact.panel_width < regular.panel_width);
if !advanced {
assert!(!compact.tools.iter().any(|id| id == "selection"), "the user's main-toolbar edit remains");
}
}
}
#[test]
fn compact_tools_do_not_resize_named_toolbars_or_torn_off_strips() {
let _case = CASE.lock().unwrap_or_else(|e| e.into_inner());
let _language = Language::english();
let mut app = main_toolbar_app(false, Some(false));
app.run("window.toolbar.new", json!({"name": "Named"})).unwrap();
for tool in ["pen", "rectangle", "selection"] {
app.run("toolbar.addTool", json!({"tool": tool, "toolbar": "Named"})).unwrap();
}
app.run("window.floatTools", json!({"tool": "rectangle", "floating": true})).unwrap();
let mut frames = ToolbarFrames::new(app, 1000.0);
frames.settled();
// Existing observable egui Area IDs, matching the production areas; no private helper import.
let named_id = egui::Id::unique(("custom-toolbar", "named".to_string()));
let strip_id = egui::Id::unique(("tool-floating", "rectangle"));
let before = frames.ctx.memory(|m| (m.area_rect(named_id).unwrap().size(), m.area_rect(strip_id).unwrap().size()));
frames.app.run("window.toolbarCompact", json!({"on": true})).unwrap();
frames.settled();
let after = frames.ctx.memory(|m| (m.area_rect(named_id).unwrap().size(), m.area_rect(strip_id).unwrap().size()));
assert_eq!(before, after, "the main Tools choice must not shrink the shared strip pitch or named-toolbar buttons");
}
#[test]
fn compact_tools_workspace_roundtrip_restores_density_and_legacy_defaults() {
use vectorcraft_ui_egui::workspaces;
let _case = CASE.lock().unwrap_or_else(|e| e.into_inner());
let _language = Language::english();
let mut app = main_toolbar_app(true, Some(true));
app.select_tool("pen");
let workspace = workspaces::capture(&app.ui, "Compact drawing");
let saved = serde_json::to_value(workspace).unwrap();
assert_eq!(saved["toolbarCompact"], true, "Workspace uses its existing camelCase wire convention");
let restored: workspaces::Workspace = serde_json::from_value(saved.clone()).unwrap();
app.run("window.toolbarCompact", json!({"on": false})).unwrap();
app.run("window.toolbarColumns", json!({"double": false})).unwrap();
workspaces::apply(&mut app.ui, &restored);
assert!(compact_value(&app) && app.ui.toolbar_double, "applying the saved workspace restores both layout choices");
assert_eq!(app.session.tool_id(), "pen", "workspace layout does not select another tool");
let mut legacy = saved;
legacy.as_object_mut().unwrap().remove("toolbarCompact");
let legacy: workspaces::Workspace = serde_json::from_value(legacy).unwrap();
workspaces::apply(&mut app.ui, &legacy);
assert!(!compact_value(&app), "a workspace saved before this option restores the Comfortable default");
assert!(app.ui.toolbar_double, "the older saved column choice is retained");
assert_eq!(app.session.tool_id(), "pen");
}
+1
View File
@@ -757,6 +757,7 @@ macOS cursor delivery (#2292) is narrowed to a native host adapter using the exi
were made in, and Window › Toolbars › Manage Toolbars renames, copies and deletes them; they dock in lanes along
the window's left and right edges (`window.toolbar.dock`, `window.toolbar.float`).
Inside the estimate below.
- **Done (#7234):** Window > Toolbars > Compact Tools offers denser spacing and a narrower main Tools panel in one or two columns, docked or floating. The choice is remembered for Basic, Advanced and edited layouts without changing the selected tool, usual icon size or footer controls. The existing layout remains the default; named custom toolbars and tool flyouts retain their spacing. The G7 estimate is unchanged.
- **Done (#1753):** a saved workspace keeps the width of the dock column.
- **Done (#4135):** floating panels open in OS windows of their own on the desktop, so they can sit on another monitor; on the web and on Wayland they float inside the window.
- **Done:** View › New View… and Edit Views… ([public source](https://helpx.adobe.com/illustrator/using/viewing-artwork.html)): a document keeps up to 25 named views (zoom, centre and rotation), saved with the file; every one is listed by name at the bottom of the View menu (`view.goto1`–`view.goto25`), and choosing one changes the current window to it. Edit Views… lists them to rename or delete, applied together on OK as one undo step (`view.saved.edit {edits}`); a file's views are checked when it opens. Estimate unchanged.
+2 -2
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+4 -2
View File
File diff suppressed because one or more lines are too long