C++ DevKit
C++ set of OOP library
Loading...
Searching...
No Matches
ui_core.h
Go to the documentation of this file.
1
11#pragma once
12
13#include "pico/stdlib.h"
16#include "sw/widget/widget.h"
17
18#include <vector>
19#include <map>
20#include <string>
21#include <set>
22
24#define UI_MODEL_OBJECT_STATUS_TIME_OUT_us 3000000
25
26class UIController;
27class Widget;
28
36class Model
37{
38private:
41
46
47protected:
50 std::set<Widget *> attached_widgets;
51
52public:
54 Model();
55
57 ~Model();
58
61 void update_attached_widgets(Widget *new_widget);
62
66
69 bool has_changed();
70
72 void set_change_flag();
73
75 void draw_widget_done();
76
80
83};
84
87class UIControlledModel : public Model
88{
89private:
92
95
96public:
97 UIControlledModel(/* args */);
99
100
101
105 bool update_status(ControlledObjectStatus _new_status);
111 void update_current_controller(UIController *_new_controller);
118
127
130 virtual void process_control_event(struct_ControlEventData control_event) = 0;
131};
132
140class UIControlledIncrementalValue : public UIControlledModel
141{
142private:
143protected:
145 int value;
155
156public:
166 UIControlledIncrementalValue(int min_value = 0, int max_value = 10, bool is_wrappable = false, int increment = 1);
172
175 virtual bool increment_value();
176
179 virtual bool decrement_value();
180
184 bool set_clipped_value(int _new_value);
190 int get_value();
196 int get_min_value();
202 int get_max_value();
203};
204
216{
217protected:
229
234 virtual void increment_focus();
239 virtual void decrement_focus();
240
241public:
246 std::vector<UIControlledModel *> managed_models;
252
262 void make_manager_active();
263
269 UIModelManager(bool is_wrappable = false);
280 void add_managed_model(UIControlledModel *_new_model);
281};
282
288{
289protected:
290public:
298 UIController(/* args */);
312 void update_current_controlled_object(UIControlledModel *_new_controlled_object);
313};
int get_number_of_attached_widget()
get the number of attached widgets
Definition ui_core.cpp:16
void update_attached_widgets(Widget *new_widget)
add a new widget to the set of attached_widgets
Definition ui_core.cpp:11
void set_change_flag()
Set the change flag object to true.
Definition ui_core.cpp:26
void draw_widget_done()
Set the change flag object to false.
Definition ui_core.cpp:32
bool has_changed()
get the change flag status
Definition ui_core.cpp:21
uint32_t get_time_since_last_change()
compute time since the last status change
Definition ui_core.cpp:37
std::set< Widget * > attached_widgets
the set of widgets that are in charge of viewing this model.
Definition ui_core.h:50
int change_flag
The semaphore used to trigger the actual drawing of the widget on the screen. It is set with the numb...
Definition ui_core.h:45
virtual void draw_refresh_all_attached_widgets()
update drawing for each attached widgets
Definition ui_core.cpp:42
uint32_t last_change_time
the time in microseconds since the last status has changed
Definition ui_core.h:40
~Model()
Destroy the Model object.
Definition ui_core.cpp:7
Model()
Construct the Model object.
Definition ui_core.cpp:3
~UIControlledIncrementalValue()
Destroy the UIControlledIncrementalValue object.
Definition ui_core.cpp:58
int increment
The number that is added or substracted to the current value. Default to 1.
Definition ui_core.h:151
virtual bool decrement_value()
Substract "increment" to the current value.
Definition ui_core.cpp:77
int get_max_value()
Get the max value object.
Definition ui_core.cpp:115
int value
The internal value incremented or decremented by action on the controller.
Definition ui_core.h:145
int get_min_value()
Get the min value object.
Definition ui_core.cpp:110
virtual bool increment_value()
Add "increment" to the current value.
Definition ui_core.cpp:62
int max_value
The maximum value that can be reached. Can be either negative or positive.
Definition ui_core.h:147
bool is_wrappable
If true, once the max (resp. min) value is reached, the next one wraps to min (resp*; max) value....
Definition ui_core.h:154
int get_value()
Get the value object.
Definition ui_core.cpp:105
bool set_clipped_value(int _new_value)
Set value to _new_value, and clip the result to min or max value if needed.
Definition ui_core.cpp:92
UIControlledIncrementalValue(int min_value=0, int max_value=10, bool is_wrappable=false, int increment=1)
Construct a new UIControlledIncrementalValue object.
Definition ui_core.cpp:48
int min_value
The minimum value that can be reached. Can be either negative or positive.
Definition ui_core.h:149
Class that adds UI Controller to the basic Model class.
Definition ui_core.h:88
UIController * get_current_controller()
Get the current controller object.
Definition ui_core.cpp:246
bool update_status(ControlledObjectStatus _new_status)
update the status of the model object.
Definition ui_core.cpp:220
ControlledObjectStatus get_status()
Get the status object.
Definition ui_core.cpp:241
void update_current_controller(UIController *_new_controller)
if _new_controller is different from the current controller, change the current controller associated...
Definition ui_core.cpp:232
virtual void process_control_event(struct_ControlEventData control_event)=0
pure virtual function that process a control event
UIController * current_controller
A pointer to the controller of this model.
Definition ui_core.h:94
ControlledObjectStatus status
The status of the model, indicating if it is waiting, active or just ahs focus (pointed by the object...
Definition ui_core.h:91
UIController is the abstract class that hosts all controller object in the Model-View-Controll design...
Definition ui_core.h:288
UIControlledModel * current_controlled_model
The reference to the Model currently under control.
Definition ui_core.h:294
UIController()
create a UIController object
Definition ui_core.cpp:193
void update_current_controlled_object(UIControlledModel *_new_controlled_object)
if the current controlled object is different from _new_controlled_object, change the current control...
Definition ui_core.cpp:201
~UIController()
Destroy the UIController object.
Definition ui_core.cpp:197
void make_manager_active()
leave the current managed object and return control to the manager
Definition ui_core.cpp:186
void make_managed_model_active()
change the status of model object under focus to IS_ACTIVE
Definition ui_core.cpp:179
void add_managed_model(UIControlledModel *_new_model)
add a new Model to the list of managed objects.
Definition ui_core.cpp:132
UIControlledModel * current_active_model
the reference to the current active model object
Definition ui_core.h:251
virtual void increment_focus()
set focus on the next model in the list.
Definition ui_core.cpp:138
ControlledObjectStatusTimeOutReason check_time_out(uint32_t managed_object_status_time_out_us=3000000)
check if there is a time out either on the managed models or the manager itself.
Definition ui_core.cpp:156
virtual void decrement_focus()
set focus on the previous model in the list.
Definition ui_core.cpp:147
~UIModelManager()
Destroy the UIModelManager object.
Definition ui_core.cpp:127
std::vector< UIControlledModel * > managed_models
The list of managed objects.
Definition ui_core.h:246
UIModelManager(bool is_wrappable=false)
Construct a new UIModelManager object.
Definition ui_core.cpp:120
A widget is a displayed object on a device screen. This is the base widget, it is derived as GraphicW...
Definition widget.h:100
this is the structure used to transmit control event through a RTOS queue
Definition ui_control_event.h:46
ControlledObjectStatusTimeOutReason
The list of reason of manager time out report. (0) NO_TIME_OUT (1) MANAGER_INACTIVE (3) MANAGED_OBJEC...
Definition ui_control_event.h:76
ControlledObjectStatus
The list of status that a Model can have. (0) IS_WAITING (1) HAS_FOCUS (2) IS_ACTIVE.
Definition ui_control_event.h:58
@ IS_WAITING
the object has done its job and is waiting for the next activation
Definition ui_control_event.h:62
#define UI_MODEL_OBJECT_STATUS_TIME_OUT_us
the time out used by the UIModelManager that indicates there is no more UI_ModelObject Status change.
Definition ui_core.h:24