UI: one After Effects-style colour picker with a hex field for every colour input

Every colour input opens one picker laid out like After Effects' Color
Picker: a square and slider for the channel chosen with H / S / B /
R / G / B, the new colour over the original, HSB and RGB fields, a hex
field (#RRGGBB, RRGGBB, #RGB) and OK / Cancel. Changes apply live;
Cancel, Escape and the original swatch restore the starting colour.

The 3D light dialog, Essential Graphics and Layer Styles passed sRGB
values to egui's color_edit_button_rgb(a), which reads them as linear,
so picked colours were stored darker (#808080 became #373737). They and
the other dialogs now use the shared sRGB colour button.

The picker and colour helpers live in color_picker.rs; widgets
re-exports them.

Tests: ui_color_hex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
FrederoxDev
2026-10-10 19:26:20 +01:00
co-authored by Claude Opus 5.5
parent 1e61b4e04b
commit c8657bf214
17 changed files with 678 additions and 68 deletions
+12 -4
View File
@@ -38,6 +38,12 @@ fn hex(c: [u8; 3]) -> String {
format!("#{:02x}{:02x}{:02x}", c[0], c[1], c[2])
}
/// sRGB components (0–1) as bytes.
fn srgb_bytes(c: [f32; 3]) -> [u8; 3] {
let col = crate::widgets::srgb32(c);
[col.r(), col.g(), col.b()]
}
fn reg(app: &mut EffectcraftApp, id: &str, r: &egui::Response, label: &str) {
app.auto.add(id, r.rect, label);
}
@@ -178,8 +184,9 @@ fn page_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, page: &Page, cur: &Value
}
Kind::Color => {
let c = crate::panels::viewer::hex_rgb(v.as_str().unwrap_or("")).unwrap_or([128, 128, 128]);
let mut rgb = c;
let r = ui.color_edit_button_srgb(&mut rgb);
let mut f = c.map(|v| v as f32 / 255.0);
let r = crate::widgets::srgb_color_button(ui, &mut f);
let rgb = if r.changed() { srgb_bytes(f) } else { c };
ui.label(RichText::new(hex(rgb)).monospace().color(t.text_dim));
if rgb != c {
acts.push(Act::Set(key.into(), json!(hex(rgb))));
@@ -559,8 +566,9 @@ fn labels_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, cur: &Value, acts: &mu
egui::Grid::new("settings-labels").num_columns(4).spacing([10.0, 4.0]).show(ui, |ui| {
for (i, l) in labels.iter().enumerate() {
let c = crate::panels::viewer::hex_rgb(l["color"].as_str().unwrap_or("")).unwrap_or([128, 128, 128]);
let mut rgb = c;
let r = ui.color_edit_button_srgb(&mut rgb);
let mut f = c.map(|v| v as f32 / 255.0);
let r = crate::widgets::srgb_color_button(ui, &mut f);
let rgb = if r.changed() { srgb_bytes(f) } else { c };
app.auto.add(&format!("settings.labels.{i}.color"), r.rect, "label colour");
if rgb != c {
acts.push(Act::Set(format!("labels.{i}.color"), json!(hex(rgb))));