SpinBox.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. void set_value_from_current_text();
  17. int min() const { return m_min; }
  18. int max() const { return m_max; }
  19. void set_min(int min, AllowCallback allow_callback = AllowCallback::Yes) { set_range(min, max(), allow_callback); }
  20. void set_max(int max, AllowCallback allow_callback = AllowCallback::Yes) { set_range(min(), max, allow_callback); }
  21. void set_range(int min, int max, AllowCallback = AllowCallback::Yes);
  22. Function<void(int value)> on_change;
  23. Function<void()> on_return_pressed;
  24. protected:
  25. SpinBox();
  26. virtual void mousewheel_event(MouseEvent&) override;
  27. virtual void resize_event(ResizeEvent&) override;
  28. private:
  29. RefPtr<TextEditor> m_editor;
  30. RefPtr<Button> m_increment_button;
  31. RefPtr<Button> m_decrement_button;
  32. int m_min { 0 };
  33. int m_max { 100 };
  34. int m_value { 0 };
  35. };
  36. }