GAbstractButton.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <LibGUI/GWidget.h>
  3. class GAbstractButton : public GWidget {
  4. public:
  5. virtual ~GAbstractButton() override;
  6. Function<void(bool)> on_checked;
  7. void set_text(const String&);
  8. const String& text() const { return m_text; }
  9. bool is_checked() const { return m_checked; }
  10. void set_checked(bool);
  11. bool is_checkable() const { return m_checkable; }
  12. void set_checkable(bool);
  13. bool is_hovered() const { return m_hovered; }
  14. bool is_being_pressed() const { return m_being_pressed; }
  15. virtual void click() = 0;
  16. virtual const char* class_name() const override { return "GAbstractButton"; }
  17. virtual bool accepts_focus() const override { return true; }
  18. protected:
  19. explicit GAbstractButton(GWidget* parent);
  20. GAbstractButton(const String&, GWidget* parent);
  21. virtual void mousedown_event(GMouseEvent&) override;
  22. virtual void mousemove_event(GMouseEvent&) override;
  23. virtual void mouseup_event(GMouseEvent&) override;
  24. virtual void keydown_event(GKeyEvent&) override;
  25. virtual void enter_event(CEvent&) override;
  26. virtual void leave_event(CEvent&) override;
  27. private:
  28. String m_text;
  29. bool m_checked { false };
  30. bool m_checkable { false };
  31. bool m_hovered { false };
  32. bool m_being_pressed { false };
  33. };