Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge #199: Swatch menus: the whole row (chip included) is clickable; the Contextual Task Bar's fill and stroke menus show chips

aiongg97e0109ca61f
diff --cc crates/ui-egui/src/panels/properties.rs
index 934486eb7,d90158b27..31a4d0051
--- a/crates/ui-egui/src/panels/properties.rs
+++ b/crates/ui-egui/src/panels/properties.rs
@@@ -2133,35 -2124,42 +2130,74 @@@ mod tests
use super::*;
+ fn language(app: &mut DesignApp) -> Value {
+ text_attrs(app).unwrap()["chars"]["language"].clone()
+ }
+
+ #[test]
+ fn properties_character_section_sets_the_language() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ app.run("frame.create", json!({"rect": [72, 72, 300, 200], "content": "text", "text": "bunun", "caret": true})).unwrap();
+ app.run("edit.selectAll", json!({})).unwrap();
+ assert_ne!(language(&mut app), "French");
+ let mut h = Harness::builder().with_size(vec2(320.0, 1400.0)).build_ui_state(
+ |ui, app: &mut DesignApp| {
+ // The panel's fonts are installed before its first frame.
+ let id = egui::Id::new("test_fonts");
+ if ui.data(|d| d.get_temp::<bool>(id)).is_none() {
+ crate::theme::install_fonts(ui.ctx(), "");
+ ui.data_mut(|d| d.insert_temp(id, true));
+ return;
+ }
+ show(app, ui);
+ },
+ app,
+ );
+ h.run_steps(3);
+ h.get_by_label("Language").click();
+ h.run_steps(2);
+ h.get_by_label("French").click();
+ h.run_steps(2);
+ assert_eq!(language(h.state_mut()), "French");
+ }
++
+ #[test]
+ fn clicking_a_swatch_chip_in_the_appearance_fill_menu_applies_it() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ // A graphic frame: the Appearance section shows a single Fill chip.
+ let id = app.run("frame.create", json!({"rect": [72, 72, 300, 200]})).unwrap()["id"].as_u64().unwrap();
+ app.run("selection.set", json!({"ids": [id]})).unwrap();
+ let before = app.session.active().unwrap().doc.item(designcraft_doc::ids::ItemId(id)).unwrap().fill.swatch.clone();
+ assert_ne!(before, "[Paper]");
+ let mut h = Harness::builder().with_size(vec2(320.0, 1400.0)).build_ui_state(
+ |ui, app: &mut DesignApp| {
+ let id = egui::Id::new("test_fonts");
+ if ui.data(|d| d.get_temp::<bool>(id)).is_none() {
+ crate::theme::install_fonts(ui.ctx(), "");
+ ui.data_mut(|d| d.insert_temp(id, true));
+ return;
+ }
+ show(app, ui);
+ },
+ app,
+ );
+ h.run_steps(3);
+ // Open the Fill menu from the Appearance chip.
+ h.get_by_label("Fill swatch").click();
+ h.run_steps(3);
+ // Click the *chip* (the row's left edge), not the name.
+ let name = "[Paper]".to_string();
+ let row = h.get_by_label(&name).rect();
+ // The row spans the menu (chip + name), not just the name text.
+ assert!(row.width() > 150.0, "the row is the full menu width, chip included: {row:?}");
+ let p = row.min + vec2(8.0, row.height() / 2.0);
+ h.hover_at(p);
+ h.drag_at(p);
+ h.drop_at(p);
+ h.run_steps(4);
+ let after = h.state().session.active().unwrap().doc.item(designcraft_doc::ids::ItemId(id)).unwrap().fill.swatch.clone();
+ assert_eq!(after, name, "clicking the swatch chip applies it");
+ }
}