Merge pull request #2634 from davidmann4/fix/picker-full-hex-enter

Color Picker: Enter in the Full layout's hex field confirms
This commit is contained in:
David Mann authored and GitHub committed 2026-11-20 21:11:43 +01:00
commit 399922917f
2 files changed
+33 -5

No files matched your search

+7 -5
View File
@@ -127,12 +127,14 @@ impl<'a> Body<'a> {
}
}
/// The hex field, at `sizing` when given. The picker's first show focuses it, its text selected. Enter in it
/// commits the typed digits and does not reach the dialog's OK, as in the production Colors dialog.
/// The hex field, at `sizing` when given. The picker's first show focuses it, its text selected. In the Compact
/// layout (the tabbed Colors dialog) Enter in it commits the typed digits and does not reach the dialog's OK, as in
/// the production Colors dialog. In the Full layout Enter commits the digits and confirms the dialog, as in the
/// reference image editor's Color Picker.
pub(super) fn hex_field(&self, ui: &mut Ui, pass: &Pass<'a>, words: &ColorPickerWords, sizing: Option<Sizing>, got: &mut Collected) {
let field = TextField::hex(words.hex.as_str().to_owned(), Bind::given(pass.shows(pass.shown.color.to_rgba())))
.empty(pass.shown.color.to_rgba())
.submits();
let field =
TextField::hex(words.hex.as_str().to_owned(), Bind::given(pass.shows(pass.shown.color.to_rgba()))).empty(pass.shown.color.to_rgba());
let field = if self.layout == ColorPickerLayout::Compact { field.submits() } else { field };
let edit = match sizing {
Some(sizing) => field.sizing(sizing),
None => field,
+26
View File
@@ -450,3 +450,29 @@ fn the_tabbed_colors_dialog_opens_on_its_tab_and_answers_from_either_page() {
let answered = dialogs.borrow_mut().take::<ColorPickerDialog>().and_then(DialogResult::ok).map(|result| result.picked.color.to_hex());
assert_eq!(answered.as_deref(), Some("#0000ff"));
}
/// The Full dialog opens with its hex field focused and selected; digits typed there and Enter commit the colour and
/// confirm the dialog, as in the reference image editor's Color Picker (the tabbed Colors dialog keeps Enter in the
/// field instead).
#[trial]
fn enter_in_the_full_dialogs_hex_field_confirms_the_typed_colour() {
let dialogs = Rc::new(RefCell::new(DialogHost::new()));
let shown = Rc::clone(&dialogs);
let mut fixture = Fixture::new(move |ui| shown.borrow_mut().run(ui));
fixture.room(vec2(900.0, 700.0));
fixture.host(std::sync::Arc::new(Host::builder(AppInfo { id: "picker-test", name: "Picker test", version: "0" }).build()));
let colour = |hex: &str| Srgba::from_hex(hex).expect("a colour");
dialogs
.borrow_mut()
.open(ColorPickerDialog::new("foreground", "Color Picker (Foreground Color)", colour("#000000")).web_colors_remembered(false));
fixture.idle(6);
assert!(dialogs.borrow().get::<ColorPickerDialog>().is_some(), "the picker is open");
fixture.type_text("336699");
fixture.key(Key::Enter, Modifiers::NONE);
fixture.settle();
assert!(dialogs.borrow().get::<ColorPickerDialog>().is_none(), "Enter in the hex field confirms the dialog");
let answer = dialogs.borrow_mut().take::<ColorPickerDialog>();
let Some(DialogResult::Ok(result)) = answer else { panic!("the dialog answers OK") };
assert_eq!(result.picked.color.to_hex(), "#336699", "with the typed colour");
}