Browse Source

LibGUI: Require a full click on ColorInput's color rect to open picker

Let's not open the ColorPicker on mousedown, that was too jarring.
Andreas Kling 5 years ago
parent
commit
cdbc252190
2 changed files with 16 additions and 4 deletions
  1. 14 4
      Libraries/LibGUI/ColorInput.cpp
  2. 2 0
      Libraries/LibGUI/ColorInput.h

+ 14 - 4
Libraries/LibGUI/ColorInput.cpp

@@ -71,9 +71,21 @@ void ColorInput::set_color(Color color)
 };
 
 void ColorInput::mousedown_event(MouseEvent& event)
+{
+    if (event.button() == MouseButton::Left && color_rect().contains(event.position())) {
+        m_may_be_color_rect_click = true;
+        return;
+    }
+
+    TextEditor::mousedown_event(event);
+}
+
+void ColorInput::mouseup_event(MouseEvent& event)
 {
     if (event.button() == MouseButton::Left) {
-        if (is_enabled() && color_rect().contains(event.position())) {
+        bool is_color_rect_click = m_may_be_color_rect_click && color_rect().contains(event.position());
+        m_may_be_color_rect_click = false;
+        if (is_color_rect_click) {
             auto dialog = GUI::ColorPicker::construct(m_color, window(), m_color_picker_title);
             dialog->set_color_has_alpha_channel(m_color_has_alpha_channel);
             if (dialog->exec() == GUI::Dialog::ExecOK)
@@ -82,8 +94,7 @@ void ColorInput::mousedown_event(MouseEvent& event)
             return;
         }
     }
-
-    TextEditor::mousedown_event(event);
+    TextEditor::mouseup_event(event);
 }
 
 void ColorInput::mousemove_event(MouseEvent& event)
@@ -109,5 +120,4 @@ void ColorInput::paint_event(PaintEvent& event)
     painter.fill_rect(color_rect(), m_color);
     painter.draw_rect(color_rect(), Color::Black);
 }
-
 }

+ 2 - 0
Libraries/LibGUI/ColorInput.h

@@ -50,6 +50,7 @@ public:
 
 protected:
     virtual void mousedown_event(MouseEvent&) override;
+    virtual void mouseup_event(MouseEvent&) override;
     virtual void mousemove_event(MouseEvent&) override;
     virtual void paint_event(PaintEvent&) override;
 
@@ -62,6 +63,7 @@ private:
     Color m_color;
     String m_color_picker_title { "Select color" };
     bool m_color_has_alpha_channel { true };
+    bool m_may_be_color_rect_click { false };
 };
 
 }