mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-30 04:37:29 -06:00
Merge pull request #4570 from TheGalitube/fix/4558-bug-report-vectorcraft-rearrange
Retain spacing when rearranging artboards
This commit is contained in:
@@ -30,6 +30,15 @@ pub fn fields() -> Value {
|
||||
json!({"layout": "gridByRow", "order": "leftToRight", "columns": 2, "spacing": 20, "moveArtwork": true})
|
||||
}
|
||||
|
||||
/// The fields the menu item opens with, retaining the spacing from its last confirmation.
|
||||
pub fn open_fields(app: &VectorcraftApp) -> Value {
|
||||
let mut fields = fields();
|
||||
if let Some(spacing) = app.ui.rearrange_artboards_spacing.as_f64() {
|
||||
fields["spacing"] = json!(spacing);
|
||||
}
|
||||
fields
|
||||
}
|
||||
|
||||
/// A layout's toggle: its tooltip and its artboards' cells (column, row) in their order, left to
|
||||
/// right.
|
||||
fn layout_glyph(l: ArtboardLayout) -> (&'static str, &'static [(u8, u8)]) {
|
||||
@@ -110,7 +119,9 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool {
|
||||
}
|
||||
|
||||
fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String> {
|
||||
run_and_close(app, CMD, params(d))
|
||||
let result = run_and_close(app, CMD, params(d))?;
|
||||
app.ui.rearrange_artboards_spacing = json!(d.f64("spacing", 20.0));
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -169,6 +180,19 @@ mod tests {
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo + 1);
|
||||
}
|
||||
|
||||
/// The spacing confirmed last is the one the dialog opens with next time (#4558).
|
||||
#[test]
|
||||
fn keeps_spacing_when_reopening_after_rearranging() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 100, "height": 50, "artboards": 3})).unwrap();
|
||||
app.run("ui.menuDialog", json!({"command": CMD})).unwrap();
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert("spacing".into(), json!(37));
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
|
||||
app.run("ui.menuDialog", json!({"command": CMD})).unwrap();
|
||||
assert_eq!(app.ui.dialog.as_ref().unwrap().f64("spacing", 20.0), 37.0);
|
||||
}
|
||||
|
||||
/// Clicking the layout and order toggles sets the fields (the toggles' rects from the frame).
|
||||
#[test]
|
||||
fn the_toggles_set_layout_and_order() {
|
||||
|
||||
@@ -62,7 +62,7 @@ pub(super) fn menu_dialog(app: &VectorcraftApp, id: &str) -> Option<(&'static st
|
||||
("splitIntoGrid", crate::dialogs::path_ops::split_fields(size.0, size.1))
|
||||
}
|
||||
"object.vectorHalftone" => (crate::dialogs::halftone::KIND, crate::dialogs::halftone::fields()),
|
||||
"artboard.rearrange" => (crate::dialogs::rearrange_artboards::KIND, crate::dialogs::rearrange_artboards::fields()),
|
||||
"artboard.rearrange" => (crate::dialogs::rearrange_artboards::KIND, crate::dialogs::rearrange_artboards::open_fields(app)),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -555,6 +555,9 @@ pub struct UiState {
|
||||
/// them (#1732).
|
||||
#[serde(default)]
|
||||
pub transform_each: Value,
|
||||
/// The spacing used the last time Rearrange All Artboards was confirmed.
|
||||
#[serde(default)]
|
||||
pub rearrange_artboards_spacing: Value,
|
||||
/// The DXF Import Options chosen last (fit, scaleLineweights, center, mergeLayers; null:
|
||||
/// never used).
|
||||
#[serde(default)]
|
||||
@@ -878,6 +881,7 @@ impl Default for UiState {
|
||||
simplify: Value::Null,
|
||||
move_options: Value::Null,
|
||||
transform_each: Value::Null,
|
||||
rearrange_artboards_spacing: Value::Null,
|
||||
dxf_import: Value::Null,
|
||||
home: None,
|
||||
trace_hold_source: None,
|
||||
|
||||
Reference in New Issue
Block a user