SpinBox.h 956 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibGUI/Widget.h>
  8. namespace GUI {
  9. class SpinBox : public Widget {
  10. C_OBJECT(SpinBox)
  11. public:
  12. virtual ~SpinBox() override;
  13. int value() const { return m_value; }
  14. void set_value(int);
  15. int min() const { return m_min; }
  16. int max() const { return m_max; }
  17. void set_min(int min) { set_range(min, max()); }
  18. void set_max(int max) { set_range(min(), max); }
  19. void set_range(int min, int max, bool change = true);
  20. Function<void(int value)> on_change;
  21. protected:
  22. SpinBox();
  23. virtual void mousewheel_event(MouseEvent&) override;
  24. virtual void resize_event(ResizeEvent&) override;
  25. private:
  26. RefPtr<TextEditor> m_editor;
  27. RefPtr<Button> m_increment_button;
  28. RefPtr<Button> m_decrement_button;
  29. int m_min { 0 };
  30. int m_max { 100 };
  31. int m_value { 0 };
  32. };
  33. }