prepared using the roller via lvgl
This commit is contained in:
committed by
Raphael Coeffic
parent
0284a520fa
commit
a363e89fba
@@ -21,6 +21,14 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
|
||||||
|
ChoiceBase::ChoiceBase(FormGroup * parent, const rect_t & rect, ChoiceType type, WindowFlags windowFlags):
|
||||||
|
FormField(parent, rect, windowFlags),
|
||||||
|
type(type)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Choice::Choice(FormGroup * parent, const rect_t & rect, int vmin, int vmax,
|
Choice::Choice(FormGroup * parent, const rect_t & rect, int vmin, int vmax,
|
||||||
std::function<int()> getValue, std::function<void(int)> setValue, WindowFlags windowFlags) :
|
std::function<int()> getValue, std::function<void(int)> setValue, WindowFlags windowFlags) :
|
||||||
ChoiceBase(parent, rect, CHOICE_TYPE_DROPOWN, windowFlags),
|
ChoiceBase(parent, rect, CHOICE_TYPE_DROPOWN, windowFlags),
|
||||||
|
|||||||
+1
-5
@@ -32,11 +32,7 @@ enum ChoiceType {
|
|||||||
class ChoiceBase : public FormField
|
class ChoiceBase : public FormField
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ChoiceBase(FormGroup * parent, const rect_t & rect, ChoiceType type = CHOICE_TYPE_DROPOWN, WindowFlags windowFlags = 0):
|
ChoiceBase(FormGroup * parent, const rect_t & rect, ChoiceType type = CHOICE_TYPE_DROPOWN, WindowFlags windowFlags = 0);
|
||||||
FormField(parent, rect, windowFlags),
|
|
||||||
type(type)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline ChoiceType getType() const
|
inline ChoiceType getType() const
|
||||||
{
|
{
|
||||||
|
|||||||
+7
-1
@@ -64,11 +64,17 @@ void FormField::onEvent(event_t event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
extern lv_group_t* inputGroup;
|
||||||
void FormField::setFocus(uint8_t flag, Window * from)
|
void FormField::setFocus(uint8_t flag, Window * from)
|
||||||
{
|
{
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
Window::setFocus(flag, from);
|
Window::setFocus(flag, from);
|
||||||
|
if(lvobj != nullptr)
|
||||||
|
{
|
||||||
|
lv_group_focus_freeze(inputGroup, false);
|
||||||
|
lv_group_focus_obj(lvobj);
|
||||||
|
lv_group_focus_freeze(inputGroup, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (flag == SET_FOCUS_BACKWARD) {
|
if (flag == SET_FOCUS_BACKWARD) {
|
||||||
|
|||||||
+8
@@ -77,6 +77,14 @@ class FormField: public Window
|
|||||||
virtual void setEditMode(bool newEditMode)
|
virtual void setEditMode(bool newEditMode)
|
||||||
{
|
{
|
||||||
editMode = newEditMode;
|
editMode = newEditMode;
|
||||||
|
|
||||||
|
if(lvobj != nullptr)
|
||||||
|
{
|
||||||
|
lv_group_t* grp = (lv_group_t*)lv_obj_get_group(lvobj);
|
||||||
|
if(grp != nullptr)
|
||||||
|
lv_group_set_editing(grp, editMode);
|
||||||
|
}
|
||||||
|
|
||||||
if (editMode && lvobj != nullptr) {
|
if (editMode && lvobj != nullptr) {
|
||||||
lv_obj_add_state(lvobj, LV_STATE_EDITED | LV_STATE_FOCUSED);
|
lv_obj_add_state(lvobj, LV_STATE_EDITED | LV_STATE_FOCUSED);
|
||||||
} else if (lvobj != nullptr) {
|
} else if (lvobj != nullptr) {
|
||||||
|
|||||||
@@ -28,6 +28,30 @@ static LvglWidgetFactory numberEditFactory = { lv_textarea_create, nullptr };
|
|||||||
static lv_style_t style_main;
|
static lv_style_t style_main;
|
||||||
static lv_style_t style_edit;
|
static lv_style_t style_edit;
|
||||||
|
|
||||||
|
extern "C" void lvglEventCb(lv_event_t* event)
|
||||||
|
{
|
||||||
|
if(!event)
|
||||||
|
return;
|
||||||
|
uint32_t key = lv_event_get_key(event);
|
||||||
|
NumberEdit* numEdit = (NumberEdit*)event->user_data;
|
||||||
|
if(!numEdit)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lv_group_t* grp = (lv_group_t*)lv_obj_get_group(numEdit->getLvObj());
|
||||||
|
if(grp && lv_group_get_focused(grp) == numEdit->getLvObj())
|
||||||
|
numEdit->setEditMode(lv_group_get_editing(grp));
|
||||||
|
switch(key)
|
||||||
|
{
|
||||||
|
case LV_KEY_LEFT:
|
||||||
|
// numEdit->onEvent(EVT_ROTARY_LEFT);
|
||||||
|
break;
|
||||||
|
case LV_KEY_RIGHT:
|
||||||
|
// numEdit->onEvent(EVT_ROTARY_RIGHT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
event->code = LV_EVENT_REFRESH;
|
||||||
|
}
|
||||||
|
|
||||||
NumberEdit::NumberEdit(Window * parent, const rect_t & rect, int vmin, int vmax, std::function<int()> getValue, std::function<void(int)> setValue, WindowFlags windowFlags, LcdFlags textFlags):
|
NumberEdit::NumberEdit(Window * parent, const rect_t & rect, int vmin, int vmax, std::function<int()> getValue, std::function<void(int)> setValue, WindowFlags windowFlags, LcdFlags textFlags):
|
||||||
BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue), std::move(setValue), windowFlags, textFlags, &numberEditFactory)
|
BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue), std::move(setValue), windowFlags, textFlags, &numberEditFactory)
|
||||||
{
|
{
|
||||||
@@ -72,6 +96,8 @@ NumberEdit::NumberEdit(Window * parent, const rect_t & rect, int vmin, int vmax,
|
|||||||
auto label = lv_textarea_get_label(lvobj);
|
auto label = lv_textarea_get_label(lvobj);
|
||||||
lv_obj_set_style_pad_left(label, FIELD_PADDING_LEFT, LV_PART_MAIN);
|
lv_obj_set_style_pad_left(label, FIELD_PADDING_LEFT, LV_PART_MAIN);
|
||||||
lv_obj_set_style_pad_top(label, FIELD_PADDING_TOP, LV_PART_MAIN);
|
lv_obj_set_style_pad_top(label, FIELD_PADDING_TOP, LV_PART_MAIN);
|
||||||
|
|
||||||
|
lv_obj_add_event_cb(lvobj, lvglEventCb, LV_EVENT_ALL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NumberEdit::onEvent(event_t event)
|
void NumberEdit::onEvent(event_t event)
|
||||||
|
|||||||
+9
-1
@@ -37,6 +37,7 @@ static void window_event_cb(lv_event_t * e)
|
|||||||
|
|
||||||
Window* window = (Window *)lv_obj_get_user_data(target);
|
Window* window = (Window *)lv_obj_get_user_data(target);
|
||||||
if (!window) return;
|
if (!window) return;
|
||||||
|
if(window->deleted()) return;
|
||||||
|
|
||||||
if (code == LV_EVENT_GET_SELF_SIZE) {
|
if (code == LV_EVENT_GET_SELF_SIZE) {
|
||||||
lv_point_t *p = (lv_point_t *)lv_event_get_param(e);
|
lv_point_t *p = (lv_point_t *)lv_event_get_param(e);
|
||||||
@@ -232,11 +233,16 @@ void Window::clear()
|
|||||||
|
|
||||||
void Window::clearLvgl()
|
void Window::clearLvgl()
|
||||||
{
|
{
|
||||||
|
if(lvobj == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
for (auto window: children)
|
for (auto window: children)
|
||||||
{
|
{
|
||||||
if(lvobj != nullptr && window->lvobj != nullptr && window->lvobj->parent == lvobj)
|
if(window->lvobj != nullptr && window->lvobj->parent == lvobj)
|
||||||
window->clearLvgl();
|
window->clearLvgl();
|
||||||
}
|
}
|
||||||
|
// lv_obj_set_user_data(lvobj, nullptr);
|
||||||
|
|
||||||
lvobj = nullptr;
|
lvobj = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,6 +515,7 @@ coord_t Window::getSnapStep(coord_t relativeScrollPosition, coord_t pageSize)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void lvglPushEncoderEvent(event_t evt);
|
||||||
void Window::checkEvents()
|
void Window::checkEvents()
|
||||||
{
|
{
|
||||||
auto copy = children;
|
auto copy = children;
|
||||||
@@ -520,6 +527,7 @@ void Window::checkEvents()
|
|||||||
|
|
||||||
if (this == Window::focusWindow) {
|
if (this == Window::focusWindow) {
|
||||||
event_t event = getWindowEvent();
|
event_t event = getWindowEvent();
|
||||||
|
lvglPushEncoderEvent(event);
|
||||||
if (event) {
|
if (event) {
|
||||||
this->onEvent(event);
|
this->onEvent(event);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user