Skip to content

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

Color panel: the Tint field keeps typed text and applies it on Enter or leaving the field

Guillem Hermida939d5676cb5e
diff --git a/ROADMAP.md b/ROADMAP.md
index 9f8168e50..dda2d5e99 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -132,6 +132,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.m
Newest first.
+- **2026-10-14** · The Color panel's Tint field keeps what is typed while it has focus and applies it on Enter or when it loses focus, clamped to 0–100 %. Typing 60 over 100 % no longer snaps back to 100 after the first digit (10060), and a typed tint is no longer ignored. No readiness percentage change.
- **2026-10-13** · Object › Fitting has InDesign's shortcuts: Fill Frame Proportionally ⌘⌥⇧C, Fit Content Proportionally ⌘⌥⇧E, Fit Frame to Content ⌘⌥C, Fit Content to Frame ⌘⌥E, Center Content ⌘⇧E. No readiness percentage change.
- **2026-10-13** · Gradients between process colours blend as inks, as InDesign shows them: magenta to cyan passes through C 50 M 50 (a light lilac) on screen instead of the darker RGB mix, and a midpoint between CMYK or grey stops no longer turns the PDF shading RGB. No readiness percentage change.
- **2026-10-14** · The Swatches panel has InDesign's header: a Fill/Stroke proxy, Formatting Affects Container/Text and the Tint of the colour in front (a tint alone keeps each object's own swatch). Clicking a swatch applies it to the fill or stroke in front (of the text, when formatting affects text), and the bottom row has New Color Group, New Swatch and Delete Swatch. No readiness percentage change.
diff --git a/crates/ui-egui/src/panels/color_panel_tests.rs b/crates/ui-egui/src/panels/color_panel_tests.rs
new file mode 100644
index 000000000..cd102b2e3
--- /dev/null
+++ b/crates/ui-egui/src/panels/color_panel_tests.rs
@@ -0,0 +1,83 @@
+//! Color panel: the Tint field of a named swatch.
+
+use egui::accesskit::Role;
+use egui::vec2;
+use egui_kittest::Harness;
+use egui_kittest::kittest::Queryable;
+use serde_json::json;
+
+use crate::DesignApp;
+
+fn harness(app: DesignApp) -> Harness<'static, DesignApp> {
+ Harness::builder().with_size(vec2(320.0, 320.0)).build_ui_state(|ui, app: &mut DesignApp| super::swatches::color_panel(app, ui), app)
+}
+
+fn fill_tint(app: &DesignApp, id: u64) -> f32 {
+ app.session.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().fill.tint
+}
+
+/// The Tint row is the panel's first value field, above the C/M/Y/K fields.
+fn click_tint_field(h: &mut Harness<'static, DesignApp>) {
+ let at = h
+ .query_all_by(|n| matches!(n.role(), Role::SpinButton | Role::TextInput))
+ .map(|n| n.rect())
+ .min_by(|a, b| a.min.y.total_cmp(&b.min.y))
+ .unwrap()
+ .center();
+ h.hover_at(at);
+ h.drag_at(at);
+ h.drop_at(at);
+ h.run_steps(2);
+}
+
+fn typed(h: &Harness<'static, DesignApp>) -> Option<String> {
+ h.query_by(|n| n.is_focused()).and_then(|n| n.value())
+}
+
+/// Typing "60" over "100%" keeps the text while the field has focus (it used to snap back to
+/// 100 after the first digit, giving 10060), applies it on Enter, and a value out of range is
+/// clamped when the field loses focus.
+#[test]
+fn a_typed_tint_is_kept_while_typing_and_applied_on_enter_or_leaving_the_field() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let id = app.run("frame.create", json!({"rect": [36, 36, 200, 200], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();
+ app.run("object.fill", json!({"ids": [id], "swatch": "C=100 M=0 Y=0 K=0"})).unwrap();
+ app.run("selection.set", json!({"ids": [id]})).unwrap();
+ let mut h = harness(app);
+ h.run_steps(3);
+ click_tint_field(&mut h);
+ h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
+ h.run_steps(2);
+ for digit in ["6", "0"] {
+ h.event(egui::Event::Text(digit.into()));
+ h.run_steps(3);
+ }
+ assert_eq!(typed(&h).as_deref(), Some("60"), "the typed text stays while the field has focus");
+ assert_eq!(fill_tint(h.state(), id), 1.0, "nothing is applied while typing");
+ h.key_press(egui::Key::Enter);
+ h.run_steps(3);
+ assert!((fill_tint(h.state(), id) - 0.6).abs() < 1e-6, "Enter applies 60 %: {}", fill_tint(h.state(), id));
+ assert_eq!(h.state().session.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().fill.swatch, "C=100 M=0 Y=0 K=0");
+ // Out of range: clamped to 100 % when focus moves away.
+ click_tint_field(&mut h);
+ h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
+ h.event(egui::Event::Text("150".into()));
+ h.run_steps(3);
+ let away = egui::pos2(300.0, 310.0);
+ h.hover_at(away);
+ h.drag_at(away);
+ h.drop_at(away);
+ h.run_steps(3);
+ assert_eq!(fill_tint(h.state(), id), 1.0, "150 is clamped to 100 % when the field loses focus");
+ // The slider still applies on release.
+ let track = h.get_by_role(Role::Slider).rect();
+ h.hover_at(track.right_center());
+ h.drag_at(track.right_center());
+ h.run_steps(1);
+ h.hover_at(track.left_center());
+ h.run_steps(1);
+ h.drop_at(track.left_center());
+ h.run_steps(3);
+ assert_eq!(fill_tint(h.state(), id), 0.0, "dragging the slider to the left end applies 0 %");
+}
diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rs
index baf9a1251..1feaaa6e1 100644
--- a/crates/ui-egui/src/panels/mod.rs
+++ b/crates/ui-egui/src/panels/mod.rs
@@ -13,6 +13,9 @@ pub mod styles;
pub mod swatches;
pub mod table;
+#[cfg(test)]
+mod color_panel_tests;
+
use designcraft_doc::{Content, StrokeAlign, WrapMode};
use designcraft_geom::Rect;
use egui::vec2;
diff --git a/crates/ui-egui/src/panels/swatches.rs b/crates/ui-egui/src/panels/swatches.rs
index aea4e4acc..7ea1d8a0a 100644
--- a/crates/ui-egui/src/panels/swatches.rs
+++ b/crates/ui-egui/src/panels/swatches.rs
@@ -364,12 +364,25 @@ pub fn color_panel(app: &mut DesignApp, ui: &mut egui::Ui) {
if let Some(sw) = sw.as_ref().filter(|w| !w.hidden && !w.locked) {
let cur = if stroke { stroke_tint } else { fill_tint };
let mut tint = cur * 100.0;
+ let mut commit = None;
ui.horizontal(|ui| {
ui.label("T");
- if ui.add(egui::Slider::new(&mut tint, 0.0..=100.0).suffix("%").integer()).drag_stopped() {
- let _ = super::apply_swatch(app, stroke, &sw.name, Some(tint / 100.0));
+ // The slider applies on release. The field keeps typed text while it has focus (the
+ // tint is read back from the document every frame) and applies it, clamped, on Enter
+ // or when it loses focus.
+ ui.spacing_mut().slider_width = (ui.available_width() - 60.0).max(60.0);
+ if ui.add(egui::Slider::new(&mut tint, 0.0..=100.0).integer().show_value(false)).drag_stopped() {
+ commit = Some(tint);
+ }
+ if let Some(v) =
+ crate::widgets::NumField::number("color_tint", Some(f64::from(cur) * 100.0), "%", 0).width(44.0).range(0.0, 100.0).show(ui)
+ {
+ commit = Some(v as f32);
}
});
+ if let Some(v) = commit {
+ let _ = super::apply_swatch(app, stroke, &sw.name, Some(v / 100.0));
+ }
}
let mut send: Option<serde_json::Value> = None;
match mode {