GSpinBox.h 834 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <LibGUI/GWidget.h>
  3. class GButton;
  4. class GTextEditor;
  5. class GSpinBox : public GWidget {
  6. C_OBJECT(GSpinBox)
  7. public:
  8. virtual ~GSpinBox() override;
  9. int value() const { return m_value; }
  10. void set_value(int);
  11. int min() const { return m_min; }
  12. int max() const { return m_max; }
  13. void set_min(int min) { set_range(min, max()); }
  14. void set_max(int max) { set_range(min(), max); }
  15. void set_range(int min, int max);
  16. Function<void(int value)> on_change;
  17. protected:
  18. explicit GSpinBox(GWidget* parent = nullptr);
  19. virtual void resize_event(GResizeEvent&) override;
  20. private:
  21. ObjectPtr<GTextEditor> m_editor;
  22. GButton* m_increment_button { nullptr };
  23. GButton* m_decrement_button { nullptr };
  24. int m_min { 0 };
  25. int m_max { 100 };
  26. int m_value { 0 };
  27. };