mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 02:25:07 +00:00

This is essentially a combo widget containing a single-line GTextEditor and two buttons for increment and decrement. The GTextEditor::on_change callback is hooked to prevent non-numeric input but it's not entirely perfect since that callback is asynchronous. This will work until we have some more sophisticated input validation mechanism though.
31 lines
621 B
C++
31 lines
621 B
C++
#pragma once
|
|
|
|
#include <LibGUI/GWidget.h>
|
|
|
|
class GButton;
|
|
class GTextEditor;
|
|
|
|
class GSpinBox : public GWidget {
|
|
public:
|
|
GSpinBox(GWidget* parent = nullptr);
|
|
virtual ~GSpinBox() override;
|
|
|
|
int value() const { return m_value; }
|
|
void set_value(int);
|
|
|
|
void set_range(int min, int max);
|
|
|
|
Function<void(int value)> on_change;
|
|
|
|
protected:
|
|
virtual void resize_event(GResizeEvent&) override;
|
|
|
|
private:
|
|
GTextEditor* m_editor { nullptr };
|
|
GButton* m_increment_button { nullptr };
|
|
GButton* m_decrement_button { nullptr };
|
|
|
|
int m_min { 0 };
|
|
int m_max { 100 };
|
|
int m_value { 0 };
|
|
};
|