2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-02-26 10:50:04 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-04-09 16:29:00 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/Widget.h>
|
2019-04-09 16:29:00 +02:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
namespace GUI {
|
2019-04-09 16:29:00 +02:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
class SpinBox : public Widget {
|
|
|
|
|
C_OBJECT(SpinBox)
|
2019-04-09 16:29:00 +02:00
|
|
|
public:
|
2022-02-26 10:50:04 -07:00
|
|
|
virtual ~SpinBox() override = default;
|
2019-04-09 16:29:00 +02:00
|
|
|
|
|
|
|
|
int value() const { return m_value; }
|
2021-09-21 17:02:48 -04:00
|
|
|
void set_value(int, AllowCallback = AllowCallback::Yes);
|
2019-04-09 16:29:00 +02:00
|
|
|
|
2019-04-12 15:17:53 +02:00
|
|
|
int min() const { return m_min; }
|
|
|
|
|
int max() const { return m_max; }
|
2021-09-21 17:02:48 -04:00
|
|
|
void set_min(int min, AllowCallback allow_callback = AllowCallback::Yes) { set_range(min, max(), allow_callback); }
|
|
|
|
|
void set_max(int max, AllowCallback allow_callback = AllowCallback::Yes) { set_range(min(), max, allow_callback); }
|
|
|
|
|
void set_range(int min, int max, AllowCallback = AllowCallback::Yes);
|
2019-04-09 16:29:00 +02:00
|
|
|
|
|
|
|
|
Function<void(int value)> on_change;
|
|
|
|
|
|
|
|
|
|
protected:
|
2020-02-23 12:07:13 +01:00
|
|
|
SpinBox();
|
2019-09-21 16:15:11 +02:00
|
|
|
|
2020-02-24 10:20:25 +01:00
|
|
|
virtual void mousewheel_event(MouseEvent&) override;
|
2020-02-02 15:07:41 +01:00
|
|
|
virtual void resize_event(ResizeEvent&) override;
|
2019-04-09 16:29:00 +02:00
|
|
|
|
|
|
|
|
private:
|
2020-02-02 15:07:41 +01:00
|
|
|
RefPtr<TextEditor> m_editor;
|
2021-02-27 08:23:42 -05:00
|
|
|
RefPtr<Button> m_increment_button;
|
|
|
|
|
RefPtr<Button> m_decrement_button;
|
2019-04-09 16:29:00 +02:00
|
|
|
|
|
|
|
|
int m_min { 0 };
|
|
|
|
|
int m_max { 100 };
|
|
|
|
|
int m_value { 0 };
|
|
|
|
|
};
|
2020-02-02 15:07:41 +01:00
|
|
|
|
|
|
|
|
}
|