MyRP2_ui_core
Loading...
Searching...
No Matches
ui_core.h
Go to the documentation of this file.
1
11#if !defined(UI_CORE_H)
12#define UI_CORE_H
13
14#include "pico/stdlib.h"
15#include "framebuffer.h"
16#include <vector>
17#include <map>
18#include <string>
19
25enum class ControlEvent
26{
27 NOOP,
28 PUSH,
29 DOUBLE_PUSH, // TODO find a way to do "DOUBLE_PUSH"
30 LONG_PUSH,
31 RELEASED_AFTER_LONG_TIME,
32 RELEASED_AFTER_SHORT_TIME,
33 INCREMENT,
34 DECREMENT,
35 TIME_OUT // TODO find a way to do "TIME_OUT"
36};
37
43{
44 IS_WAITING, // nothing to do
45 HAS_FOCUS, // the widget or object manager is pointing to this model
46 IS_ACTIVE // the user has selected (clicked) on this model. CtrolEvent are then passed to this model in order to be processed.
47};
48
55{
56 size_t width{128};
57 size_t height{8};
58 bool with_border{true};
59 bool with_label{true};
60 uint8_t anchor_x{0};
61 uint8_t anchor_y{0};
62 const unsigned char *font{nullptr};
63};
64
65class UIController;
66
72class UIDisplayDevice : public Framebuffer
73{
74private:
75public:
84 UIDisplayDevice(size_t width, size_t height, FramebufferFormat format = FramebufferFormat::MONO_VLSB, StructFramebufferText txt_cnf = {.font = font_8x8});
89 virtual ~UIDisplayDevice();
95 virtual void show() = 0;
104 virtual void show(Framebuffer *frame, uint8_t anchor_x, uint8_t anchor_y) = 0;
105};
106
112{
113private:
118 bool change_flag{true};
123 ControlledObjectStatus status{ControlledObjectStatus::IS_WAITING};
128 UIController *current_controller{nullptr};
129
130protected:
131public:
136 UIModelObject(/* args */);
148 bool has_changed();
153 void set_change_flag();
158 void clear_change_flag();
164 void update_status(ControlledObjectStatus _new_status);
170 void update_current_controller(UIController *_new_controller);
182 virtual void process_control_event(ControlEvent _event) = 0;
183};
184
190{
191private:
192protected:
197 int value;
202 int max_value;
207 int min_value;
212 int increment;
217 bool is_wrappable;
218
219public:
228 UIControlledIncrementalValue(int _min_value = 0, int _max_value = 10, bool _is_wrapable = false, int increment = 1);
238 virtual void increment_value();
243 virtual void decrement_value();
249 void set_clipped_value(int _new_value);
255 int get_value();
261 int get_min_value();
267 int get_max_value();
268};
269
275{
276protected:
281 std::vector<UIModelObject *> managed_models;
286 UIModelObject *current_active_model;
291 void make_managed_object_active();
296 void make_manager_active();
301 virtual void increment_focus();
306 virtual void decrement_focus();
307
308public:
313 UIObjectManager(/* args */);
324 void add_managed_model(UIModelObject *_new_model);
325};
326
332{
333protected:
338 UIModelObject *current_controlled_object{nullptr};
339
340public:
345 UIController(/* args */);
356 void update_current_controlled_object(UIModelObject *_new_controlled_object);
357};
358
363class UIWidget : public Framebuffer
364{
365private:
370 UIDisplayDevice *display_screen{nullptr};
375 UIModelObject * displayed_model{nullptr};
380 bool widget_with_border{true};
385 uint8_t widget_anchor_x;
390 uint8_t widget_anchor_y;
396protected:
401 std::vector<UIWidget *> widgets;
406 size_t widget_width{128};
411 size_t widget_height{8};
416 uint8_t widget_start_x;
421 uint8_t widget_start_y;
426 uint8_t widget_border_width;
432 virtual void set_displayed_model(UIModelObject *_new_displayed_model);
438 void set_display_screen(UIDisplayDevice *_new_display_device);
443 void draw_border();
448 virtual void draw() = 0;
449
450public:
457 static FramebufferColor blinking_us(uint32_t _blink_period);
471 UIWidget(UIDisplayDevice *_display_screen, size_t _frame_width, size_t _frame_height,
472 uint8_t _widget_anchor_x, uint8_t _widget_anchor_y, bool _widget_with_border, uint8_t _widget_border_width = 1,
473 FramebufferFormat _framebuffer_format = FramebufferFormat::MONO_VLSB, StructFramebufferText _framebuffer_txt_cnf = {.font = font_8x8});
478 ~UIWidget();
484 void add_widget(UIWidget *_sub_widget);
489 virtual void refresh();
490};
491
492#endif // UI_CORE_H
~UIControlledIncrementalValue()
Destroy the UIControlledIncrementalValue object.
Definition ui_core.cpp:68
int get_max_value()
Get the max value object.
Definition ui_core.cpp:110
UIControlledIncrementalValue(int _min_value=0, int _max_value=10, bool _is_wrapable=false, int increment=1)
Construct a new UIControlledIncrementalValue object.
Definition ui_core.cpp:58
int get_min_value()
Get the min value object.
Definition ui_core.cpp:105
void set_clipped_value(int _new_value)
Set the clipped value object.
Definition ui_core.cpp:92
int get_value()
Get the value object.
Definition ui_core.cpp:100
void update_current_controlled_object(UIModelObject *_new_controlled_object)
Definition ui_core.cpp:181
~UIController()
Destroy the UIController object.
Definition ui_core.cpp:177
This is the abstract class to handle all generic behavior of physical display devices (e....
Definition ui_core.h:73
UIDisplayDevice(size_t width, size_t height, FramebufferFormat format=FramebufferFormat::MONO_VLSB, StructFramebufferText txt_cnf={.font=font_8x8})
Construct a new UIDisplayDevice object.
Definition ui_core.cpp:3
virtual void show(Framebuffer *frame, uint8_t anchor_x, uint8_t anchor_y)=0
This is an pure virtual member function that all final derived class must implement....
virtual ~UIDisplayDevice()
Destroy the UIDisplayDevice object.
Definition ui_core.cpp:8
virtual void show()=0
This is an pure virtual member function that all final derived class must implement....
void update_status(ControlledObjectStatus _new_status)
Definition ui_core.cpp:39
~UIModelObject()
Destroy the UIModelObject object.
Definition ui_core.cpp:16
void set_change_flag()
Set the change flag object.
Definition ui_core.cpp:53
virtual void process_control_event(ControlEvent _event)=0
ControlledObjectStatus get_status()
Get the status object.
Definition ui_core.cpp:48
void update_current_controller(UIController *_new_controller)
Definition ui_core.cpp:30
bool has_changed()
Definition ui_core.cpp:20
~UIObjectManager()
Destroy the UIObjectManager object.
Definition ui_core.cpp:122
void add_managed_model(UIModelObject *_new_model)
Definition ui_core.cpp:126
virtual void set_displayed_model(UIModelObject *_new_displayed_model)
Set the displayed model object.
Definition ui_core.cpp:220
void add_widget(UIWidget *_sub_widget)
Definition ui_core.cpp:230
~UIWidget()
Destroy the UIWidget object.
Definition ui_core.cpp:216
static FramebufferColor blinking_us(uint32_t _blink_period)
Definition ui_core.cpp:195
virtual void refresh()
WARNING : this function can be redefined. When several widget display one Model, only le last one mus...
Definition ui_core.cpp:235
void set_display_screen(UIDisplayDevice *_new_display_device)
Set the display screen object.
Definition ui_core.cpp:225
UIWidget(UIDisplayDevice *_display_screen, size_t _frame_width, size_t _frame_height, uint8_t _widget_anchor_x, uint8_t _widget_anchor_y, bool _widget_with_border, uint8_t _widget_border_width=1, FramebufferFormat _framebuffer_format=FramebufferFormat::MONO_VLSB, StructFramebufferText _framebuffer_txt_cnf={.font=font_8x8})
Construct a new UIWidget object.
Definition ui_core.cpp:200
Can be useful for keep memory of widget configuration and share it. The structure reflects the memebe...
Definition ui_core.h:55
ControlledObjectStatus
The list of status that a model can have.
Definition ui_core.h:43
ControlEvent
The list of predefined event that a Controller can send to the controlled object, leaving it the resp...
Definition ui_core.h:26