Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

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

semmelrinde0515dee9cef7
diff --git a/assets/locales/pending/color-channel-names.json b/assets/locales/pending/color-channel-names.json
new file mode 100644
index 0000000000..8fa193b0ed
--- /dev/null
+++ b/assets/locales/pending/color-channel-names.json
@@ -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": "红色"
+ }
+}
diff --git a/crates/ui-egui/src/ui_kit/color.rs b/crates/ui-egui/src/ui_kit/color.rs
index dfef5e72aa..3f181be176 100644
--- a/crates/ui-egui/src/ui_kit/color.rs
+++ b/crates/ui-egui/src/ui_kit/color.rs
@@ -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();
diff --git a/crates/ui-egui/src/ui_kit/color_tests.rs b/crates/ui-egui/src/ui_kit/color_tests.rs
index ffc05c0f05..8e417c1146 100644
--- a/crates/ui-egui/src/ui_kit/color_tests.rs
+++ b/crates/ui-egui/src/ui_kit/color_tests.rs
@@ -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));
+}