mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
LibGUI: Add a spinbox widget.
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.
This commit is contained in:
parent
4ba5e472be
commit
4c0f586f2b
4 changed files with 115 additions and 14 deletions
31
LibGUI/GSpinBox.h
Normal file
31
LibGUI/GSpinBox.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#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 };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue