VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Paragraph: Reset Panel also resets the Hyphenation options
dotCooCood7026367f7f5
diff --git a/crates/ui-egui/src/panels/paragraph.rs b/crates/ui-egui/src/panels/paragraph.rsindex 0f56fe7a0..84c52281f 100644--- a/crates/ui-egui/src/panels/paragraph.rs+++ b/crates/ui-egui/src/panels/paragraph.rs@@ -4,7 +4,7 @@use egui::{Ui, vec2};use serde_json::{Value, json};-use vectorcraft_doc::{Composer, Justify, NodeKind, ParaDirection, ParaStyle};+use vectorcraft_doc::{Composer, HyphenationOptions, Justify, NodeKind, ParaDirection, ParaStyle};use super::character::text_style;use super::{pstate, set_pstate};@@ -330,14 +330,27 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {}ui.separator();if menu_item(ui, tl!("Reset Panel"), has, false) {- para_cmd(app, "text.setStyle", json!({"justify": "auto"}));- format(- app,- json!({"leftIndent": 0, "rightIndent": 0, "firstLineIndent": 0, "spaceBefore": 0, "spaceAfter": 0, "hyphenate": false, "direction": "auto", "leadingModel": "romanBaseline", "burasagari": "standard", "kinsoku": "hard", "composer": "everyLine"}),- );+ reset_panel(app);}}+/// Reset Panel: the paragraphs the panel acts on ([`format`]) take Auto alignment, no indents or+/// paragraph spacing, Hyphenate off with the default Hyphenation options, Auto direction,+/// Bottom-to-Bottom Leading, Regular burasagari, the Hard kinsoku set and the Every-line Composer.+fn reset_panel(app: &mut VectorcraftApp) {+ let h = HyphenationOptions::default();+ para_cmd(app, "text.setStyle", json!({"justify": "auto"}));+ format(+ app,+ json!({+ "leftIndent": 0, "rightIndent": 0, "firstLineIndent": 0, "spaceBefore": 0, "spaceAfter": 0, "hyphenate": false,+ "wordsLongerThan": h.words_longer_than, "afterFirst": h.after_first, "beforeLast": h.before_last,+ "hyphenLimit": h.hyphen_limit, "hyphenationZone": h.zone, "hyphenateCapitalized": h.capitalized,+ "direction": "auto", "leadingModel": "romanBaseline", "burasagari": "standard", "kinsoku": "hard", "composer": "everyLine"+ }),+ );+}+#[cfg(test)]mod tests {use super::*;@@ -560,4 +573,33 @@ mod tests {app.session.prefs.show_indic_options = true;assert!(tips(&mut app) > without, "two more buttons");}++ /// Reset Panel turns Hyphenate off and sets the Hyphenation options back to their defaults in+ /// every paragraph it acts on, so the paragraphs save no hyphenation options.+ #[test]+ fn reset_panel_resets_the_hyphenation_options() {+ let mut app = VectorcraftApp::new(Session::new(), Default::default());+ app.run("file.new", json!({"width": 400, "height": 200})).unwrap();+ let id = app.run("text.create", json!({"x": 20, "y": 50, "text": "First\nSecond"})).unwrap()["id"].clone();+ app.run(+ "text.setFormat",+ json!({"hyphenate": true, "wordsLongerThan": 8, "afterFirst": 2, "beforeLast": 4, "hyphenLimit": 2, "hyphenationZone": 18, "hyphenateCapitalized": false}),+ )+ .unwrap();+ let paras = |app: &VectorcraftApp| {+ let node = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id.as_u64().unwrap())).unwrap();+ let NodeKind::Text(text) = &node.kind else { panic!("text") };+ [text.para_at(0).clone(), text.para_at(1).clone()]+ };+ for para in paras(&app) {+ assert!(para.hyphenate);+ assert_ne!(para.hyphenation, HyphenationOptions::default());+ }+ reset_panel(&mut app);+ for para in paras(&app) {+ assert!(!para.hyphenate);+ assert_eq!(para.hyphenation, HyphenationOptions::default());+ assert_eq!(serde_json::to_value(¶).unwrap().get("hyphenation"), None, "saves no hyphenation options");+ }+ }}