SpinBox.h 1.2 KB

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