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
41
55
56class UIController;
57class Widget;
58
66class Model
67{
68private:
70 uint32_t last_change_time;
71
75 int change_flag;
76
77protected:
80 std::set<Widget *> attached_widgets;
81
82public:
84 Model();
85
87 ~Model();
88
91 void update_attached_widgets(Widget *new_widget);
92
96
99 bool has_changed();
100
102 void set_change_flag();
103
105 void draw_widget_done();
106
110
113};
114
117class UIControlledModel : public Model
118{
119private:
122
124 UIController *current_controller{nullptr};
125
126public:
127 UIControlledModel(/* args */);
128 ~UIControlledModel();
134 void update_status(ControlledObjectStatus _new_status);
140 void update_current_controller(UIController *_new_controller);
147
156
162 virtual void process_control_event(UIControlEvent _event) = 0;
163};
164
172class UIControlledIncrementalValue : public UIControlledModel
173{
174private:
175protected:
177 int value;
187
188public:
198 UIControlledIncrementalValue(int min_value = 0, int max_value = 10, bool is_wrappable = false, int increment = 1);
208 virtual void increment_value();
213 virtual void decrement_value();
219 void set_clipped_value(int _new_value);
225 int get_value();
231 int get_min_value();
237 int get_max_value();
238};
239
251{
252protected:
268 std::vector<UIControlledModel *> managed_models;
283 void make_manager_active();
288 virtual void increment_focus();
293 virtual void decrement_focus();
294
295public:
301 UIModelManager(bool is_wrappable = false);
312 void add_managed_model(UIControlledModel *_new_model);
313};
314
320{
321protected:
322public:
330 UIController(/* args */);
344 void update_current_controlled_object(UIControlledModel *_new_controlled_object);
345};
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:80
virtual void draw_refresh_all_attached_widgets()
update drawing for each attached widgets
Definition ui_core.cpp:42
~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:183
virtual void increment_value()
Add "increment" to the current value.
Definition ui_core.cpp:62
int get_max_value()
Get the max value object.
Definition ui_core.cpp:100
int value
The internal value incremented or decremented by action on the controller.
Definition ui_core.h:177
int get_min_value()
Get the min value object.
Definition ui_core.cpp:95
void 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:82
int max_value
The maximum value that can be reached. Can be either negative or positive.
Definition ui_core.h:179
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:186
int get_value()
Get the value object.
Definition ui_core.cpp:90
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:181
virtual void decrement_value()
Substract "increment" to the current value.
Definition ui_core.cpp:72
Class that adds UI Controller to the basic Model class.
Definition ui_core.h:118
UIController * get_current_controller()
Get the current controller object.
Definition ui_core.cpp:227
ControlledObjectStatus get_status()
Get the status object.
Definition ui_core.cpp:222
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:213
virtual void process_control_event(UIControlEvent _event)=0
The purpose of this function is to implement the behavior of the implemented model object when a Cont...
void update_status(ControlledObjectStatus _new_status)
check if the _new_status change is effective, then change it and set the change_flag to true.
Definition ui_core.cpp:204
UIController is the abstract class that hosts all controller object in the Model-View-Controll design...
Definition ui_core.h:320
UIControlledModel * current_controlled_model
The reference to the Model currently under control.
Definition ui_core.h:326
UIController()
create a UIController object
Definition ui_core.cpp:178
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:186
~UIController()
Destroy the UIController object.
Definition ui_core.cpp:182
void make_manager_active()
leave the current managed object and return control to the manager
Definition ui_core.cpp:171
void make_managed_model_active()
change the status of model object under focus to IS_ACTIVE
Definition ui_core.cpp:164
void add_managed_model(UIControlledModel *_new_model)
add a new Model to the list of managed objects.
Definition ui_core.cpp:117
UIControlledModel * current_active_model
the reference to the current active model object
Definition ui_core.h:273
virtual void increment_focus()
set focus on the next model in the list.
Definition ui_core.cpp:123
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:141
virtual void decrement_focus()
set focus on the previous model in the list.
Definition ui_core.cpp:132
~UIModelManager()
Destroy the UIModelManager object.
Definition ui_core.cpp:112
std::vector< UIControlledModel * > managed_models
The list of managed objects.
Definition ui_core.h:268
UIModelManager(bool is_wrappable=false)
Construct a new UIModelManager object.
Definition ui_core.cpp:105
A widget is a displayed object on a device screen. This is the base widget, it is derived as GraphicW...
Definition widget.h:100
UIControlEvent
The list of predefined events that a button, or more generally an User Interface Controller,...
Definition ui_control_event.h:18
ControlledObjectStatusTimeOutReason
The list of reason of manager time out report. (0) NO_TIME_OUT (1) MANAGER_INACTIVE (3) MANAGED_OBJEC...
Definition ui_core.h:47
@ NO_TIME_OUT
no time out
Definition ui_core.h:49
@ MANAGER_INACTIVE
The object is inactive, nothing to do.
Definition ui_core.h:51
@ MANAGED_OBJECT_INACTIVE
The widget or object manager is pointing to this model.
Definition ui_core.h:53
ControlledObjectStatus
The list of status that a Model can have. (0) IS_WAITING (1) HAS_FOCUS (2) IS_ACTIVE.
Definition ui_core.h:31
@ IS_WAITING
The object is inactive, nothing to do.
Definition ui_core.h:33
@ IS_ACTIVE
The user has selected (clicked) on this model. ControlEvent are then passed to this model in order to...
Definition ui_core.h:39
@ HAS_FOCUS
The widget or object manager is pointing to this model.
Definition ui_core.h:36
#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