Max OS 0.3
Loading...
Searching...
No Matches
inputbox.h
Go to the documentation of this file.
1
9#ifndef MAXOS_GUI_WIDGETS_INPUTBOX_H
10#define MAXOS_GUI_WIDGETS_INPUTBOX_H
11
12#include <cstdint>
13#include <gui/widget.h>
14#include <gui/font.h>
15#include <common/string.h>
16
17namespace MaxOS::gui::widgets {
18
19
24 enum class InputBoxEvents {
25 TEXT_CHANGED
26 };
27
32 class InputBoxTextChangedEvent : public common::Event<InputBoxEvents> {
33 public:
34 InputBoxTextChangedEvent(const string&);
36
37 string new_text;
38 };
39
44 class InputBoxEventHandler : public common::EventHandler<InputBoxEvents> {
45 public:
48
50
51 virtual void on_input_box_text_changed(const string& text);
52 };
53
58 class InputBox : public Widget, public common::EventManager<InputBoxEvents> {
59
60 protected:
62 string m_widget_text = " ";
63
64 public:
65 InputBox(int32_t left, int32_t top, uint32_t width, uint32_t height);
66 InputBox(int32_t left, int32_t top, uint32_t width, uint32_t height, const string& text);
67 ~InputBox();
68
70
71 void on_focus() override;
72 void on_focus_lost() override;
73
74 void on_key_down(drivers::peripherals::KeyCode key_down_code, const drivers::peripherals::KeyboardState& key_down_state) override;
75
76 void update_text(const string&);
77 string text();
78
79 // InputBox Variables
84 uint32_t cursor_position { 0 };
85
86 };
87}
88
89#endif //MAXOS_GUI_WIDGETS_INPUTBOX_H
Stores the red, green, blue and alpha values of a colour. Can be parsed from a hex string,...
Definition colour.h:91
Used to handle an event.
Manages the m_handlers for a type of event, raises events and calls the m_handlers.
Used to store information about an event, has a type and a return value.
Draws pixels to the screen, and handles drawing lines, rectangles and circles.
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
Holds the state of the keyboard.
Definition keyboard.h:216
A class that can be used to draw text.
Definition font.h:27
A graphical object that can be drawn on the screen.
Definition widget.h:29
Handles input box events.
Definition inputbox.h:44
virtual void on_input_box_text_changed(const string &text)
Event triggered when the text in the input box is changed.
Definition inputbox.cpp:44
common::Event< InputBoxEvents > * on_event(common::Event< InputBoxEvents > *event) override
Delegates an event to the event handler for that event type.
Definition inputbox.cpp:28
Event that is triggered when the text in an input box is changed.
Definition inputbox.h:32
string new_text
The new text in the input box.
Definition inputbox.h:37
A box that can be used to input text.
Definition inputbox.h:58
void draw(common::GraphicsContext *gc, common::Rectangle< int32_t > &area) override
Draw an area of the input box onto a graphics context.
Definition inputbox.cpp:96
void update_text(const string &)
Update the text in the input box.
Definition inputbox.cpp:264
common::Colour background_colour
The background colour of the input box.
Definition inputbox.h:80
void on_focus() override
Update the border when the input box is focussed.
Definition inputbox.cpp:157
common::Colour foreground_colour
The colour of the text in the input box.
Definition inputbox.h:81
void on_key_down(drivers::peripherals::KeyCode key_down_code, const drivers::peripherals::KeyboardState &key_down_state) override
Handles a keypress event by updating the rendered text in the input box.
Definition inputbox.cpp:180
string text()
Get the text currently in the input box.
Definition inputbox.cpp:281
void on_focus_lost() override
Reset to the original input box style when it is no longer focussed.
Definition inputbox.cpp:167
common::Colour border_colour
The colour of the bar around the input box.
Definition inputbox.h:82
gui::Font font
The font to use for the input box text.
Definition inputbox.h:83
uint32_t cursor_position
How many characters into the text the cursor is.
Definition inputbox.h:84
string m_widget_text
The text in the input box.
Definition inputbox.h:62
Defines a Font class for drawing text onto a graphics context.
InputBoxEvents
The events that an input box can trigger.
Definition inputbox.h:24
KeyCode
A mapping of key codes to their values.
Definition keyboard.h:40
Defines a String class for dynamically sized strings with various operations.
Defines a base Widget class and CompositeWidget class for creating graphical user interface elements.