Serenity Operating System
at master 59 lines 1.7 kB view raw
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 8#pragma once 9 10#include <AK/String.h> 11#include <LibGUI/AbstractSlider.h> 12 13namespace GUI { 14 15class ValueSlider : public AbstractSlider { 16 C_OBJECT(ValueSlider); 17 18public: 19 enum class KnobStyle { 20 Wide, 21 Thin, 22 }; 23 24 virtual ~ValueSlider() override = default; 25 26 void set_suffix(String suffix) { m_suffix = move(suffix); } 27 void set_knob_style(KnobStyle knobstyle) { m_knob_style = knobstyle; } 28 29 virtual void set_value(int value, AllowCallback = AllowCallback::Yes, DoClamp = DoClamp::Yes) override; 30 31protected: 32 virtual void paint_event(PaintEvent&) override; 33 virtual void mousedown_event(MouseEvent&) override; 34 virtual void mousemove_event(MouseEvent&) override; 35 virtual void mouseup_event(MouseEvent&) override; 36 virtual void mousewheel_event(MouseEvent&) override; 37 virtual void leave_event(Core::Event&) override; 38 39private: 40 explicit ValueSlider(Gfx::Orientation = Gfx::Orientation::Horizontal, String suffix = {}); 41 42 DeprecatedString formatted_value() const; 43 int value_at(Gfx::IntPoint position) const; 44 Gfx::IntRect bar_rect() const; 45 Gfx::IntRect knob_rect() const; 46 int knob_length() const; 47 48 virtual Optional<UISize> calculated_min_size() const override; 49 virtual Optional<UISize> calculated_preferred_size() const override; 50 51 String m_suffix {}; 52 Orientation m_orientation { Orientation::Horizontal }; 53 KnobStyle m_knob_style { KnobStyle::Thin }; 54 RefPtr<GUI::TextBox> m_textbox; 55 bool m_dragging { false }; 56 bool m_hovered { false }; 57}; 58 59}