ValueSlider.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2021, Marcus Nilsson <brainbomb@gmail.com>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibGUI/AbstractSlider.h>
  9. namespace GUI {
  10. class ValueSlider : public AbstractSlider {
  11. C_OBJECT(ValueSlider);
  12. public:
  13. enum class KnobStyle {
  14. Wide,
  15. Thin,
  16. };
  17. virtual ~ValueSlider() override = default;
  18. void set_suffix(String suffix) { m_suffix = move(suffix); }
  19. void set_knob_style(KnobStyle knobstyle) { m_knob_style = knobstyle; }
  20. virtual void set_value(int value, AllowCallback = AllowCallback::Yes, DoClamp = DoClamp::Yes) override;
  21. protected:
  22. virtual void paint_event(PaintEvent&) override;
  23. virtual void mousedown_event(MouseEvent&) override;
  24. virtual void mousemove_event(MouseEvent&) override;
  25. virtual void mouseup_event(MouseEvent&) override;
  26. virtual void mousewheel_event(MouseEvent&) override;
  27. virtual void leave_event(Core::Event&) override;
  28. private:
  29. explicit ValueSlider(Gfx::Orientation = Gfx::Orientation::Horizontal, String suffix = "");
  30. String formatted_value() const;
  31. int value_at(Gfx::IntPoint const& position) const;
  32. Gfx::IntRect bar_rect() const;
  33. Gfx::IntRect knob_rect() const;
  34. String m_suffix {};
  35. Orientation m_orientation { Orientation::Horizontal };
  36. KnobStyle m_knob_style { KnobStyle::Thin };
  37. RefPtr<GUI::TextBox> m_textbox;
  38. bool m_dragging { false };
  39. bool m_hovered { false };
  40. };
  41. }