mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 12:21:08 +01:00
Merge pull request #9363 from dotCooCoo/fix/painting-double-column-tools
Workspaces: Painting shows the Tools panel in two columns again
This commit is contained in:
2 files changed
+55
-5
No files matched your search
@@ -155,6 +155,12 @@ fn rail_owner_among(toolbars: impl Iterator<Item = u32>, id: &str) -> Option<Own
|
||||
/// canvas, and at the end edge the Properties · Layers · Libraries column and the icon column.
|
||||
/// Each of `fronts` comes to the front of the group that holds it.
|
||||
pub(crate) fn default_workspace(fronts: &[&str]) -> Workspace<String> {
|
||||
builtin_workspace(fronts, 1)
|
||||
}
|
||||
|
||||
/// [`default_workspace`] with the Tools panel laying its tools out in `tools_steps` columns, as a
|
||||
/// built-in workspace defines it.
|
||||
pub(crate) fn builtin_workspace(fronts: &[&str], tools_steps: u16) -> Workspace<String> {
|
||||
let mut placed: Vec<String> = Vec::new();
|
||||
let mut group = |ids: &[&str]| {
|
||||
let fresh: Vec<String> = ids.iter().filter(|id| registered(id) && !placed.iter().any(|p| p == *id)).map(|id| (*id).to_owned()).collect();
|
||||
@@ -168,7 +174,7 @@ pub(crate) fn default_workspace(fronts: &[&str]) -> Workspace<String> {
|
||||
if !icons.is_empty() {
|
||||
columns.push(Column::new(icons).with_iconic(true));
|
||||
}
|
||||
let tools = Column::new(vec![Group::new(vec![crate::toolbar::TOOLS.to_owned()], 0)]).with_steps(1);
|
||||
let tools = Column::new(vec![Group::new(vec![crate::toolbar::TOOLS.to_owned()], 0)]).with_steps(tools_steps);
|
||||
let centre = Node::split(Axis::X, BESIDE_DOCK, Node::tabs(vec![CANVAS.to_owned()], 0), Node::dock(DockEdge::End, columns));
|
||||
let root = Node::split(Axis::X, BESIDE_DOCK, Node::dock(DockEdge::Start, vec![tools]), centre);
|
||||
Workspace::new(Layout::new(Some(root), Vec::new()))
|
||||
|
||||
@@ -209,13 +209,23 @@ pub const TOUCH: &str = "Touch";
|
||||
/// The id of [`ESSENTIALS`].
|
||||
const ESSENTIALS_ID: &str = "essentials";
|
||||
|
||||
/// A built-in workspace: its name, the panels it brings to the front of their groups, and its record.
|
||||
/// A built-in workspace: its name, the panels it brings to the front of their groups, the number
|
||||
/// of columns its Tools panel lays the tools out in, and its record.
|
||||
pub struct Builtin {
|
||||
pub name: &'static str,
|
||||
pub fronts: &'static [&'static str],
|
||||
pub tools_steps: u16,
|
||||
pub record: WorkspaceRecord,
|
||||
}
|
||||
|
||||
impl Builtin {
|
||||
/// The workspace with its Tools panel in two columns (Window › Toolbars › Double Column on).
|
||||
fn double_tools(mut self) -> Self {
|
||||
self.tools_steps = 2;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// The id of a built-in workspace: its lower-case name with dashes.
|
||||
fn builtin_id(name: &str) -> String {
|
||||
name.to_lowercase().replace(' ', "-")
|
||||
@@ -226,7 +236,7 @@ pub fn builtins() -> Vec<Builtin> {
|
||||
let w = |name: &'static str, fronts: &'static [&'static str], f: &dyn Fn(&mut WorkspaceRecord)| {
|
||||
let mut record = WorkspaceRecord::default();
|
||||
f(&mut record);
|
||||
Builtin { name, fronts, record }
|
||||
Builtin { name, fronts, tools_steps: 1, record }
|
||||
};
|
||||
vec![
|
||||
w(ESSENTIALS, &[], &|_| {}),
|
||||
@@ -248,7 +258,8 @@ pub fn builtins() -> Vec<Builtin> {
|
||||
w("Painting", &["brushes"], &|x| {
|
||||
x.control_bar = true;
|
||||
x.toolbar_advanced = true;
|
||||
}),
|
||||
})
|
||||
.double_tools(),
|
||||
w("Printing and Proofing", &["info"], &|x| {
|
||||
x.control_bar = true;
|
||||
x.rulers = true;
|
||||
@@ -279,7 +290,10 @@ pub fn builtins() -> Vec<Builtin> {
|
||||
|
||||
/// The built-ins as the framework's named workspaces.
|
||||
fn builtin_set() -> Vec<NamedWorkspace<String>> {
|
||||
builtins().into_iter().map(|b| NamedWorkspace::new(builtin_id(b.name), b.name, crate::panel_docking::default_workspace(b.fronts))).collect()
|
||||
builtins()
|
||||
.into_iter()
|
||||
.map(|b| NamedWorkspace::new(builtin_id(b.name), b.name, crate::panel_docking::builtin_workspace(b.fronts, b.tools_steps)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The chrome the set stores beside a layout, from `record`. Never read back: the record is the truth.
|
||||
@@ -745,6 +759,36 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Painting lays the Tools panel out in two columns and Window › Toolbars › Double Column reads
|
||||
/// checked; every other built-in workspace has one column. Switching back to Essentials brings
|
||||
/// back its own column count, as it was left, and Reset Painting gives two columns again.
|
||||
#[test]
|
||||
fn painting_shows_tools_in_two_columns_and_essentials_keeps_its_own() {
|
||||
let steps = |app: &VectorcraftApp| {
|
||||
crate::panel_docking::column_of(crate::panel_docking::layout_of(&app.ui), crate::toolbar::TOOLS).and_then(|(_, column)| column.steps)
|
||||
};
|
||||
let double = |app: &VectorcraftApp| crate::menus::checked(app, "window.toolbarColumns", &json!({}));
|
||||
let mut app = app();
|
||||
assert_eq!((steps(&app), double(&app)), (Some(1), Some(false)), "Essentials starts with one column");
|
||||
for b in builtins() {
|
||||
switch(&mut app, b.name).unwrap();
|
||||
let painting = b.name == "Painting";
|
||||
assert_eq!(steps(&app), Some(if painting { 2 } else { 1 }), "{}", b.name);
|
||||
assert_eq!(double(&app), Some(painting), "Double Column in {}", b.name);
|
||||
}
|
||||
switch(&mut app, ESSENTIALS).unwrap();
|
||||
assert_eq!((steps(&app), double(&app)), (Some(1), Some(false)), "Essentials has one column again");
|
||||
app.run("window.toolbarColumns", json!({"double": true})).unwrap();
|
||||
switch(&mut app, "Painting").unwrap();
|
||||
app.run("window.toolbarColumns", json!({"double": false})).unwrap();
|
||||
switch(&mut app, ESSENTIALS).unwrap();
|
||||
assert_eq!(double(&app), Some(true), "Essentials keeps the two columns it was left with");
|
||||
switch(&mut app, "Painting").unwrap();
|
||||
assert_eq!(double(&app), Some(false), "Painting keeps the one column it was left with");
|
||||
reset(&mut app);
|
||||
assert_eq!((steps(&app), double(&app)), (Some(2), Some(true)), "Reset Painting gives two columns again");
|
||||
}
|
||||
|
||||
/// A file saved before `WorkspaceSet` names workspaces in any case: the layout remembered under
|
||||
/// another spelling belongs to the saved workspace, once; a name no workspace has is dropped,
|
||||
/// and a saved name equal to a built-in's is refused and reported.
|
||||
|
||||
Reference in new issue
Block a user