PhotoCraft: An open-source, photo editor written by scratch in pure Rust
The wheel steps the options bar's Mode dropdown for Brush, Pencil and Gradient (#2061) (#4447)
MegaDonc96842f7d94b
diff --git a/contributors/people.toml b/contributors/people.tomlindex f5b001204..30191f52a 100644--- a/contributors/people.toml+++ b/contributors/people.toml@@ -143,3 +143,7 @@ sync_github_name = true[people.deadmeu]sync_github_name = true++[people.megaDon101]+display_name = "megadon"+sync_github_name = falsediff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex b6d844b80..4a05a5728 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -2401,6 +2401,9 @@ mod warp_text_dialog_tests;#[cfg(test)]mod blend_dropdown_wheel_tests;+#[cfg(test)]+mod options_bar_mode_wheel_tests;+#[cfg(test)]mod dropdown_press_tests;diff --git a/crates/ui-egui/src/options_bar_mode_wheel_tests.rs b/crates/ui-egui/src/options_bar_mode_wheel_tests.rsnew file mode 100644index 000000000..068561b4a--- /dev/null+++ b/crates/ui-egui/src/options_bar_mode_wheel_tests.rs@@ -0,0 +1,83 @@+//! #2061: the scroll wheel over the options bar's Mode dropdown (Brush, Pencil, Gradient) steps+//! through the blend modes, as over the Layers panel's (#1747) and as in Photoshop.++use egui::accesskit::Role;+use egui::{Pos2, Rect, vec2};+use egui_kittest::Harness;+use egui_kittest::kittest::Queryable;+use photocraft_doc::BlendMode;+use serde_json::json;++use crate::PhotocraftApp;+use crate::state::Tool;++/// The app with a new document and `tool` chosen.+fn harness(tool: Tool) -> Harness<'static, PhotocraftApp> {+ let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_max_steps(64).build_eframe(move |cc| {+ PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({"width": 64, "height": 48})).unwrap();+ app.ui.tool = tool;+ app+ });+ h.run_steps(8);+ h+}++/// The options bar's Mode dropdown: the highest one showing `Normal` (the Layers panel's is lower).+fn mode_dropdown(h: &Harness<'_, PhotocraftApp>) -> Rect {+ h.query_all_by_role(Role::ComboBox).filter(|n| n.value().as_deref() == Some("Normal")).map(|n| n.rect()).min_by(|a, b| a.top().total_cmp(&b.top())).unwrap()+}++/// `lines` wheel lines at `at` in one event: negative is down.+fn wheel(h: &mut Harness<'_, PhotocraftApp>, at: Pos2, lines: f32) {+ h.hover_at(at);+ h.run_steps(1);+ h.event(egui::Event::MouseWheel {+ unit: egui::MouseWheelUnit::Line,+ delta: vec2(0.0, lines),+ phase: egui::TouchPhase::Move,+ modifiers: Default::default(),+ });+ h.run_steps(3);+}++fn brush_mode(h: &Harness<'_, PhotocraftApp>) -> BlendMode {+ h.state().session.tools.brush.mode+}++#[test]+fn the_wheel_over_the_brush_mode_dropdown_steps_the_painting_mode() {+ let mut h = harness(Tool::Brush);+ let at = mode_dropdown(&h).center();+ assert_eq!(brush_mode(&h), BlendMode::Normal);+ wheel(&mut h, at, -1.0);+ assert_eq!(brush_mode(&h), BlendMode::Dissolve);+ wheel(&mut h, at, -1.0);+ assert!(h.state().ui.tool_options.brush_clear, "Clear follows Dissolve, as in Photoshop");+ wheel(&mut h, at, -1.0);+ assert!(!h.state().ui.tool_options.brush_clear);+ assert_eq!(brush_mode(&h), BlendMode::Darken);+ wheel(&mut h, at, 3.0);+ assert_eq!(brush_mode(&h), BlendMode::Normal, "up steps back and stops at the first mode");+}++#[test]+fn the_wheel_over_the_pencil_mode_dropdown_steps_the_painting_mode() {+ let mut h = harness(Tool::Pencil);+ let at = mode_dropdown(&h).center();+ wheel(&mut h, at, -1.0);+ assert_eq!(brush_mode(&h), BlendMode::Dissolve);+ wheel(&mut h, at, 1.0);+ assert_eq!(brush_mode(&h), BlendMode::Normal);+}++#[test]+fn the_wheel_over_the_gradient_mode_dropdown_steps_its_blend_mode() {+ let mut h = harness(Tool::Gradient);+ let at = mode_dropdown(&h).center();+ wheel(&mut h, at, -2.0);+ assert_eq!(h.state().ui.tool_options.gradient_blend_mode, BlendMode::Darken);+ wheel(&mut h, at, 1.0);+ assert_eq!(h.state().ui.tool_options.gradient_blend_mode, BlendMode::Dissolve);+}diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex 1cc16a1fa..585841042 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -1226,7 +1226,8 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {widgets::vline(ui, 22.0);opt_label(ui, tl!("Mode"));let opts: Vec<(BlendMode, &str)> = BlendMode::LAYER_MODES.iter().map(|m| (*m, m.label())).collect();- widgets::dropdown(ui, "gradient-blend-mode", &mut app.ui.tool_options.gradient_blend_mode, &opts, 96.0);+ // The wheel over it steps the mode, as over the Layers panel's (#2061).+ widgets::dropdown_wheel_hovered(ui, "gradient-blend-mode", &mut app.ui.tool_options.gradient_blend_mode, &opts, 96.0);opt_label(ui, tl!("Opacity"));widgets::value_field(ui, &mut app.ui.tool_options.fill_opacity, 1.0..=100.0, "%", 62.0);widgets::checkbox(ui, &mut app.ui.tool_options.gradient_reverse, tl!("Reverse"));@@ -3576,13 +3577,13 @@ fn brush_tip(p: &egui::Painter, c: egui::Pos2, rad: f32, hardness: f32, color: C/// The Brush's or Pencil's Mode dropdown: the blend modes, with Photoshop's painting-only Clear/// after Dissolve (#3439). Clear erases with the brush (`clear`); it shows while chosen, or while-/// `~` is held (`held`).+/// `~` is held (`held`). The wheel over it steps the mode, as over the Layers panel's (#2061).fn paint_mode_dropdown(ui: &mut egui::Ui, id: &str, b: &mut photocraft_engine::BrushSettings, clear: &mut bool, held: bool) {let mut opts: Vec<(Option<BlendMode>, &str)> = BlendMode::LAYER_MODES.iter().map(|m| (Some(*m), m.label())).collect();let at = opts.iter().position(|o| o.0 == Some(BlendMode::Dissolve)).map_or(opts.len(), |i| i + 1);opts.insert(at, (None, "Clear"));let mut mode = if *clear || held { None } else { Some(b.mode) };- if widgets::dropdown(ui, id, &mut mode, &opts, 96.0) {+ if !widgets::dropdown_wheel_hovered(ui, id, &mut mode, &opts, 96.0).0.is_empty() {*clear = mode.is_none();if let Some(m) = mode {b.mode = m;