Colour popover: a held step button keeps stepping, and R, G and B have tooltips (#10201) (#10203)

* Colour popover: a held step button keeps stepping, and R, G and B have tooltips (#10201)

The step buttons beside each colour number sensed clicks only. egui
stops counting a press as a possible click once it outlasts its longest
click (0.8 s), so the held button stopped repeating after 8 steps. They
now sense drags too, which keeps a long press down on the button until
it is let go.

R, G and B now carry tooltips (Red, Green, Blue) as H, S and V already
did: a single letter doesn't name the colour in every language.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Colour popover: the R, G and B tooltips in Vietnamese too, a complete catalog (#10201)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
semmelrinde
2026-11-01 20:08:43 +00:00
committed by GitHub
parent 0478f7e401
commit 0515dee9ce
3 changed files with 91 additions and 3 deletions
@@ -0,0 +1,42 @@
{
"ar": {
"color.blue": "أزرق",
"color.green": "أخضر",
"color.red": "أحمر"
},
"de": {
"color.blue": "Blau",
"color.green": "Grün",
"color.red": "Rot"
},
"en": {
"color.blue": "Blue",
"color.green": "Green",
"color.red": "Red"
},
"he": {
"color.blue": "כחול",
"color.green": "ירוק",
"color.red": "אדום"
},
"ja": {
"color.blue": "青",
"color.green": "緑",
"color.red": "赤"
},
"ko": {
"color.blue": "파랑",
"color.green": "초록",
"color.red": "빨강"
},
"vi": {
"color.blue": "Xanh dương",
"color.green": "Xanh lá",
"color.red": "Đỏ"
},
"zh": {
"color.blue": "蓝色",
"color.green": "绿色",
"color.red": "红色"
}
}
+9 -3
View File
@@ -205,8 +205,11 @@ fn color_popover_with_opacity(ui: &mut Ui, rgb: &mut [u8; 3], mut opacity: Optio
Spin { max: 255.0, step: 1.0, speed: 0.5, decimals: 0 }
};
ui.columns(3, |columns| {
for ((ui, channel), name) in columns.iter_mut().zip(channels.iter_mut()).zip(["R", "G", "B"]) {
edited |= spin_channel(ui, name, None, channel, spin);
// Named like H, S and V: "R" alone doesn't say red in every language (#10201).
for ((ui, channel), (name, tip)) in
columns.iter_mut().zip(channels.iter_mut()).zip([("R", "color.red"), ("G", "color.green"), ("B", "color.blue")])
{
edited |= spin_channel(ui, name, Some(i18n::tr(tip)), channel, spin);
}
});
}
@@ -436,7 +439,10 @@ fn spin_buttons(ui: &mut Ui, key: &str, height: f32) -> i32 {
let mut steps = 0;
for (direction, half, label, end) in [(1, top, "color.step_up", "up"), (-1, bottom, "color.step_down", "down")] {
let id = ui.id().with(("color_spin", key, end));
let response = ui.interact(half, id, Sense::click());
// Sensing drags too keeps a long press down on the button: a press that senses clicks
// only stops counting once it outlasts egui's longest click (0.8 s), and the repeat with
// it, after 8 steps (#10201).
let response = ui.interact(half, id, Sense::click_and_drag());
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), i18n::tr(label)));
publish(&format!("color:spin:{key}:{end}"), &response);
let held = response.is_pointer_button_down_on();
+40
View File
@@ -501,3 +501,43 @@ fn recent_colours_are_saved_with_the_preferences_and_hostile_entries_dropped() {
assert_eq!(restored.ui.recent_colors.get(1), Some(&[1, 2, 3]));
assert_eq!(restored.ui.recent_colors.len(), MAX_RECENT_COLORS);
}
/// #10201: a step button held down keeps stepping until it is let go, past egui's longest click
/// (0.8 s): two seconds of holding H's up button step it about 32 degrees, not the 8 a press
/// counted as a click managed before it stopped.
#[test]
fn a_held_step_button_keeps_stepping_until_it_is_let_go() {
let ctx = crate::fonts::test_context();
let mut rgb = [255, 0, 0];
let at_time = |time: f64, events: Vec<egui::Event>, rgb: &mut [u8; 3]| {
scenario::clear_handles();
let _ = crate::test_support::frame(
&ctx,
egui::RawInput {
screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(320.0, 600.0))),
events,
time: Some(time),
focused: true,
..Default::default()
},
|ui| {
ui.set_width(280.0);
ui.push_id("picker", |ui| crate::ui_kit::scope(ui, |ui| color_popover(ui, rgb)));
},
);
};
at_time(0.0, vec![], &mut rgb);
let up = scenario::handle_at("color:spin:H:up").expect("H's up button");
at_time(0.01, pointer(up, true), &mut rgb);
for frame in 1..=120 {
at_time(0.01 + f64::from(frame) / 60.0, vec![egui::Event::PointerMoved(up)], &mut rgb);
}
let hue = |rgb: [u8; 3]| HsvaGamma::from(Color32::from_rgb(rgb[0], rgb[1], rgb[2])).h * 360.0;
let held = hue(rgb);
assert!(held > 20.0, "two seconds held stepped the hue to {held:.1} degrees");
at_time(2.1, pointer(up, false), &mut rgb);
for frame in 1..=30 {
at_time(2.1 + f64::from(frame) / 60.0, vec![], &mut rgb);
}
assert!((hue(rgb) - held).abs() < 1.5, "let go, it stops: {} after {held}", hue(rgb));
}