AbstractSlider.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 AbstractSlider : public Widget {
  10. C_OBJECT_ABSTRACT(AbstractSlider);
  11. public:
  12. virtual ~AbstractSlider() override;
  13. void set_orientation(Orientation value);
  14. Orientation orientation() const { return m_orientation; }
  15. int value() const { return m_value; }
  16. int min() const { return m_min; }
  17. int max() const { return m_max; }
  18. int step() const { return m_step; }
  19. int page_step() const { return m_page_step; }
  20. bool jump_to_cursor() const { return m_jump_to_cursor; }
  21. bool is_min() const { return m_value == m_min; }
  22. bool is_max() const { return m_value == m_max; }
  23. void set_range(int min, int max);
  24. virtual void set_value(int, AllowCallback = AllowCallback::Yes);
  25. void set_min(int min) { set_range(min, max()); }
  26. void set_max(int max) { set_range(min(), max); }
  27. void set_step(int step) { m_step = step; }
  28. void set_page_step(int page_step);
  29. void set_jump_to_cursor(bool b) { m_jump_to_cursor = b; }
  30. Function<void(int)> on_change;
  31. protected:
  32. explicit AbstractSlider(Orientation = Orientation::Vertical);
  33. private:
  34. void set_knob_hovered(bool);
  35. int m_value { 0 };
  36. int m_min { 0 };
  37. int m_max { 0 };
  38. int m_step { 1 };
  39. int m_page_step { 10 };
  40. bool m_jump_to_cursor { false };
  41. Orientation m_orientation { Orientation::Horizontal };
  42. };
  43. }