Max OS 0.3
Loading...
Searching...
No Matches
button.h
Go to the documentation of this file.
1
9#ifndef MAXOS_GUI_WIDGETS_BUTTON_H
10#define MAXOS_GUI_WIDGETS_BUTTON_H
11
12#include <cstdint>
13#include <common/eventHandler.h>
14#include <gui/widget.h>
15#include <gui/font.h>
16
17
18namespace MaxOS::gui::widgets {
19
20 //forward declaration
21 class Button;
22
27 enum class ButtonEvents {
28 PRESSED,
29 RELEASED
30 };
31
36 class ButtonPressedEvent : public common::Event<ButtonEvents> {
37 public:
38 explicit ButtonPressedEvent(Button*);
40
42 };
43
48 class ButtonReleasedEvent : public common::Event<ButtonEvents> {
49 public:
50 explicit ButtonReleasedEvent(Button*);
52
54 };
55
61 class ButtonEventHandler : public common::EventHandler<ButtonEvents> {
62 public:
65
67
68 virtual void on_button_pressed(Button* source);
69 virtual void on_button_released(Button* source);
70 };
71
76 class Button : public Widget, public common::EventManager<ButtonEvents> {
77
78 public:
79 Button(int32_t left, int32_t top, uint32_t width, uint32_t height, const string& text);
80 ~Button();
81
82 // Widget Stuff
84 drivers::peripherals::MouseEventHandler* on_mouse_button_pressed(uint32_t x, uint32_t y, uint8_t button) override;
85 void on_mouse_button_released(uint32_t x, uint32_t y, uint8_t button) override;
86
87 // Button Stuff
92 string text;
93 };
94}
95
96
97#endif //MAXOS_GUI_WIDGETS_BUTTON_H
ButtonEvents
The events that a button can trigger.
Definition button.h:27
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
Handles events that are triggered by the mouse driver.
Definition mouse.h:72
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
common::Event< ButtonEvents > * on_event(common::Event< ButtonEvents > *) override
Handles the button events.
Definition button.cpp:28
virtual void on_button_pressed(Button *source)
Handles the button pressed event.
Definition button.cpp:49
virtual void on_button_released(Button *source)
Handles the button released event.
Definition button.cpp:58
Event that is triggered when a button is pressed.
Definition button.h:36
Button * source
The button that triggered the event.
Definition button.h:41
Event that is triggered when a button is released.
Definition button.h:48
Button * source
The button that triggered the event.
Definition button.h:53
A button widget, can be clicked.
Definition button.h:76
void draw(common::GraphicsContext *gc, common::Rectangle< int32_t > &area) override
Draws the button.
Definition button.cpp:90
common::Colour border_colour
The colour of the bar around the button.
Definition button.h:90
common::Colour background_colour
The colour of the button background.
Definition button.h:88
string text
The text to display on the button.
Definition button.h:92
drivers::peripherals::MouseEventHandler * on_mouse_button_pressed(uint32_t x, uint32_t y, uint8_t button) override
Handles the mouse button pressed event.
Definition button.cpp:158
gui::Font font
The font to use for the button text.
Definition button.h:91
void on_mouse_button_released(uint32_t x, uint32_t y, uint8_t button) override
Handles the mouse button released event.
Definition button.cpp:178
common::Colour foreground_colour
The colour of the button text.
Definition button.h:89
Defines classes for handling events and event managers.
Defines a Font class for drawing text onto a graphics context.
Defines a base Widget class and CompositeWidget class for creating graphical user interface elements.