mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 19:36:16 +00:00
Toolbars: Dock Toolbar and Float Toolbar run again on the dock
window.toolbar.dock and window.toolbar.float were still listed in the command catalogs, but the move to the framework dock removed their handlers, so both returned "unknown command". - window.toolbar.dock docks a toolbar made with New Toolbar as a column of the left or right edge's dock, at the column `order` asks for. Without `side` it uses the edge it docks at, else the edge of the docked panel it left, else the left. - window.toolbar.float floats it at x, y, or as the dock floats a panel. - A hidden toolbar that either command shows brings back the groups torn off it, and both commands end a Tab hide. - window.toolbar.list reports that same edge for a floating toolbar instead of always "left". - place_floating moves an open OS window's record with its rect, as float_actions does. Docs: the params text in both catalogs, docs/mcp.md and docs/control-protocol.md describe dock columns instead of lanes.
This commit is contained in:
@@ -658,19 +658,19 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"window.toolbar.dock",
|
||||
"Dock Toolbar",
|
||||
"",
|
||||
"{name: string, side?: left|right, order?: int} dock the toolbar made with New Toolbar called `name` in the lane along the window's left or right edge (omitted: the edge it docked at last, the left at first), as Dock to Left and Dock to Right in its title bar's context menu and dropping its title bar on that edge do; `order` is its place in that edge's stack, 0 at the top (omitted: the end, or where it is when it is docked at that edge already); a bad `side` or `order` is an error and changes nothing; returns {toolbar, floating, side, order, pos}",
|
||||
"{name: string, side?: left|right, order?: int} dock the toolbar made with New Toolbar called `name` as a column of the dock along the window's left or right edge (omitted: the edge it docks at, else the edge it docked at last, the left at first), as dragging its title bar to that edge does; a hidden toolbar shows; `order` is its column's place in that edge's dock, 0 at the window's edge (omitted: the innermost, or where it is when it docks at that edge already); a bad `side` or `order` is an error and changes nothing; returns {toolbar, floating, side, order, pos}, `pos` its top-left corner while it floats (else null)",
|
||||
),
|
||||
(
|
||||
"window.toolbar.float",
|
||||
"Float Toolbar",
|
||||
"",
|
||||
"{name: string, x?: number, y?: number} float the toolbar made with New Toolbar called `name` with its top-left corner at x, y in screen points (both or neither; omitted: where it floated last), as Float Toolbar in its title bar's context menu and dragging its title bar out of its lane do; returns {toolbar, floating, side, order, pos}",
|
||||
"{name: string, x?: number, y?: number} float the toolbar made with New Toolbar called `name` with its top-left corner at x, y in window points (both or neither, each from -1000000 to 1000000; omitted: where the dock floats a panel, and a floating toolbar stays where it is), as dragging its title bar out of the dock does; a hidden toolbar shows; returns {toolbar, floating, side, order, pos}",
|
||||
),
|
||||
(
|
||||
"window.toolbar.list",
|
||||
"List Toolbars",
|
||||
"",
|
||||
"{} the toolbars made with New Toolbar in the current workspace: [{name, shown, double, slots, floating, side, order}], `side` the edge it docks at (while floating, the edge it docked at last) and `order` its place in that edge's stack while docked (else null)",
|
||||
"{} the toolbars made with New Toolbar in the current workspace: [{name, shown, double, slots, floating, side, order}], `side` the edge it docks at (while floating, the edge it docked at last) and `order` its column's place in that edge's dock, 0 at the window's edge, while docked (else null)",
|
||||
),
|
||||
("window.taskBar", "Contextual Task Bar", "", "{}"),
|
||||
(
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use craft::behavior::IconId;
|
||||
use craft::behavior::dock::{Action, DockEdge};
|
||||
use craft::behavior::dock::{Action, DockEdge, DockPlacement, Target};
|
||||
use craft::ui::buttons::IconButton;
|
||||
use craft::ui::contract::{PopupKind, Props as _, Show as _, ShowContainer as _, Trigger};
|
||||
use craft::ui::dialog::DialogResult;
|
||||
@@ -345,6 +345,133 @@ fn set_shown(app: &mut VectorcraftApp, name: &str, show: Option<bool>) -> Result
|
||||
Ok(show)
|
||||
}
|
||||
|
||||
// ---------- docking and floating ----------
|
||||
|
||||
/// The window edge and column index from that edge where `panel` docks; none while it floats or is hidden.
|
||||
fn docked_at(ui: &UiState, panel: &str) -> Option<(DockEdge, usize)> {
|
||||
panel_docking::column_of(panel_docking::layout_of(ui), panel).and_then(|(slot, _)| slot)
|
||||
}
|
||||
|
||||
/// The window edge toolbar panel `panel` docks at: while docked, its edge; while it floats or is
|
||||
/// hidden, the edge of the docked panel the dock records it left; else the left edge.
|
||||
fn last_edge(ui: &UiState, panel: &str) -> DockEdge {
|
||||
let ws = &ui.dock_workspace;
|
||||
let left = ws.floated().iter().chain(ws.hidden()).find(|(p, _)| p == panel).and_then(|(_, at)| at.anchor.as_deref());
|
||||
docked_at(ui, panel).or_else(|| left.and_then(|anchor| docked_at(ui, anchor))).map_or(DockEdge::Start, |(edge, _)| edge)
|
||||
}
|
||||
|
||||
/// The `side` param's name of `edge`.
|
||||
fn side_name(edge: DockEdge) -> &'static str {
|
||||
if edge == DockEdge::End { "right" } else { "left" }
|
||||
}
|
||||
|
||||
/// Where toolbar `bar` is: `{toolbar, floating, side, order, pos}`, as `window.toolbar.dock` and
|
||||
/// `window.toolbar.float` return it.
|
||||
fn placement(app: &VectorcraftApp, bar: &str) -> Result<Value, String> {
|
||||
let b = find(&app.ui, bar).ok_or_else(|| format!("no toolbar named `{bar}`"))?;
|
||||
let panel = panel_id(b.id);
|
||||
let docked = docked_at(&app.ui, &panel);
|
||||
let pos = panel_docking::floating_window(panel_docking::layout_of(&app.ui), &panel).map(|w| [w.rect.min.x, w.rect.min.y]);
|
||||
Ok(json!({
|
||||
"toolbar": b.name,
|
||||
"floating": docked.is_none(),
|
||||
"side": side_name(last_edge(&app.ui, &panel)),
|
||||
"order": docked.map(|(_, n)| n),
|
||||
"pos": pos,
|
||||
}))
|
||||
}
|
||||
|
||||
/// `window.toolbar.dock`: docks the toolbar named `name` as a column of the dock on the `side` edge
|
||||
/// (omitted: [`last_edge`]), at column `order` from the window edge (omitted: the innermost, or where it
|
||||
/// is when it docks at that edge already). Bad params are errors and change nothing.
|
||||
fn dock(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
let name = p.get("name").and_then(Value::as_str).ok_or("name (a toolbar's name) is required")?;
|
||||
let bar = find(&app.ui, name).ok_or_else(|| format!("no toolbar named `{name}`"))?;
|
||||
let (id, panel, name) = (bar.id, panel_id(bar.id), bar.name.clone());
|
||||
let edge = match p.get("side") {
|
||||
None | Some(Value::Null) => last_edge(&app.ui, &panel),
|
||||
// `Start` and `End`, as panels take them, too.
|
||||
Some(Value::String(s)) if s.eq_ignore_ascii_case("left") || s.eq_ignore_ascii_case("start") => DockEdge::Start,
|
||||
Some(Value::String(s)) if s.eq_ignore_ascii_case("right") || s.eq_ignore_ascii_case("end") => DockEdge::End,
|
||||
Some(Value::String(s)) => return Err(format!("side is left or right, not `{s}`")),
|
||||
Some(v) => return Err(format!("side is left or right, not `{v}`")),
|
||||
};
|
||||
// A panel of each other column of that edge's dock, from the window edge inwards.
|
||||
let others: Vec<String> = panel_docking::edge_columns(panel_docking::layout_of(&app.ui), edge)
|
||||
.iter()
|
||||
.filter(|c| !c.panels().any(|q| *q == panel))
|
||||
.filter_map(|c| c.panels().next().cloned())
|
||||
.collect();
|
||||
let order = match p.get("order") {
|
||||
None | Some(Value::Null) => None,
|
||||
Some(v) => match v.as_u64().and_then(|n| usize::try_from(n).ok()).filter(|&n| n <= others.len()) {
|
||||
Some(n) => Some(n),
|
||||
None => return Err(format!("order is a whole number from 0 to {}, not `{v}`", others.len())),
|
||||
},
|
||||
};
|
||||
let here = docked_at(&app.ui, &panel).filter(|(e, _)| *e == edge).map(|(_, n)| n);
|
||||
if here.is_none() {
|
||||
// A new innermost column of that edge's dock; a hidden toolbar shows.
|
||||
let hidden = !panel_docking::layout_of(&app.ui).contains(&panel);
|
||||
app.run("window.panel.dock", json!({ "panel": panel, "side": if edge == DockEdge::End { "End" } else { "Start" } }))?;
|
||||
shown_again(app, id, hidden);
|
||||
}
|
||||
let now = docked_at(&app.ui, &panel).map(|(_, n)| n);
|
||||
if let Some(n) = order.filter(|n| Some(*n) != now) {
|
||||
let to = match others.get(n) {
|
||||
Some(anchor) => Target::at(anchor.clone(), DockPlacement::column(false)),
|
||||
None => match others.last() {
|
||||
Some(last) => Target::at(last.clone(), DockPlacement::column(true)),
|
||||
None => return placement(app, &name),
|
||||
},
|
||||
};
|
||||
let ctx = app.ui_ctx.clone();
|
||||
panel_docking::apply(app, ctx.as_ref(), vec![Action::move_panel(panel, to)])?;
|
||||
}
|
||||
// A toolbar where it was asked to go shows too, which ends a Tab hide.
|
||||
panel_docking::show_panels(app);
|
||||
placement(app, &name)
|
||||
}
|
||||
|
||||
/// `window.toolbar.float`: floats the toolbar named `name` with its top-left corner at `x`, `y` in
|
||||
/// window points (both or neither; neither: where the dock floats a panel, and a floating toolbar
|
||||
/// stays where it is).
|
||||
fn float(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
let name = p.get("name").and_then(Value::as_str).ok_or("name (a toolbar's name) is required")?;
|
||||
let bar = find(&app.ui, name).ok_or_else(|| format!("no toolbar named `{name}`"))?;
|
||||
let (id, panel, name) = (bar.id, panel_id(bar.id), bar.name.clone());
|
||||
let coord = |k: &str| match p.get(k) {
|
||||
None | Some(Value::Null) => Some(None),
|
||||
Some(v) => v.as_f64().filter(|f| f.abs() <= 1e6).map(|f| Some(f as f32)),
|
||||
};
|
||||
let at = match (coord("x"), coord("y")) {
|
||||
(Some(Some(x)), Some(Some(y))) => Some(pos2(x, y)),
|
||||
(Some(None), Some(None)) => None,
|
||||
_ => return Err("x and y must both be numbers from -1000000 to 1000000".into()),
|
||||
};
|
||||
let window = panel_docking::floating_window(panel_docking::layout_of(&app.ui), &panel).map(|w| w.rect);
|
||||
let hidden = !panel_docking::layout_of(&app.ui).contains(&panel);
|
||||
match (at, window) {
|
||||
(Some(at), _) => panel_docking::place_floating(app, &panel, at, window.map_or(0.0, |r| r.width()))?,
|
||||
(None, None) => {
|
||||
app.run("window.panel.float", json!({ "panel": panel }))?;
|
||||
}
|
||||
(None, Some(_)) => {}
|
||||
}
|
||||
shown_again(app, id, hidden);
|
||||
// A toolbar floating already shows too, which ends a Tab hide.
|
||||
panel_docking::show_panels(app);
|
||||
placement(app, &name)
|
||||
}
|
||||
|
||||
/// After a command showed toolbar `id`, which was `hidden`, the groups torn off it show again, as
|
||||
/// Show Toolbar brings them back.
|
||||
fn shown_again(app: &mut VectorcraftApp, id: u32, hidden: bool) {
|
||||
if hidden && panel_docking::layout_of(&app.ui).contains(&panel_id(id)) {
|
||||
crate::toolbar::strips_follow(app, &Owner::Toolbar(id), true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens New Toolbar: a name box whose OK is held while the name is refused, the refusal shown under
|
||||
/// the row.
|
||||
fn open_new(app: &mut VectorcraftApp) -> Result<(), String> {
|
||||
@@ -464,6 +591,8 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
|
||||
let name = p.get("name").and_then(Value::as_str).ok_or("name (a toolbar's name) is required")?;
|
||||
delete(app, name).map(|_| Value::Null)
|
||||
})(),
|
||||
"window.toolbar.dock" => dock(app, p),
|
||||
"window.toolbar.float" => float(app, p),
|
||||
"window.toolbar.list" => {
|
||||
let layout = panel_docking::layout_of(&app.ui);
|
||||
Ok(json!(
|
||||
@@ -474,7 +603,6 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
|
||||
let panel = panel_id(b.id);
|
||||
let place = panel_docking::column_of(layout, &panel);
|
||||
let docked = place.as_ref().and_then(|(at, _)| at.as_ref());
|
||||
let side = if matches!(docked, Some((DockEdge::End, _))) { "right" } else { "left" };
|
||||
let double = place.as_ref().is_some_and(|(_, column)| column.steps == Some(2));
|
||||
json!({
|
||||
"name": b.name,
|
||||
@@ -482,7 +610,7 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
|
||||
"double": double,
|
||||
"slots": b.slots,
|
||||
"floating": docked.is_none(),
|
||||
"side": side,
|
||||
"side": side_name(last_edge(&app.ui, &panel)),
|
||||
"order": docked.map(|(_, n)| *n),
|
||||
})
|
||||
})
|
||||
@@ -723,8 +851,9 @@ mod tests {
|
||||
|
||||
/// What hides a toolbar: Window › Tools hides the Tools panel alone and a toolbar still shows, with
|
||||
/// the drawer open for it; a strip torn off a toolbar follows the toolbar and one torn off Tools
|
||||
/// follows Tools; Tab hides the toolbar and a second Tab shows it; making, copying or showing a
|
||||
/// toolbar while Tab hides the panels shows them again, with the other toolbars as they were
|
||||
/// follows Tools; Tab hides the toolbar and a second Tab shows it; making, copying, showing,
|
||||
/// docking or floating a toolbar while Tab hides the panels shows them again, with the other
|
||||
/// toolbars as they were
|
||||
/// (VectorCraft's own rule: showing one does not turn the others off).
|
||||
#[test]
|
||||
fn a_new_toolbar_shows_without_the_tools_panel_until_tab() {
|
||||
@@ -759,11 +888,15 @@ mod tests {
|
||||
assert!(!panel_docking::panels_shown(&app));
|
||||
tab(&mut app, &ctx, 2.0);
|
||||
assert!(panel_docking::panels_shown(&app) && shown(&app, "Mine"));
|
||||
// Made, copied or shown while Tab hides the panels, a toolbar ends the hide.
|
||||
// Made, copied, shown, docked or floated while Tab hides the panels, a toolbar ends the hide.
|
||||
for (k, (command, params)) in [
|
||||
("window.toolbar.new", json!({"name": "Other"})),
|
||||
("window.toolbar.duplicate", json!({"name": "Mine"})),
|
||||
("window.toolbar.custom", json!({"name": "Other", "show": true})),
|
||||
// Floating already, docked, then docked where it is already.
|
||||
("window.toolbar.float", json!({"name": "Mine"})),
|
||||
("window.toolbar.dock", json!({"name": "Mine"})),
|
||||
("window.toolbar.dock", json!({"name": "Mine"})),
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
@@ -978,4 +1111,122 @@ mod tests {
|
||||
assert_eq!(many.len(), MAX);
|
||||
assert_eq!(many.iter().map(|b| b.id).collect::<BTreeSet<_>>().len(), MAX, "every toolbar has an id of its own");
|
||||
}
|
||||
|
||||
/// A hidden toolbar that `window.toolbar.dock` or `window.toolbar.float` shows brings back the
|
||||
/// group torn off it, as Show Toolbar does.
|
||||
#[test]
|
||||
fn docking_or_floating_a_hidden_toolbar_brings_back_its_torn_off_group() {
|
||||
let mut app = app();
|
||||
app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
app.run("toolbar.addTool", json!({"tool": "pen", "toolbar": "Mine"})).unwrap();
|
||||
app.run("toolbar.addTool", json!({"tool": "curvature", "toolbar": "Mine", "slot": 0, "place": "group"})).unwrap();
|
||||
app.run("window.floatTools", json!({"tool": "pen", "toolbar": "Mine"})).unwrap();
|
||||
let id = find(&app.ui, "Mine").unwrap().id;
|
||||
let strip = strip_id(&Owner::Toolbar(id), "pen");
|
||||
let on = |app: &VectorcraftApp| panel_docking::layout_of(&app.ui).contains(&strip);
|
||||
assert!(on(&app));
|
||||
for (command, params) in [
|
||||
("window.toolbar.dock", json!({"name": "Mine"})),
|
||||
("window.toolbar.float", json!({"name": "Mine"})),
|
||||
("window.toolbar.float", json!({"name": "Mine", "x": 40, "y": 50})),
|
||||
] {
|
||||
app.run("window.toolbar.custom", json!({"name": "Mine", "show": false})).unwrap();
|
||||
assert!(!on(&app), "the strip hides with its toolbar");
|
||||
app.run(command, params.clone()).unwrap();
|
||||
assert!(panel_docking::layout_of(&app.ui).contains(&panel_id(id)), "{command} {params} shows the toolbar");
|
||||
assert!(on(&app), "{command} {params} brings the strip back");
|
||||
}
|
||||
}
|
||||
|
||||
/// The dock layout, to compare.
|
||||
fn layout(app: &VectorcraftApp) -> Value {
|
||||
serde_json::to_value(panel_docking::layout_of(&app.ui)).unwrap()
|
||||
}
|
||||
|
||||
/// Where the toolbar named `name` docks: its edge and column from that edge (none: floating).
|
||||
fn dock_place(app: &VectorcraftApp, name: &str) -> Option<(DockEdge, usize)> {
|
||||
docked_at(&app.ui, &panel_id(find(&app.ui, name).unwrap().id))
|
||||
}
|
||||
|
||||
/// `window.toolbar.dock` docks a toolbar at an edge, innermost or at the column asked for, and
|
||||
/// `window.toolbar.float` floats it, at x, y when given; bad params and a toolbar already where
|
||||
/// it is asked to go change nothing, and `window.toolbar.list` reports the same places.
|
||||
#[test]
|
||||
fn toolbars_dock_and_float_by_their_commands() {
|
||||
let mut app = app();
|
||||
for name in ["A", "B", "C"] {
|
||||
app.run("window.toolbar.new", json!({ "name": name })).unwrap();
|
||||
}
|
||||
assert_eq!(dock_place(&app, "A"), None, "New Toolbar floats");
|
||||
let undo = app.session.doc().map_or(0, |d| d.history.undo.len());
|
||||
let r = app.run("window.toolbar.dock", json!({"name": "a"})).unwrap();
|
||||
assert_eq!((&r["toolbar"], &r["floating"], &r["side"], &r["pos"]), (&json!("A"), &json!(false), &json!("left"), &Value::Null));
|
||||
let (edge, a) = dock_place(&app, "A").unwrap();
|
||||
assert_eq!(edge, DockEdge::Start);
|
||||
assert_eq!(r["order"], json!(a));
|
||||
// Each one docked after it goes inside it; one asked to go at A's column goes outside it.
|
||||
app.run("window.toolbar.dock", json!({"name": "B", "side": "left"})).unwrap();
|
||||
let b = dock_place(&app, "B").unwrap().1;
|
||||
assert!(b > dock_place(&app, "A").unwrap().1, "B docks inside A");
|
||||
let at_a = dock_place(&app, "A").unwrap().1;
|
||||
app.run("window.toolbar.dock", json!({"name": "C", "side": "start", "order": at_a})).unwrap();
|
||||
let [c, a, b] = ["C", "A", "B"].map(|n| dock_place(&app, n).unwrap().1);
|
||||
assert!(c < a && a < b, "C goes outside A: {c} {a} {b}");
|
||||
// Docked again at the edge it docks at, with no column asked for, nothing changes.
|
||||
let before = layout(&app);
|
||||
app.run("window.toolbar.dock", json!({"name": "A"})).unwrap();
|
||||
app.run("window.toolbar.dock", json!({"name": "A", "side": "left", "order": a})).unwrap();
|
||||
assert_eq!(layout(&app), before);
|
||||
// Bad params are errors and change nothing.
|
||||
let columns = panel_docking::edge_columns(panel_docking::layout_of(&app.ui), DockEdge::Start).len();
|
||||
for p in [
|
||||
json!({"name": "A", "side": "top"}),
|
||||
json!({"name": "A", "side": 1}),
|
||||
json!({"name": "A", "order": columns}),
|
||||
json!({"name": "A", "order": -1}),
|
||||
json!({"name": "A", "order": 0.5}),
|
||||
json!({"name": "A", "order": "1"}),
|
||||
json!({"name": "Nope"}),
|
||||
json!({}),
|
||||
] {
|
||||
assert!(app.run("window.toolbar.dock", p.clone()).is_err(), "{p}");
|
||||
}
|
||||
for p in [
|
||||
json!({"name": "A", "x": 10}),
|
||||
json!({"name": "A", "x": 1e7, "y": 0}),
|
||||
json!({"name": "A", "x": "1", "y": 2}),
|
||||
json!({"name": "Nope"}),
|
||||
json!({}),
|
||||
] {
|
||||
assert!(app.run("window.toolbar.float", p.clone()).is_err(), "{p}");
|
||||
}
|
||||
assert_eq!(layout(&app), before);
|
||||
// The innermost column asked for: A moves inside B.
|
||||
app.run("window.toolbar.dock", json!({"name": "A", "order": columns - 1})).unwrap();
|
||||
assert!(dock_place(&app, "A").unwrap().1 > dock_place(&app, "B").unwrap().1);
|
||||
// At the right edge.
|
||||
let r = app.run("window.toolbar.dock", json!({"name": "A", "side": "RIGHT"})).unwrap();
|
||||
assert_eq!(r["side"], json!("right"));
|
||||
assert_eq!(dock_place(&app, "A").map(|(e, _)| e), Some(DockEdge::End));
|
||||
// Floated, it remembers the right edge, and docks there again.
|
||||
let r = app.run("window.toolbar.float", json!({"name": "A"})).unwrap();
|
||||
assert_eq!((&r["floating"], &r["side"], &r["order"]), (&json!(true), &json!("right"), &Value::Null));
|
||||
assert!(r["pos"].is_array());
|
||||
let listed = app.run("window.toolbar.list", json!({})).unwrap();
|
||||
let a_row = listed.as_array().unwrap().iter().find(|t| t["name"] == "A").unwrap().clone();
|
||||
assert_eq!((&a_row["floating"], &a_row["side"]), (&json!(true), &json!("right")));
|
||||
// Floating already, with no x, y: it stays where it is.
|
||||
let before = layout(&app);
|
||||
app.run("window.toolbar.float", json!({"name": "A"})).unwrap();
|
||||
assert_eq!(layout(&app), before);
|
||||
let r = app.run("window.toolbar.float", json!({"name": "A", "x": 300, "y": 200})).unwrap();
|
||||
assert_eq!(r["pos"], json!([300.0, 200.0]));
|
||||
assert_eq!(app.run("window.toolbar.dock", json!({"name": "A"})).unwrap()["side"], json!("right"));
|
||||
// A hidden toolbar shows where it is docked or floated to.
|
||||
app.run("window.toolbar.custom", json!({"name": "B", "show": false})).unwrap();
|
||||
app.run("window.toolbar.float", json!({"name": "B", "x": 50, "y": 60})).unwrap();
|
||||
assert!(panel_docking::floating_window(panel_docking::layout_of(&app.ui), &panel_id(find(&app.ui, "B").unwrap().id)).is_some());
|
||||
// Neither command records an undo step.
|
||||
assert_eq!(app.session.doc().map_or(0, |d| d.history.undo.len()), undo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,19 +659,19 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"window.toolbar.dock",
|
||||
"Dock Toolbar",
|
||||
"",
|
||||
"{name: string, side?: left|right, order?: int} dock the toolbar made with New Toolbar called `name` in the lane along the window's left or right edge (omitted: the edge it docked at last, the left at first), as Dock to Left and Dock to Right in its title bar's context menu and dropping its title bar on that edge do; `order` is its place in that edge's stack, 0 at the top (omitted: the end, or where it is when it is docked at that edge already); a bad `side` or `order` is an error and changes nothing; returns {toolbar, floating, side, order, pos}",
|
||||
"{name: string, side?: left|right, order?: int} dock the toolbar made with New Toolbar called `name` as a column of the dock along the window's left or right edge (omitted: the edge it docks at, else the edge it docked at last, the left at first), as dragging its title bar to that edge does; a hidden toolbar shows; `order` is its column's place in that edge's dock, 0 at the window's edge (omitted: the innermost, or where it is when it docks at that edge already); a bad `side` or `order` is an error and changes nothing; returns {toolbar, floating, side, order, pos}, `pos` its top-left corner while it floats (else null)",
|
||||
),
|
||||
(
|
||||
"window.toolbar.float",
|
||||
"Float Toolbar",
|
||||
"",
|
||||
"{name: string, x?: number, y?: number} float the toolbar made with New Toolbar called `name` with its top-left corner at x, y in screen points (both or neither; omitted: where it floated last), as Float Toolbar in its title bar's context menu and dragging its title bar out of its lane do; returns {toolbar, floating, side, order, pos}",
|
||||
"{name: string, x?: number, y?: number} float the toolbar made with New Toolbar called `name` with its top-left corner at x, y in window points (both or neither, each from -1000000 to 1000000; omitted: where the dock floats a panel, and a floating toolbar stays where it is), as dragging its title bar out of the dock does; a hidden toolbar shows; returns {toolbar, floating, side, order, pos}",
|
||||
),
|
||||
(
|
||||
"window.toolbar.list",
|
||||
"List Toolbars",
|
||||
"",
|
||||
"{} the toolbars made with New Toolbar in the current workspace: [{name, shown, double, slots, floating, side, order}], `side` the edge it docks at (while floating, the edge it docked at last) and `order` its place in that edge's stack while docked (else null)",
|
||||
"{} the toolbars made with New Toolbar in the current workspace: [{name, shown, double, slots, floating, side, order}], `side` the edge it docks at (while floating, the edge it docked at last) and `order` its column's place in that edge's dock, 0 at the window's edge, while docked (else null)",
|
||||
),
|
||||
("window.taskBar", "Contextual Task Bar", "", "{}"),
|
||||
(
|
||||
|
||||
@@ -267,7 +267,7 @@ fn dock_columns(layout: &Layout<String>) -> Vec<&Column<String>> {
|
||||
}
|
||||
|
||||
/// The columns of the dock on `edge`, from the window edge inwards; none when that edge has no dock.
|
||||
fn edge_columns(layout: &Layout<String>, edge: DockEdge) -> &[Column<String>] {
|
||||
pub(crate) fn edge_columns(layout: &Layout<String>, edge: DockEdge) -> &[Column<String>] {
|
||||
let dock = layout.dock_path(edge).and_then(|path| node_at(layout.root.as_ref()?, &path));
|
||||
match dock {
|
||||
Some(Node::Dock { columns, .. }) => columns,
|
||||
@@ -1113,14 +1113,18 @@ pub(crate) fn place_floating(app: &mut VectorcraftApp, panel: &str, pos: egui::P
|
||||
}
|
||||
// A rail's window is a stepped column, which the dock fits to the rail's grid; it keeps the steps it had.
|
||||
let steps = is_rail(&id).then(|| column_of(layout, &id).and_then(|(_, column)| column.steps).unwrap_or(1));
|
||||
actions.push(match floating_window(layout, &id) {
|
||||
Some(window) if window.panels().count() == 1 => Action::move_floating(id.clone(), rect),
|
||||
_ => Action::float(id.clone(), rect),
|
||||
});
|
||||
let ctx = app.ui_ctx.clone();
|
||||
match floating_window(layout, &id) {
|
||||
// An open OS window moves with its window: the dock keeps it where its record says.
|
||||
Some(window) if window.panels().count() == 1 => {
|
||||
actions.push(Action::move_floating(id.clone(), rect));
|
||||
actions.extend(native_moved(ctx.as_ref(), window, rect));
|
||||
}
|
||||
_ => actions.push(Action::float(id.clone(), rect)),
|
||||
}
|
||||
if let Some(steps) = steps {
|
||||
actions.push(Action::set_column_steps(id, steps));
|
||||
}
|
||||
let ctx = app.ui_ctx.clone();
|
||||
apply(app, ctx.as_ref(), actions).map(drop)
|
||||
}
|
||||
|
||||
|
||||
@@ -242,6 +242,22 @@ fn an_explicit_float_command_updates_an_existing_native_windows_geometry() {
|
||||
}
|
||||
}
|
||||
|
||||
/// `window.toolbar.float` with x, y moves the OS window a toolbar made with New Toolbar already has.
|
||||
#[test]
|
||||
fn floating_a_toolbar_at_a_point_moves_its_native_window() {
|
||||
let mut h = Harness::new();
|
||||
h.app.run("window.toolbar.new", json!({"name": "Mine"})).unwrap();
|
||||
h.app.run("window.toolbar.float", json!({"name": "Mine", "x": 240, "y": 160})).unwrap();
|
||||
h.frames(3);
|
||||
let panel = crate::custom_toolbars::panel_id(crate::custom_toolbars::find(&h.app.ui, "Mine").unwrap().id);
|
||||
let viewport = h.viewport(&panel);
|
||||
assert_eq!(h.host.borrow().windows[&viewport].rect.min, ORIGIN + vec2(240.0, 160.0));
|
||||
h.app.run("window.toolbar.float", json!({"name": "Mine", "x": 300, "y": 220})).unwrap();
|
||||
h.frames(3);
|
||||
assert_eq!(h.viewport(&panel), viewport);
|
||||
assert_eq!(h.host.borrow().windows[&viewport].rect.min, ORIGIN + vec2(300.0, 220.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keys_typed_in_a_native_window_run_the_main_windows_shortcuts() {
|
||||
let mut h = Harness::new();
|
||||
|
||||
@@ -494,9 +494,8 @@ button (Add Tool…) opens a menu of every tool under the drawer's headings: a c
|
||||
there. `window.floatTools {tool, toolbar}` floats one of its groups, and a group torn off it shows and hides with
|
||||
it. `window.toolbar.list` returns the toolbars (`ui.custom_toolbars` in `ui.inspect`: name, slots, shown flag,
|
||||
two-column flag, top-left corner, the groups torn off it, and `dock` and `dock_right` while docked or once docked).
|
||||
`window.toolbar.dock {name, side?, order?}` docks a toolbar in the lane along the window's left or right edge, and
|
||||
`window.toolbar.float {name, x?, y?}` floats it again; dropping its title bar on an edge or dragging it out of its
|
||||
lane does the same (see the docking section in `docs/mcp.md`). They are kept with the workspace they were made in:
|
||||
`window.toolbar.dock {name, side?, order?}` docks a toolbar as a column of the dock along the window's left or right
|
||||
edge, and `window.toolbar.float {name, x?, y?}` floats it again; dragging its title bar does the same (see the docking section in `docs/mcp.md`). They are kept with the workspace they were made in:
|
||||
switching workspaces shows that workspace's toolbars, Reset Workspace keeps them, and New Workspace starts the new
|
||||
workspace with a copy of them.
|
||||
|
||||
|
||||
+16
-29
@@ -3912,36 +3912,23 @@ the window's edge.
|
||||
|
||||
## Docking toolbars made with New Toolbar
|
||||
|
||||
A toolbar made with New Toolbar floats when it is made. `window.toolbar.dock {name, side?, order?}` (Dock to Left and
|
||||
Dock to Right in the context menu of the toolbar's title bar, remote mode, `invoke_menu`) docks it in a lane along the
|
||||
window's left or right edge. On the left, the lane is right of the Tools panel when the Tools panel is docked at the
|
||||
window's edge. With Keep Tools Beside the Canvas on and the Tools panel docked on the left, the lane is right of the
|
||||
Tools panel beside the canvas, and dropping a title bar on the Tools panel or on the lane docks the toolbar there. `side` is `left` or `right` (`start` and `end` also work); without it, the toolbar docks at the edge it
|
||||
docked at last, or at the left the first time. Toolbars docked at one edge stack from the top. `order` is the
|
||||
toolbar's place in that stack, 0 at the top, from 0 to the number of other toolbars docked there; without it, the
|
||||
toolbar goes at the end, or stays where it is when it is already docked at that edge. Each toolbar takes an equal
|
||||
share of the lane's height and its tools scroll in it, and the lane is as wide as its widest toolbar. When the lane
|
||||
is too short to give each toolbar 88 points of height, the stack wraps into more columns, left to right, and the lane
|
||||
widens, so no toolbar covers another. A lane takes at most half the width the canvas and panels would have (beside
|
||||
the canvas, it also leaves the canvas at least 200 points, and the canvas keeps room for one column); when that
|
||||
many columns still give a toolbar less than 88 points, the toolbars in those columns show only their title bars, which
|
||||
still float, dock and show the context menu. A column too short for all of its title bars shows as many as fit, and
|
||||
the mouse wheel over the column scrolls through the others, one toolbar per notch.
|
||||
`window.toolbar.float {name, x?, y?}` (Float Toolbar in the same menu) floats it with its top-left corner at `x`, `y`
|
||||
in screen points, or where it floated last when both are omitted. Both commands answer
|
||||
`{toolbar, floating, side, order, pos}`: `side` is the edge the toolbar docks at (while it floats, the edge it docked
|
||||
at last), `order` its place in that edge's stack (null while it floats) and `pos` where it floats (while it is docked,
|
||||
where it floated last). A missing or unknown name, a `side` other than left or right, an `order` that is not a whole
|
||||
number in range, or only one of `x` and `y` is an error and changes nothing. `window.toolbar.list` reports `floating`,
|
||||
`side` and `order` for each toolbar.
|
||||
A toolbar made with New Toolbar floats when it is made. `window.toolbar.dock {name, side?, order?}` (remote mode,
|
||||
`invoke_menu`) docks it as a column of the dock along the window's left or right edge, and a hidden toolbar shows.
|
||||
`side` is `left` or `right` (`start` and `end` also work); without it, the toolbar docks at the edge it docks at
|
||||
now, else at the edge of the docked panel it left when it floated or was hidden, else at the left. `order` is the
|
||||
place of the toolbar's column in that edge's dock, 0 at the window's edge, from 0 to the number of the dock's other
|
||||
columns; without it, the toolbar docks as the innermost column, or stays where it is when it already docks at that
|
||||
edge. `window.toolbar.float {name, x?, y?}` floats it with its top-left corner at `x`, `y` in window points, each
|
||||
from -1000000 to 1000000. When both are omitted, the dock floats it as it floats a panel, and a toolbar that floats
|
||||
already stays where it is. Both commands answer `{toolbar, floating, side, order, pos}`: `side` is the edge the
|
||||
toolbar docks at (while it floats or is hidden, the edge `window.toolbar.dock` uses without `side`), `order` its
|
||||
column's place in that edge's dock (null while it floats) and `pos` its top-left corner while it floats (null while it
|
||||
is docked). A missing or unknown name, a `side` other than left or right, an `order` that is not a whole number in
|
||||
range, or only one of `x` and `y` is an error and changes nothing. `window.toolbar.list` reports `floating`, `side`
|
||||
and `order` for each toolbar.
|
||||
|
||||
With the pointer, dropping a floating toolbar's title bar on the window's left or right edge, or on that edge's lane,
|
||||
docks it at the end of that edge's stack; the target lights up while the title bar is dragged over it. Dragging a
|
||||
docked toolbar's title bar out of its lane floats it under the pointer. Escape, or the window losing focus, during
|
||||
the drag puts the toolbar back where it was. Hiding a docked toolbar keeps its place, renaming it keeps its place, a
|
||||
copy made with Manage Toolbars' + floats, and deleting one closes up the stack. Placement is kept with the workspace.
|
||||
Toolbars saved before docking existed load floating. The lanes, the edge targets and the stacking are VectorCraft's
|
||||
own layout rules.
|
||||
Dragging the toolbar's title bar also docks and floats it. Placement is kept with the
|
||||
workspace. These are VectorCraft's own layout rules.
|
||||
|
||||
```json
|
||||
{"name":"invoke_menu","arguments":{"command":"window.toolbar.dock","params":{"name":"Toolbar 1","side":"left","order":0}}}
|
||||
|
||||
Reference in New Issue
Block a user