Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(ui): display uppercase hex values in the color picker (#4859)

Nigel Ihza Firdausy625141c2add8
diff --git a/crates/ui-egui/src/color_picker_ui.rs b/crates/ui-egui/src/color_picker_ui.rs
index 24f0afd78..0d51f5d2f 100644
--- a/crates/ui-egui/src/color_picker_ui.rs
+++ b/crates/ui-egui/src/color_picker_ui.rs
@@ -686,7 +686,7 @@ fn fields(ui: &mut egui::Ui, f: &mut Map<String, Value>, mode: &str, now: &Compo
ui.memory_mut(|m| m.request_focus(id));
}
let typing = if ui.memory(|m| m.has_focus(id)) { ui.data(|d| d.get_temp::<String>(id)) } else { None };
- let mut h = typing.unwrap_or_else(|| hex(rgb).trim_start_matches('#').to_string());
+ let mut h = typing.unwrap_or_else(|| hex(rgb).trim_start_matches('#').to_ascii_uppercase());
let r = crate::widgets::text_field_ex(ui, id, &mut h, "", 64.0, true, Some(6));
if r.gained_focus() {
crate::field_tab::select_all(ui.ctx(), id, &h);
@@ -859,6 +859,13 @@ mod tests {
h.state().get("color").and_then(Value::as_str).unwrap().to_string()
}
+ #[test]
+ fn hex_field_shows_uppercase_without_rewriting_the_selected_color() {
+ let h = picker("#12abef");
+ assert_eq!(h.get_by_role(Role::TextInput).value().as_deref(), Some("12ABEF"));
+ assert_eq!(color(&h), "#12abef", "casing is presentation only");
+ }
+
#[test]
fn hex_field_takes_typed_digits() {
let mut h = picker("#000000");