From c537758eada32245fdb4fcaaad4bacfdbbfd06b7 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 23 Nov 2026 06:33:12 +0700 Subject: [PATCH] Follow the refreshed framework: channel rules from the alpha rule's whole steps, Color Guide glue reads a cell's grid spot and colour, Save for Web's table edits take the edit and its colours, preset previews as keyed faces, constructors for hold settings, card sources, web documents and preset drafts, the drawer marks a tool only when there is one, Shift+Enter reaches the type tool, a nudge reads Backtick from the keys held with its arrow, the web host drops pick_pending, font loading takes every cataloged version of a family's faces --- apps/vectorcraft-web/src/web.rs | 4 - crates/text/src/fontdb/db.rs | 1 - crates/text/src/fontdb/lookup.rs | 9 +- crates/ui-egui/src/canvas/tool_adapter.rs | 4 +- crates/ui-egui/src/dialogs/color_balance.rs | 4 +- crates/ui-egui/src/dialogs/new_document.rs | 2 +- crates/ui-egui/src/dialogs/recolor.rs | 30 ++--- crates/ui-egui/src/dialogs/save_for_web.rs | 4 +- .../src/dialogs/save_for_web/color_table.rs | 18 ++- .../src/dialogs/save_for_web/tests_table.rs | 10 +- crates/ui-egui/src/dialogs/save_pdf.rs | 30 +++-- crates/ui-egui/src/edit_toolbar.rs | 13 +- crates/ui-egui/src/paint_preview.rs | 8 ++ crates/ui-egui/src/panel_docking.rs | 2 +- crates/ui-egui/src/panels.rs | 9 +- crates/ui-egui/src/panels/appearance.rs | 13 +- crates/ui-egui/src/panels/color_guide.rs | 122 +++++++++--------- crates/ui-egui/src/panels/color_themes.rs | 4 +- crates/ui-egui/src/panels/color_wheel.rs | 6 +- crates/ui-egui/src/panels/glyphs.rs | 6 +- crates/ui-egui/src/panels/gradient.rs | 6 +- crates/ui-egui/src/shortcut_editor.rs | 2 +- crates/ui-egui/src/type_editing.rs | 2 +- 23 files changed, 159 insertions(+), 150 deletions(-) diff --git a/apps/vectorcraft-web/src/web.rs b/apps/vectorcraft-web/src/web.rs index 1d01f35896..a95e044ad1 100644 --- a/apps/vectorcraft-web/src/web.rs +++ b/apps/vectorcraft-web/src/web.rs @@ -581,10 +581,6 @@ impl Files for WebFiles { picks.answered.retain(|a| a.id != id); } - fn pick_pending(&self) -> bool { - !self.lock().waiting.is_empty() - } - fn pending_pick(&self) -> Option { self.lock().waiting.first().map(|(_, request)| PendingPick { request: request.clone(), sheet: false }) } diff --git a/crates/text/src/fontdb/db.rs b/crates/text/src/fontdb/db.rs index bbcdf12a6a..4235ed9fbc 100644 --- a/crates/text/src/fontdb/db.rs +++ b/crates/text/src/fontdb/db.rs @@ -233,7 +233,6 @@ impl FontDb { } // An installed family's, from its names in other languages, as a loaded face's is chosen // (every face of a family has the same names: one is enough). - // PLAN: the catalog lists a family's localized names from its typographic records whenever it has one (font-catalog scan.rs:281), so a font whose typographic family is English only loses its localized legacy name here (#2208, `family_display_name_falls_back_to_localized_legacy_names`); the fallback to legacy records belongs in that scan rule (type-w2). let native = self.catalog.resolve(&family, "").and_then(|(f, _)| { let names: Vec<(Option, String)> = f.localized_families.into_iter().map(|n| (n.language, n.name)).collect(); pick_native_label(&f.family, &names) diff --git a/crates/text/src/fontdb/lookup.rs b/crates/text/src/fontdb/lookup.rs index c909061a7c..672d63ae2a 100644 --- a/crates/text/src/fontdb/lookup.rs +++ b/crates/text/src/fontdb/lookup.rs @@ -292,12 +292,13 @@ impl FontDb { self.catalog.by_postscript_name(name).map(|f| (f.family, f.style)) } - /// Load the files of the installed `family`, adding all their faces at once - /// ([`Self::add_fonts`]). Returns whether the family is loaded now: by this call, or by another + /// Load the files of the installed `family`, every cataloged version of its faces included, + /// adding all their faces at once ([`Self::add_fonts`]). Returns whether the family is loaded now: by this call, or by another /// thread meanwhile. #[cfg(not(target_arch = "wasm32"))] fn load_cataloged(&self, family: &str) -> bool { - let mut paths: Vec = self.catalog.styles(family).into_iter().filter_map(|f| f.path).collect(); + let faces = self.catalog.styles(family); + let mut paths: Vec = faces.iter().flat_map(|f| self.catalog.versions(f)).filter_map(|f| f.path).collect(); paths.sort(); paths.dedup(); let files = paths.into_iter().flat_map(|p| font_files(&p).into_iter().map(move |data| (data, Some(p.clone())))); @@ -345,7 +346,7 @@ impl FontDb { if let Some(f) = self.read_faces().iter().find(same) { return Some(f.clone()); } - // Not loaded: the family's installed files may hold it (the catalog doesn't list versions). + // Not loaded: another installed file of the family may hold it. self.load_family_files(&face.family); let found = self.read_faces().iter().find(same).cloned(); Some(found.unwrap_or(face)) diff --git a/crates/ui-egui/src/canvas/tool_adapter.rs b/crates/ui-egui/src/canvas/tool_adapter.rs index 47e143f737..fb6d9f7d1a 100644 --- a/crates/ui-egui/src/canvas/tool_adapter.rs +++ b/crates/ui-egui/src/canvas/tool_adapter.rs @@ -389,7 +389,7 @@ impl CanvasTool for SessionTool<'_> { let space = cx.held(Key::Space); let held = tool_mods(cx.mods, space); match key { - ToolKey::Nudge { direction, mods, .. } => { + ToolKey::Nudge { direction, mods, held: with, .. } => { let (k, arrow) = match (direction.x.abs() > direction.y.abs(), direction.x < 0.0, direction.y < 0.0) { (true, true, _) => (EngineKey::Left, Key::Left), (true, false, _) => (EngineKey::Right, Key::Right), @@ -410,7 +410,7 @@ impl CanvasTool for SessionTool<'_> { !matches!(keymap.lookup_where(&chord, false, &craft::keymap::Active::NONE, &[], &global), craft::keymap::Lookup::None) }); if !bound { - crate::shortcuts::nudge(&mut self.app(), *direction, *mods, cx.held(Key::Backtick)); + crate::shortcuts::nudge(&mut self.app(), *direction, *mods, with.contains(&Key::Backtick)); } !bound } diff --git a/crates/ui-egui/src/dialogs/color_balance.rs b/crates/ui-egui/src/dialogs/color_balance.rs index 3ded2ae22b..87aefa8acf 100644 --- a/crates/ui-egui/src/dialogs/color_balance.rs +++ b/crates/ui-egui/src/dialogs/color_balance.rs @@ -10,7 +10,7 @@ //! Fields: `mode` (`gray`, `rgb`, `cmyk` or `global`), the channels `r`, `g`, `b`, `c`, `m`, `y`, //! `k`, `gray`, `tint`, then `convert`, `fill` and `stroke`. The preview check box is the host's. -use craft::color_ui::ui::{ChannelRow, ChannelRule, ChannelUnit}; +use craft::color_ui::ui::{ChannelRow, ChannelUnit}; use craft::theme::Srgba; use craft::ui::contract::Bind; use craft::ui::dialog::DialogId; @@ -128,7 +128,7 @@ impl Adjust { pub(super) fn percent_row(ui: &mut egui::Ui, fields: &mut DialogFields, key: &str, label: &'static str, track: impl Fn(f32) -> Srgba) { const RAIL_STOPS: usize = 5; let rail = (0..RAIL_STOPS).map(|i| track(i as f32 / (RAIL_STOPS - 1) as f32)).collect(); - let rule = ChannelRule { range: -100.0..=100.0, step: 1.0, decimals: 0 }; + let rule = crate::panels::whole_steps(-100.0..=100.0); let value = fields.number(key).unwrap_or(0.0); let edit = ChannelRow::new(label, Bind::given(value), rule).unit(ChannelUnit::Percent).track(rail).show(ui); if let Some(value) = edit.as_ref().and_then(|edit| edit.value()) { diff --git a/crates/ui-egui/src/dialogs/new_document.rs b/crates/ui-egui/src/dialogs/new_document.rs index 7fc2bba032..06c12a4c51 100644 --- a/crates/ui-egui/src/dialogs/new_document.rs +++ b/crates/ui-egui/src/dialogs/new_document.rs @@ -388,7 +388,7 @@ fn built_in_card(preset: &DocSettings, values: &VcNewDocument, orientation: Opti } let line = s.size_label(); let value = VcNewDocument { title: values.title.clone(), settings: s, turn: None }; - DocumentCard::new(text(preset_name(&preset.name)), line, value, CardSource::Preset { artboard: None }) + DocumentCard::new(text(preset_name(&preset.name)), line, value, CardSource::preset(None)) } /// A label with the text `s`, already translated. diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index 14cfee4196..cae9945831 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -122,7 +122,7 @@ use std::sync::Arc; use craft::behavior::edit_history::{EditHistory, Step}; use craft::behavior::{ColumnKey, ColumnWidth, EditEvent, IconId, Mixed, Selection, SelectionChange, keyed}; -use craft::color_ui::ui::{ChannelRow, ChannelRule, ChannelUnit, ColorPanelMode, DiscRadius, patch_at}; +use craft::color_ui::ui::{ChannelRow, ChannelUnit, ColorPanelMode, DiscRadius, patch_at}; use craft::host::PickRequest; use craft::theme::variant::Tone; use craft::theme::{ModelValues, Rgba, Srgba}; @@ -162,7 +162,7 @@ use crate::VectorcraftApp; use crate::panels::color::{color_of_values, working_rgb}; use crate::panels::library_panel; use crate::panels::swatches::{DOCUMENT_SWATCHES, colour_libraries, limit_key}; -use crate::panels::{c32, srgba}; +use crate::panels::{c32, srgba, whole_steps}; /// The dialog kind of Recolor Artwork. pub const KIND: &str = "recolor"; @@ -1762,11 +1762,8 @@ impl RecolorDialog { /// Color Groups button that can't run ([`check_group_action`]) and a `groupStorage` that is not a /// bool are refused, and the dialog stays as it was. fn set_field(&mut self, field: &str, value: Value) -> Result<(), String> { - let known = if field.starts_with("__") { - SETTABLE.contains(&field) - } else { - self.fields.fields.contains_key(field) || UNSET_FIELDS.contains(&field) - }; + let known = + if field.starts_with("__") { SETTABLE.contains(&field) } else { self.fields.fields.contains_key(field) || UNSET_FIELDS.contains(&field) }; if !known { return Err(FieldRefusal::Unknown.message(field)); } @@ -2396,11 +2393,6 @@ fn channels(mode: ColorPanelMode) -> &'static [(&'static str, f64, f64, ChannelU } } -/// A slider's rule: whole steps from `lo` to `hi`. -fn rule(lo: f64, hi: f64) -> ChannelRule { - ChannelRule { range: lo..=hi, step: 1.0, decimals: 0 } -} - /// `c`'s values in `mode` (HSB °/%/% and RGB 0 to 255 of the working RGB, CMYK %, Lab L*a*b*). fn values_in(mode: ColorPanelMode, c: &Color) -> Vec { match mode { @@ -2557,7 +2549,8 @@ fn global_sliders(ui: &mut Ui, d: &mut Fields, sample: Color) { }) .collect(); let value = values.get(n).copied().unwrap_or(0.0); - let Some(out) = ChannelRow::new(*label, Bind::given(value), rule(-100.0, 100.0)).unit(ChannelUnit::Percent).track(stops).show(ui) + let Some(out) = + ChannelRow::new(*label, Bind::given(value), whole_steps(-100.0..=100.0)).unit(ChannelUnit::Percent).track(stops).show(ui) else { continue; }; @@ -2590,7 +2583,7 @@ fn sliders(ui: &mut Ui, feed: &Feed, d: &mut Fields, rows: &mut [Value], row: Op Row::new().show(ui, |ui, _| { for &(name, lo, hi, unit) in pair { // A disabled row edits nothing: its output has no edit to read. - let _ = ChannelRow::new(name, Bind::given(lo), rule(lo, hi)).short(name).unit(unit).show(ui); + let _ = ChannelRow::new(name, Bind::given(lo), whole_steps(lo..=hi)).short(name).unit(unit).show(ui); } }); } @@ -2601,7 +2594,7 @@ fn sliders(ui: &mut Ui, feed: &Feed, d: &mut Fields, rows: &mut [Value], row: Op let tint = f64::from(row_tint(&rows[i])) * 100.0; let stops: Vec = (0..TRACK_STOPS).map(|k| srgba(&target.linked.tinted(k as f32 / (TRACK_STOPS - 1) as f32))).collect(); Row::new().show(ui, |ui, _| { - if let Some(out) = ChannelRow::new(tl!("Tint"), Bind::given(tint), rule(0.0, 100.0)) + if let Some(out) = ChannelRow::new(tl!("Tint"), Bind::given(tint), whole_steps(0.0..=100.0)) .short("T") .unit(ChannelUnit::Percent) .track(stops.clone()) @@ -2622,8 +2615,11 @@ fn sliders(ui: &mut Ui, feed: &Feed, d: &mut Fields, rows: &mut [Value], row: Op for (k, &(name, lo, hi, unit)) in pair.iter().enumerate() { let n = line * 2 + k; let value = f64::from(comps.get(n).copied().unwrap_or(0.0)); - let Some(out) = - ChannelRow::new(name, Bind::given(value), rule(lo, hi)).short(name).unit(unit).track(track(mode, &comps, n, lo, hi)).show(ui) + let Some(out) = ChannelRow::new(name, Bind::given(value), whole_steps(lo..=hi)) + .short(name) + .unit(unit) + .track(track(mode, &comps, n, lo, hi)) + .show(ui) else { continue; }; diff --git a/crates/ui-egui/src/dialogs/save_for_web.rs b/crates/ui-egui/src/dialogs/save_for_web.rs index 9c889edf8d..488b807e43 100644 --- a/crates/ui-egui/src/dialogs/save_for_web.rs +++ b/crates/ui-egui/src/dialogs/save_for_web.rs @@ -197,7 +197,7 @@ pub fn open(app: &mut VectorcraftApp) -> Result { } }; let mut dialog = HostedSaveForWeb::new(name, size, original) - .document(WebDocument::Vector { artboards }) + .document(WebDocument::vector(artboards)) .formats(vec![WebFormat::Gif, WebFormat::Jpeg, WebFormat::Png8, WebFormat::Png24]) .color_tables(vec![ ColorTable::Perceptual, @@ -522,7 +522,7 @@ fn edit_table(app: &mut VectorcraftApp, ctx: &egui::Context, host: &craft::ui::s }; let mut deleted = false; for event in &asked.tables { - match color_table::apply(&mut app.web_export.table, event, &shown) { + match color_table::apply(&mut app.web_export.table, &event.edit, &event.colors, &shown) { Ok(()) => deleted |= matches!(event.edit, ColorTableEdit::Delete), Err(e) => app.status(e), } diff --git a/crates/ui-egui/src/dialogs/save_for_web/color_table.rs b/crates/ui-egui/src/dialogs/save_for_web/color_table.rs index 67475b7894..f80c488fef 100644 --- a/crates/ui-egui/src/dialogs/save_for_web/color_table.rs +++ b/crates/ui-egui/src/dialogs/save_for_web/color_table.rs @@ -8,7 +8,7 @@ use serde_json::{Map, Value, json}; use vectorcraft_engine::cmd::webexport; use vectorcraft_render::encode::web::ColorSort; -use craft::ui::patterns::form_dialogs::{ColorTableEdit, ColorTableEvent, TableMarks, TableOrder}; +use craft::ui::patterns::form_dialogs::{ColorTableEdit, TableMarks, TableOrder}; /// `c` as lowercase `#rrggbb`. fn hex(c: [u8; 3]) -> String { @@ -86,8 +86,8 @@ fn unshift(table: &mut Value, source: &str) { /// locked until it is unshifted), and Web Shift takes the hand shift of the colours it adds away. /// Unshift All and Sort act on the whole table. Delete is refused with [`webexport::KEEP_ONE`], /// and nothing changes, when no colour would be left that is neither deleted nor transparent. -pub(crate) fn apply(table: &mut Value, event: &ColorTableEvent, shown: &[[u8; 3]]) -> Result<(), String> { - match &event.edit { +pub(crate) fn apply(table: &mut Value, edit: &ColorTableEdit, colors: &[[u8; 3]], shown: &[[u8; 3]]) -> Result<(), String> { + match edit { ColorTableEdit::UnshiftAll => { set_table(table, "shifted", json!({})); set_table(table, "webShift", json!([])); @@ -110,7 +110,7 @@ pub(crate) fn apply(table: &mut Value, event: &ColorTableEvent, shown: &[[u8; 3] // PLAN: assumed `ColorTableEdit::Shift([u8; 3])` (ex.A11 pending change): the colour the // first selected colour is shifted to. ColorTableEdit::Shift(to) => { - if let Some(&from) = event.colors.first().filter(|c| shown.contains(c)) { + if let Some(&from) = colors.first().filter(|c| shown.contains(c)) { shift(table, from, *to); } return Ok(()); @@ -118,7 +118,7 @@ pub(crate) fn apply(table: &mut Value, event: &ColorTableEvent, shown: &[[u8; 3] _ => {} } let mut picked: Vec = Vec::new(); - for c in event.colors.iter().filter(|c| shown.contains(c)) { + for c in colors.iter().filter(|c| shown.contains(c)) { let c = hex(*c); if !picked.contains(&c) { picked.push(c); @@ -127,7 +127,7 @@ pub(crate) fn apply(table: &mut Value, event: &ColorTableEvent, shown: &[[u8; 3] if picked.is_empty() { return Ok(()); } - match &event.edit { + match edit { ColorTableEdit::Lock => { let by_hand = shifts(table); let free: Vec = picked.into_iter().filter(|c| !by_hand.keys().any(|k| k.eq_ignore_ascii_case(c))).collect(); @@ -202,5 +202,9 @@ pub(crate) fn marks(table: &Value) -> TableMarks { let colors = |key: &str| list(table, key).iter().filter_map(|c| parse(c)).collect(); let shifted = shifts(table).iter().filter_map(|(k, v)| Some((parse(k)?, parse(v.as_str()?)?))).collect(); // PLAN: TableMarks lacks `web_shifted` (ex.W9 request); the Web Shift/Unshift label needs it. - TableMarks { locked: colors("locked"), transparent: colors("transparent"), shifted } + let mut marks = TableMarks::default(); + marks.locked = colors("locked"); + marks.transparent = colors("transparent"); + marks.shifted = shifted; + marks } diff --git a/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs b/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs index 76e548b537..a3c3b0859a 100644 --- a/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs +++ b/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs @@ -3,7 +3,7 @@ use serde_json::{Value, json}; use vectorcraft_engine::cmd::webexport; -use craft::ui::patterns::form_dialogs::{ColorTableEdit, ColorTableEvent, PALETTE_COLOR_KEY, TableOrder}; +use craft::ui::patterns::form_dialogs::{ColorTableEdit, PALETTE_COLOR_KEY, TableOrder}; use super::color_table::{apply, marks, restore, shift}; use super::tests::{app, frame, host, save, set}; @@ -13,12 +13,8 @@ const B: [u8; 3] = [0x11, 0x11, 0x11]; const C: [u8; 3] = [0x22, 0x22, 0x22]; const D: [u8; 3] = [0x33, 0x33, 0x33]; -fn event(edit: ColorTableEdit, colors: &[[u8; 3]]) -> ColorTableEvent { - ColorTableEvent { edit, colors: colors.to_vec() } -} - fn run(table: &mut Value, edit: ColorTableEdit, colors: &[[u8; 3]], shown: &[[u8; 3]]) -> Result<(), String> { - apply(table, &event(edit, colors), shown) + apply(table, &edit, colors, shown) } #[test] @@ -167,7 +163,7 @@ fn delete_color_reaches_the_saved_file_and_is_remembered() { } frame(&mut app); let red = [0xcc, 0x33, 0x00]; - apply(&mut app.web_export.table, &event(ColorTableEdit::Delete, &[red]), &[red, [0, 0, 255]]).unwrap(); + apply(&mut app.web_export.table, &ColorTableEdit::Delete, &[red], &[red, [0, 0, 255]]).unwrap(); frame(&mut app); save(&mut app); let path = diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index 851ad48396..42ffd6bbcf 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -117,15 +117,18 @@ pub(crate) fn open_for_save(app: &mut VectorcraftApp, params: &Value, mode: Save /// (default: the app default). pub fn open_preset(app: &mut VectorcraftApp, params: &Value) -> Result { let s = |k: &str| params.get(k).and_then(Value::as_str); - let (base, name, description, editing) = match s("name") { + let mut draft = PresetDraft::default(); + let (base, editing) = match s("name") { Some(name) => { let p = app.session.prefs.pdf_presets.iter().find(|p| p.name.eq_ignore_ascii_case(name.trim())); let p = p.ok_or_else(|| format!("no saved PDF preset named `{name}` (built-in presets are read-only: start a new one from them)"))?; - (p.name.clone(), p.name.clone(), p.description.clone(), p.name.clone()) + (draft.name, draft.description) = (p.name.clone(), p.description.clone()); + (p.name.clone(), p.name.clone()) } None => { let base = s("preset").map_or_else(|| default_preset_name(APP).to_string(), str::to_string); - (base, app.session.new_pdf_preset_name(), String::new(), String::new()) + draft.name = app.session.new_pdf_preset_name(); + (base, String::new()) } }; let settings = pdf::resolve("ui.savePdfDialog", &json!({ "preset": base }), &app.session.prefs.pdf_presets).map_err(|e| e.to_string())?; @@ -136,17 +139,16 @@ pub fn open_preset(app: &mut VectorcraftApp, params: &Value) -> Result Option) - } } +/// A face painting `paint` with [`paint_rect`], keyed by every field of the paint. +pub fn rect_face(paint: &Paint) -> FacePaint { + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + serde_json::to_string(paint).unwrap_or_default().hash(&mut hasher); + let paint = paint.clone(); + FacePaint::new(hasher.finish(), move |cx, rect| paint_rect(cx, rect, &paint)) +} + /// Paints `paint` into `rect` of a content painter (a `Picture::painter` body). Nothing is drawn /// for no paint: the picture's own surface shows. pub fn paint_rect(cx: &ContentPainterCx<'_>, rect: Rect, paint: &Paint) { diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index a87f1f4f55..b833b6bab7 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -1175,7 +1175,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) { .hide(hide) .flyout(Bind::bound(&mut flyout)); if let Some((panel, grab)) = hand_over { - area = area.continue_move(panel, grab); + area = area.continue_move((panel, grab)); } if auto_collapse { area.auto_collapse().show(ui) } else { area.show(ui) } }; diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index f12b9cdb44..90b921f08a 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -57,7 +57,7 @@ pub mod variables; use std::sync::Arc; use craft::behavior::{ColumnWidth, IconId, Mixed}; -use craft::color_ui::ui::HarmonyCommand; +use craft::color_ui::ui::{ChannelRule, HarmonyCommand}; use craft::color_ui::ui::{PaintChip, PairWell, SwatchPair, SwatchPairOutput, SwatchPalette, Well}; use craft::keymap::CommandRef; use craft::theme::Srgba; @@ -876,6 +876,13 @@ pub(crate) fn srgba(c: &Color) -> Srgba { Srgba::rgb(f32::from(r) / 255.0, f32::from(g) / 255.0, f32::from(b) / 255.0) } +/// A colour channel row's rule over `range` in whole steps, as the alpha row steps. +pub(crate) fn whole_steps(range: std::ops::RangeInclusive) -> ChannelRule { + let mut rule = ChannelRule::ALPHA; + rule.range = range; + rule +} + /// The empty state of a panel with nothing to show: `icon` over the title and the message, /// centred in the panel. pub(crate) fn empty_state(ui: &mut Ui, icon: &'static str, title: &str, body: &str) { diff --git a/crates/ui-egui/src/panels/appearance.rs b/crates/ui-egui/src/panels/appearance.rs index 90dc826a1a..092e0a1db7 100644 --- a/crates/ui-egui/src/panels/appearance.rs +++ b/crates/ui-egui/src/panels/appearance.rs @@ -17,7 +17,7 @@ use std::cell::RefCell; use std::collections::HashSet; -use std::hash::{DefaultHasher, Hash, Hasher}; +use std::hash::Hash; use std::sync::{Arc, OnceLock}; use craft::behavior::overlay::{Align, Side}; @@ -40,7 +40,7 @@ use craft::ui::patterns::presets::{ PresetBrowser, PresetEvent, PresetFns, PresetRow, PresetRowMenu, PresetSource, PresetState, PresetTiles, PresetView, }; use craft::ui::popover::Popover; -use craft::ui::primitives::{FacePaint, IconSpec}; +use craft::ui::primitives::IconSpec; use craft::ui::runtime::commands::{CommandRef, CommandState, CommandStates}; use craft::ui::runtime::env::Label; use craft::ui::sections::{FooterAction, FooterBar}; @@ -849,12 +849,9 @@ fn paint_swatch(fill: bool, paint: &Paint) -> Swatch { let [r, g, b] = c.to_rgb(); Srgba::rgb(r, g, b) }); - let mut hasher = DefaultHasher::new(); - serde_json::to_string(paint).unwrap_or_default().hash(&mut hasher); - let shown = paint.clone(); let row = if fill { tl!("Fill") } else { tl!("Stroke") }; Swatch::new(crate::i18n::fmt(tl!("{row} swatch"), &[("row", row)]), color) - .face(FacePaint::new(hasher.finish(), move |painter, rect| paint_preview::paint_rect(painter, rect, &shown))) + .face(paint_preview::rect_face(paint)) .tooltip(tl!("Click to choose a swatch, Shift-click to mix a colour")) } @@ -1381,9 +1378,7 @@ fn swatch_picker(app: &mut VectorcraftApp, ui: &mut Ui, target: Painted) -> bool let fns = PresetFns::, String>::new(|s, _| { doc_swatches(s.doc) .map(|(name, paint)| { - let paint = paint.clone(); - PresetRow::item(name.clone(), name.clone(), 0) - .preview(ThumbAspect::SQUARE, move |painter, rect| paint_preview::paint_rect(painter, rect, &paint)) + PresetRow::item(name.clone(), name.clone(), 0).preview_face(ThumbAspect::SQUARE, paint_preview::rect_face(paint)) }) .collect() }); diff --git a/crates/ui-egui/src/panels/color_guide.rs b/crates/ui-egui/src/panels/color_guide.rs index 12052fa25c..9897c096a1 100644 --- a/crates/ui-egui/src/panels/color_guide.rs +++ b/crates/ui-egui/src/panels/color_guide.rs @@ -568,19 +568,29 @@ fn spot_paints(app: &VectorcraftApp, rule: Harmony) -> Vec<(usize, Paint)> { .collect() } -/// What a cell applies, carries and saves: the spot tint of the base row ([`spot_paints`]) or the -/// color it shows. -fn tint_or_solid(tints: &[(usize, Paint)], cell: &GuideCell) -> Paint { - match cell.at { - GuideCellAt::Grid { row: 0, column } => tints.iter().find(|(col, _)| *col == column).map(|(_, p)| p.clone()), +/// The grid row and column of a cell at `at`; none for a cell of the harmony strip. +fn grid_spot(at: GuideCellAt) -> Option<(usize, usize)> { + match at { + GuideCellAt::Grid { row, column, .. } => Some((row, column)), _ => None, } - .unwrap_or_else(|| Paint::solid(color_of(cell.color))) +} + +/// The spot tint of base-row column `column` ([`spot_paints`]), if it has one. +fn tint_at(tints: &[(usize, Paint)], spot: Option<(usize, usize)>) -> Option<&Paint> { + let (0, column) = spot? else { return None }; + tints.iter().find(|(col, _)| *col == column).map(|(_, p)| p) +} + +/// What a cell at grid spot `spot` showing `color` applies, carries and saves: the spot tint of the +/// base row or the color it shows. +fn tint_or_solid(tints: &[(usize, Paint)], spot: Option<(usize, usize)>, color: Srgba) -> Paint { + tint_at(tints, spot).cloned().unwrap_or_else(|| Paint::solid(color_of(color))) } /// What a cell carries when dragged. -fn drag_payload(tints: &[(usize, Paint)], cell: &GuideCell) -> PanelDrag { - PanelDrag::paint(tint_or_solid(tints, cell)) +fn drag_payload(tints: &[(usize, Paint)], spot: Option<(usize, usize)>, color: Srgba) -> PanelDrag { + PanelDrag::paint(tint_or_solid(tints, spot, color)) } /// `ui.colorGuideLimit {library}`: limit the panel's colours to a swatch library (an id or name), @@ -606,26 +616,20 @@ fn edit_or_apply(app: &mut VectorcraftApp) { app.run("ui.recolorDialog", p).ok(); } -/// The `swatch.new` / `swatch.newGroup` entries of `cells` (grid cells, in the order given: the -/// framework keeps picked cells in grid order, each once). -fn cell_entries(app: &VectorcraftApp, g: &Guide, cells: &[GuideCell]) -> Vec { - cells - .iter() - .filter_map(|cell| match cell.at { - GuideCellAt::Grid { row, column } => cell_entry(app, g, row, column), - GuideCellAt::Strip(_) => None, - }) - .collect() +/// The `swatch.new` / `swatch.newGroup` entries of the grid cells at `cells` (row, column), in the +/// order given: the framework keeps picked cells in grid order, each once. +fn cell_entries(app: &VectorcraftApp, g: &Guide, cells: &[(usize, usize)]) -> Vec { + cells.iter().filter_map(|&(row, column)| cell_entry(app, g, row, column)).collect() } -/// The cells picked for Save Colors as Swatches. -fn picked(app: &VectorcraftApp) -> Vec { - app.ui.color_guide_panel.picked.cells().to_vec() +/// The grid cells picked for Save Colors as Swatches. +fn picked(app: &VectorcraftApp) -> Vec<(usize, usize)> { + app.ui.color_guide_panel.picked.cells().iter().filter_map(|cell| grid_spot(cell.at)).collect() } /// Save `cells`' colors as swatches (one undo step), each in its own model; a tint of a spot color /// base becomes a tint swatch of it. -fn save_selected(app: &mut VectorcraftApp, cells: &[GuideCell]) { +fn save_selected(app: &mut VectorcraftApp, cells: &[(usize, usize)]) { let g = guide(app); let colors = cell_entries(app, &g, cells); if !colors.is_empty() { @@ -636,7 +640,7 @@ fn save_selected(app: &mut VectorcraftApp, cells: &[GuideCell]) { /// Save Color Group to Swatches: `cells` as one swatch group in the order given; with none, the /// harmony colors. The group is named after the harmony rule, saved in one undo step, and each /// color keeps its own model; a tint of a spot color base becomes a tint swatch of it. -fn save_group(app: &mut VectorcraftApp, cells: &[GuideCell]) { +fn save_group(app: &mut VectorcraftApp, cells: &[(usize, usize)]) { let g = guide(app); let mut colors = cell_entries(app, &g, cells); if colors.is_empty() { @@ -647,8 +651,8 @@ fn save_group(app: &mut VectorcraftApp, cells: &[GuideCell]) { /// A cell of the guide was clicked: apply its paint to the active proxy (the inactive one with Alt /// held), leaving the base as it is. -fn chosen(app: &mut VectorcraftApp, ui: &Ui, cell: GuideCell) { - let paint = tint_or_solid(&spot_paints(app, app.ui.color_guide_panel.rule), &cell); +fn chosen(app: &mut VectorcraftApp, ui: &Ui, spot: Option<(usize, usize)>, color: Srgba) { + let paint = tint_or_solid(&spot_paints(app, app.ui.color_guide_panel.rule), spot, color); apply_click(app, ui, paint_params(&paint)); } @@ -733,11 +737,11 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { // The body can run more than once in a pass: each run starts from nothing chosen. let payload_tints = tints.clone(); let mut panel = HarmonyPanel::new(Bind::bound(&mut state), Bind::bound(&mut model.picked), base) - .cell_color(|c: &GuideCell| match c.at { - GuideCellAt::Grid { row: 0, column } => tint_colors.iter().find(|(col, _)| *col == column).map_or(c.color, |(_, s)| *s), + .cell_color(|c: &GuideCell| match grid_spot(c.at) { + Some((0, column)) => tint_colors.iter().find(|(col, _)| *col == column).map_or(c.color, |(_, s)| *s), _ => c.color, }) - .drag_payload(move |c: &GuideCell| Some(drag_payload(&payload_tints, c))); + .drag_payload(move |c: &GuideCell| Some(drag_payload(&payload_tints, grid_spot(c.at), c.color))); if let Some(palette) = limit { panel = panel.limit(palette); } @@ -753,7 +757,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { set_base(app); } if let Some(cell) = cell { - chosen(app, ui, cell); + chosen(app, ui, grid_spot(cell.at), cell.color); } if let Some(key) = limit_picked { set_limit(app, &json!({ "library": key })).ok(); @@ -817,25 +821,31 @@ mod tests { Guide::new(base_color(app), app.ui.color_guide_panel.rule, &app.ui.color_guide) } - /// The cell at `at` of `g`, as the panel reports a click on it. - fn cell_at(g: &Guide, at: GuideCellAt) -> GuideCell { - let color = match at { - GuideCellAt::Strip(i) => g.colors[i], - GuideCellAt::Grid { row, column } => g.grid[row][column], - }; - GuideCell { at, color: srgba(&color) } + /// Where a cell lies: the harmony strip's cell at an index, or the grid's at a row and column. + #[derive(Clone, Copy, Debug)] + enum At { + Strip(usize), + Grid(usize, usize), + } + + /// The grid spot and colour of the cell at `at` of `g`, as the panel reports a click on it. + fn cell_at(g: &Guide, at: At) -> (Option<(usize, usize)>, Srgba) { + match at { + At::Strip(i) => (None, srgba(&g.colors[i])), + At::Grid(row, column) => (Some((row, column)), srgba(&g.grid[row][column])), + } } /// A click on the cell at `at` of the guide shown now, through the panel's click glue. - fn click(app: &mut VectorcraftApp, at: GuideCellAt) { - let cell = cell_at(&guide_of(app), at); - let mut out = crate::testing::ui_context().run_ui(egui::RawInput::default(), |ui| chosen(app, ui, cell)); + fn click(app: &mut VectorcraftApp, at: At) { + let (spot, color) = cell_at(&guide_of(app), at); + let mut out = crate::testing::ui_context().run_ui(egui::RawInput::default(), |ui| chosen(app, ui, spot, color)); out.textures_delta.clear(); } /// A cell of grid row `row` and column `column`. - fn grid(row: usize, column: usize) -> GuideCellAt { - GuideCellAt::Grid { row, column } + fn grid(row: usize, column: usize) -> At { + At::Grid(row, column) } /// The first show takes the current color; a color chosen in the Color panel, Swatches or the @@ -876,7 +886,7 @@ mod tests { frame(&mut app, &ctx); let g = guide_of(&app); let fill = |app: &VectorcraftApp| crate::panels::current_paints(app).0.color().map(|c| c.to_hex()); - click(&mut app, GuideCellAt::Strip(1)); + click(&mut app, At::Strip(1)); assert_eq!(fill(&app), Some(g.colors[1].to_hex()), "the harmony color paints the art"); assert_eq!(base_color(&app).to_hex(), "#3366cc", "and leaves the base"); click(&mut app, grid(0, 2)); @@ -889,19 +899,13 @@ mod tests { assert_eq!(base_color(&app).to_hex(), variation, "the base chip adopts the current color"); } - /// The cells at `at` of the guide shown now, as the panel reports them picked. - fn picked_cells(app: &VectorcraftApp, at: &[(usize, usize)]) -> Vec { - let g = guide_of(app); - at.iter().map(|&(row, column)| cell_at(&g, grid(row, column))).collect() - } - #[test] fn save_colors_as_swatches_saves_each_selected_cell() { let mut app = app(); let ctx = crate::testing::ui_context(); frame(&mut app, &ctx); let before = app.session.doc().unwrap().doc.swatches.len(); - let cells = picked_cells(&app, &[(0, 0), (1, 4), (0, 8)]); + let cells = &[(0, 0), (1, 4), (0, 8)].to_vec(); let undo = app.session.doc().unwrap().history.undo.len(); save_selected(&mut app, &cells); let st = app.session.doc().unwrap(); @@ -919,7 +923,7 @@ mod tests { app.run("paint.setFill", json!({"color": "#3366cc", "keepModel": true})).unwrap(); let ctx = crate::testing::ui_context(); frame(&mut app, &ctx); - let cells = picked_cells(&app, &[(0, 0), (0, 6)]); + let cells = &[(0, 0), (0, 6)].to_vec(); save_selected(&mut app, &cells); let g = guide_of(&app); assert!(matches!(g.grid[0][6], Color::Rgb { .. }), "{:?}", g.grid[0][6]); @@ -943,7 +947,7 @@ mod tests { frame(&mut app, &ctx); let st = app.session.doc().unwrap(); let (groups, swatches, undo) = (st.doc.swatch_groups.len(), st.doc.swatches.len(), st.history.undo.len()); - let cells = picked_cells(&app, &[(0, 0), (0, 8), (1, 4)]); + let cells = &[(0, 0), (0, 8), (1, 4)].to_vec(); save_group(&mut app, &cells); let g = guide_of(&app); let st = app.session.doc().unwrap(); @@ -979,7 +983,7 @@ mod tests { let ctx = crate::testing::ui_context(); frame(&mut app, &ctx); let g = guide(&mut app); - let cells: Vec = [(0, 1), (0, 7)].iter().map(|&(row, column)| cell_at(&g, grid(row, column))).collect(); + let cells = [(0, 1), (0, 7)]; save_group(&mut app, &cells); let made = last_group(&app).1; assert_eq!(made, [g.grid[0][1], g.grid[0][7]]); @@ -1038,7 +1042,7 @@ mod tests { assert_eq!(base_color(&app), red, "the base follows the spot color"); frame(&mut app, &ctx); // Shades, another harmony row and the harmony strip are process colors. - for at in [grid(0, c - 1), grid(1, c + 1), GuideCellAt::Strip(0)] { + for at in [grid(0, c - 1), grid(1, c + 1), At::Strip(0)] { click(&mut app, at); assert_eq!(fill_link(&app).0, None, "{at:?}"); } @@ -1470,7 +1474,7 @@ mod tests { let g = guide_of(&app); let c = g.centre(); let undo = app.session.doc().unwrap().history.undo.len(); - let cells = picked_cells(&app, &[(0, c + 1), (0, c - 1), (0, c + 3)]); + let cells = &[(0, c + 1), (0, c - 1), (0, c + 3)].to_vec(); save_selected(&mut app, &cells); let st = app.session.doc().unwrap(); assert_eq!(st.history.undo.len(), undo + 1, "one undo step"); @@ -1482,7 +1486,7 @@ mod tests { assert_eq!(tint(&made[2]).map(|(b, _)| b).as_deref(), Some("Ink")); assert!(made[0].name.starts_with("Ink ") && made[0].name.ends_with('%'), "{}", made[0].name); // A group of the selected cells, in grid order. - let cells = picked_cells(&app, &[(0, c + 2), (1, c + 1)]); + let cells = &[(0, c + 2), (1, c + 1)].to_vec(); save_group(&mut app, &cells); let group = app.session.doc().unwrap().doc.swatch_groups.last().cloned().unwrap(); assert_eq!(group.swatches.len(), 2); @@ -1503,14 +1507,14 @@ mod tests { let mut app = spot_app(1.0); let c = guide_of(&app).centre(); let tints = spot_paints(&app, app.ui.color_guide_panel.rule); - let cell = cell_at(&guide_of(&app), grid(0, c + 1)); - let PanelDrag::Paint { paint, .. } = drag_payload(&tints, &cell) else { panic!("a paint drag") }; + let (spot, color) = cell_at(&guide_of(&app), grid(0, c + 1)); + let PanelDrag::Paint { paint, .. } = drag_payload(&tints, spot, color) else { panic!("a paint drag") }; let Paint::Solid { swatch, tint, .. } = &paint else { panic!("a solid paint: {paint:?}") }; assert_eq!(swatch.as_deref(), Some("Ink")); assert!((tint - expected_tint(&app, 1.0, 1)).abs() < 1e-4); // A cell outside the tint row carries its color alone. - let shade = cell_at(&guide_of(&app), grid(0, c - 1)); - assert!(matches!(drag_payload(&tints, &shade), PanelDrag::Paint { paint: Paint::Solid { swatch: None, .. }, .. })); + let (spot, color) = cell_at(&guide_of(&app), grid(0, c - 1)); + assert!(matches!(drag_payload(&tints, spot, color), PanelDrag::Paint { paint: Paint::Solid { swatch: None, .. }, .. })); app.run("swatch.new", paint_params(&paint)).unwrap(); let newest = app.session.doc().unwrap().doc.swatches.last().cloned().expect("a swatch"); let (base, made) = newest.tint_of().unwrap_or_else(|| panic!("a tint swatch: {newest:?} {}", app.ui.status)); diff --git a/crates/ui-egui/src/panels/color_themes.rs b/crates/ui-egui/src/panels/color_themes.rs index b152be5f28..4a1452d4ac 100644 --- a/crates/ui-egui/src/panels/color_themes.rs +++ b/crates/ui-egui/src/panels/color_themes.rs @@ -11,7 +11,7 @@ use std::borrow::Cow; use craft::behavior::{DisplayOrder, IconId, ItemSource, Selection, SelectionChange}; -use craft::color_ui::ui::{ChannelRow, ChannelRule, ColorPanelMode, HarmonyWheel}; +use craft::color_ui::ui::{ChannelRow, ColorPanelMode, HarmonyWheel}; use craft::theme::variant::Tone; use craft::theme::{ModelValues, Rgba}; use craft::ui::buttons::IconButton; @@ -309,7 +309,7 @@ fn sliders(ui: &mut Ui, d: &mut Draft, mode_pick: &mut Option, h srgba(&color_of_values(&probe)) }) .collect(); - let rule = ChannelRule { range: lo..=hi, step: 1.0, decimals: 0 }; + let rule = super::whole_steps(lo..=hi); let Some(row) = ChannelRow::new(letter, Bind::given(value), rule).short(letter).track(track).show(ui) else { continue }; for event in row.events { if let Some(&nv) = event.value().filter(|v| v.is_finite()) { diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index 3e15595455..8e8c9226ea 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -51,7 +51,7 @@ use std::sync::Arc; use craft::behavior::Mixed; use craft::behavior::Selection; use craft::color_ui::AreaMode; -use craft::color_ui::ui::{ChannelRow, ChannelRule, ChannelUnit, ColorArea, ColorStrip, ColorWheel, WheelInner}; +use craft::color_ui::ui::{ChannelRow, ChannelUnit, ColorArea, ColorStrip, ColorWheel, WheelInner}; use craft::keymap::CommandRef; use craft::theme::{ColorModel, HsbModel, ModelValues, RgbModel, Srgba}; use craft::ui::choice::{SwatchSpacing, SwatchTable}; @@ -1004,7 +1004,7 @@ fn oklch_rows(app: &mut VectorcraftApp, panel: &mut WheelUi, ui: &mut Ui, cx: &P // The rows read dim and take no edit without a colour to edit. Stack::new().enabled(enabled).show(ui, |ui, _| { for (i, &(letter, ref name, max, unit)) in rows.iter().enumerate() { - let rule = ChannelRule { range: 0.0..=max, step: 1.0, decimals: 0 }; + let rule = super::whole_steps(0.0..=max); let mut row = ChannelRow::new(name.clone(), Bind::given(shown[i].clamp(0.0, max)), rule).short(letter).unit(unit); if enabled { row = row.track(oklch_stops(panel, lch, i, max, max_c)); @@ -1045,7 +1045,7 @@ fn hsl_rows(app: &mut VectorcraftApp, panel: &mut WheelUi, ui: &mut Ui, cx: &Pic // The rows read dim and take no edit without a colour to edit. Stack::new().enabled(enabled).show(ui, |ui, _| { for (i, &(letter, ref name, max, unit)) in rows.iter().enumerate() { - let rule = ChannelRule { range: 0.0..=max, step: 1.0, decimals: 0 }; + let rule = super::whole_steps(0.0..=max); let mut row = ChannelRow::new(name.clone(), Bind::given(shown[i].clamp(0.0, max)), rule).short(letter).unit(unit); if enabled { let last = (HSL_STOPS - 1) as f64; diff --git a/crates/ui-egui/src/panels/glyphs.rs b/crates/ui-egui/src/panels/glyphs.rs index 525bd66dd9..b00398ef09 100644 --- a/crates/ui-egui/src/panels/glyphs.rs +++ b/crates/ui-egui/src/panels/glyphs.rs @@ -193,6 +193,7 @@ fn gid_of_cell(face: &FontFace, cell: GlyphCell) -> Option { match cell { GlyphCell::Char(c) => gid_of(face, c), GlyphCell::Glyph(g) => Some(g), + _ => None, } } @@ -435,6 +436,7 @@ impl GlyphSource for VcGlyphs<'_> { (None, None) => Some(unencoded_tip(face, g)), }; } + _ => {} } info } @@ -446,6 +448,7 @@ impl GlyphSource for VcGlyphs<'_> { match cell { GlyphCell::Char(c) => list.extend(face.alternates(c).into_iter().map(|a| a.gid)), GlyphCell::Glyph(g) => list.extend(face.substitutions(g).into_iter().flat_map(|s| s.glyphs)), + _ => {} } let mut seen = HashSet::new(); list.retain(|g| seen.insert(*g)); @@ -516,6 +519,7 @@ pub(crate) fn activate(app: &mut VectorcraftApp, cell: GlyphCell) { } } GlyphCell::Glyph(gid) => put_on_selection(app, &face, gid), + _ => {} } } @@ -527,7 +531,7 @@ pub(crate) fn pick_alternate(app: &mut VectorcraftApp, cell: GlyphCell, glyph: G GlyphCell::Char(c) => insert_alternate(app, &face, c, gid, picked), // A glyph no character maps goes on the selected character as a double-click on its cell // in Entire Font puts it. - GlyphCell::Glyph(_) => put_on_selection(app, &face, picked), + _ => put_on_selection(app, &face, picked), } } diff --git a/crates/ui-egui/src/panels/gradient.rs b/crates/ui-egui/src/panels/gradient.rs index 049048a3f9..8f9d83a4b1 100644 --- a/crates/ui-egui/src/panels/gradient.rs +++ b/crates/ui-egui/src/panels/gradient.rs @@ -60,7 +60,7 @@ use crate::VectorcraftApp; use crate::dialogs::gradient_stop::{self, Anchor}; use crate::edits::{EditPath, apply_edits}; // PLAN: assumed widgets-w13's `paint_preview::{paint_face(&GradientPaint) -> FacePaint, paint_rect(&ContentPainterCx, Rect, &Paint)}` (wg.S6). -use crate::paint_preview::{paint_face, paint_rect}; +use crate::paint_preview::{paint_face, rect_face}; // PLAN: assumed widgets-w13's `panel_drag::PanelDrag` with `Paint { params, .. }` and `color(&self) -> Option` (wg.S7). use crate::panel_drag::PanelDrag; @@ -518,9 +518,7 @@ fn preset_rows(app: &VectorcraftApp) -> Vec> { rows.push(PresetRow::group(PresetKey::Library(e.library), e.library.map_or(tl!("Saved"), |l| tl!(l)), 0)); } let paint = Paint::Gradient(Box::new(GradientPaint::new(e.gradient))); - rows.push( - PresetRow::item(PresetKey::Preset(e.name.clone()), e.name, 1).preview(ThumbAspect::SQUARE, move |cx, rect| paint_rect(cx, rect, &paint)), - ); + rows.push(PresetRow::item(PresetKey::Preset(e.name.clone()), e.name, 1).preview_face(ThumbAspect::SQUARE, rect_face(&paint))); } rows } diff --git a/crates/ui-egui/src/shortcut_editor.rs b/crates/ui-egui/src/shortcut_editor.rs index 9da16750e5..a9bac740f5 100644 --- a/crates/ui-egui/src/shortcut_editor.rs +++ b/crates/ui-egui/src/shortcut_editor.rs @@ -971,7 +971,7 @@ pub(crate) struct ShortcutsDialogState { pub(crate) fn open(app: &mut VectorcraftApp) { let (min, max) = vectorcraft_engine::KEY_HOLD_DELAY_RANGE; let prefs = &app.session.prefs; - let hold = HoldSetting { on: prefs.hold_shortcuts, delay: prefs.key_hold_delay(), range: min..=max }; + let hold = HoldSetting::new(prefs.hold_shortcuts, prefs.key_hold_delay(), min..=max); app.shortcuts_dialog = Some(ShortcutsDialogState { state: DialogState::new().with_tab("tools"), keymap: None, diff --git a/crates/ui-egui/src/type_editing.rs b/crates/ui-egui/src/type_editing.rs index bb4d46decf..6f44a6d3b7 100644 --- a/crates/ui-egui/src/type_editing.rs +++ b/crates/ui-egui/src/type_editing.rs @@ -196,7 +196,7 @@ impl<'a> TypeEditor<'a> { let key = if forward { ToolKey::Delete } else { ToolKey::Backspace }; text_key(app, key, Mods { cmd: !matches!(by, Granularity::Unit), ..Mods::default() }); } - EditorInput::Newline => text_key(app, ToolKey::Enter, Mods::default()), + EditorInput::Newline { shift, .. } => text_key(app, ToolKey::Enter, Mods { shift, ..Mods::default() }), EditorInput::Tab => text_key(app, ToolKey::Tab, Mods::default()), EditorInput::Edit(command) => match command { EditCommand::Copy => {