Serenity Operating System
at master 47 lines 1.2 kB view raw
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 8#pragma once 9 10#include <LibGUI/Widget.h> 11 12namespace GUI { 13 14class SpinBox : public Widget { 15 C_OBJECT(SpinBox) 16public: 17 virtual ~SpinBox() override = default; 18 19 int value() const { return m_value; } 20 void set_value(int, AllowCallback = AllowCallback::Yes); 21 22 int min() const { return m_min; } 23 int max() const { return m_max; } 24 void set_min(int min, AllowCallback allow_callback = AllowCallback::Yes) { set_range(min, max(), allow_callback); } 25 void set_max(int max, AllowCallback allow_callback = AllowCallback::Yes) { set_range(min(), max, allow_callback); } 26 void set_range(int min, int max, AllowCallback = AllowCallback::Yes); 27 28 Function<void(int value)> on_change; 29 Function<void()> on_return_pressed; 30 31protected: 32 SpinBox(); 33 34 virtual void mousewheel_event(MouseEvent&) override; 35 virtual void resize_event(ResizeEvent&) override; 36 37private: 38 RefPtr<TextEditor> m_editor; 39 RefPtr<Button> m_increment_button; 40 RefPtr<Button> m_decrement_button; 41 42 int m_min { 0 }; 43 int m_max { 100 }; 44 int m_value { 0 }; 45}; 46 47}