make button lvgl-Event aware
This commit is contained in:
committed by
Raphael Coeffic
parent
f99c16c7aa
commit
9d45303531
+35
@@ -22,6 +22,26 @@
|
|||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
|
||||||
|
static void lvglEvent(lv_event_t* e)
|
||||||
|
{
|
||||||
|
Button* btn = (Button*)lv_event_get_user_data(e);
|
||||||
|
if(btn->deleted())
|
||||||
|
return;
|
||||||
|
|
||||||
|
btn->onEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Button::Button(FormGroup* parent, const rect_t& rect,
|
||||||
|
std::function<uint8_t(void)> pressHandler,
|
||||||
|
WindowFlags windowFlag, LcdFlags textFlags,
|
||||||
|
LvglCreate objConstruct) :
|
||||||
|
FormField(parent, rect, windowFlag, textFlags, objConstruct),
|
||||||
|
pressHandler(std::move(pressHandler))
|
||||||
|
{
|
||||||
|
lv_obj_set_style_bg_opa(lvobj, LV_OPA_TRANSP, LV_PART_MAIN);
|
||||||
|
lv_obj_add_event_cb(lvobj, lvglEvent, LV_EVENT_CLICKED, this);
|
||||||
|
}
|
||||||
|
|
||||||
void Button::onPress()
|
void Button::onPress()
|
||||||
{
|
{
|
||||||
bool check = (pressHandler && pressHandler());
|
bool check = (pressHandler && pressHandler());
|
||||||
@@ -51,6 +71,21 @@ void Button::onEvent(event_t event)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void Button::onEvent(lv_event_t* event)
|
||||||
|
{
|
||||||
|
lv_event_code_t code = lv_event_get_code(event);
|
||||||
|
|
||||||
|
TRACE_WINDOWS("%s received lvgl event code 0x%X", getWindowDebugString("Button").c_str(), code);
|
||||||
|
|
||||||
|
if (enabled && code == LV_EVENT_CLICKED) {
|
||||||
|
onKeyPress();
|
||||||
|
onPress();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// FormField::onEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
#if defined(HARDWARE_TOUCH)
|
||||||
bool Button::onTouchStart(coord_t x, coord_t y)
|
bool Button::onTouchStart(coord_t x, coord_t y)
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-6
@@ -31,12 +31,7 @@ class Button: public FormField
|
|||||||
Button(FormGroup* parent, const rect_t& rect,
|
Button(FormGroup* parent, const rect_t& rect,
|
||||||
std::function<uint8_t(void)> pressHandler = nullptr,
|
std::function<uint8_t(void)> pressHandler = nullptr,
|
||||||
WindowFlags windowFlags = 0, LcdFlags textFlags = 0,
|
WindowFlags windowFlags = 0, LcdFlags textFlags = 0,
|
||||||
LvglCreate objConstruct = nullptr) :
|
LvglCreate objConstruct = nullptr);
|
||||||
FormField(parent, rect, windowFlags, textFlags, objConstruct),
|
|
||||||
pressHandler(std::move(pressHandler))
|
|
||||||
{
|
|
||||||
lv_obj_set_style_bg_opa(lvobj, LV_OPA_TRANSP, LV_PART_MAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const override
|
std::string getName() const override
|
||||||
@@ -74,6 +69,7 @@ class Button: public FormField
|
|||||||
#if defined(HARDWARE_KEYS)
|
#if defined(HARDWARE_KEYS)
|
||||||
void onEvent(event_t event) override;
|
void onEvent(event_t event) override;
|
||||||
#endif
|
#endif
|
||||||
|
void onEvent(lv_event_t* e);// override;
|
||||||
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
#if defined(HARDWARE_TOUCH)
|
||||||
bool onTouchStart(coord_t x, coord_t y) override;
|
bool onTouchStart(coord_t x, coord_t y) override;
|
||||||
|
|||||||
+1
-1
@@ -290,7 +290,7 @@ void Window::setFocus(uint8_t flag, Window * from)
|
|||||||
|
|
||||||
if (focusWindow != this) {
|
if (focusWindow != this) {
|
||||||
// synchronize lvgl focused state with libopenui
|
// synchronize lvgl focused state with libopenui
|
||||||
if (!lv_obj_has_state(lvobj, LV_STATE_FOCUSED)) {
|
if (lvobj != nullptr && !lv_obj_has_state(lvobj, LV_STATE_FOCUSED)) {
|
||||||
lv_obj_add_state(lvobj, LV_STATE_FOCUSED);
|
lv_obj_add_state(lvobj, LV_STATE_FOCUSED);
|
||||||
if (focusWindow != nullptr) {
|
if (focusWindow != nullptr) {
|
||||||
lv_obj_clear_state(focusWindow->lvobj, LV_STATE_FOCUSED | LV_STATE_EDITED);
|
lv_obj_clear_state(focusWindow->lvobj, LV_STATE_FOCUSED | LV_STATE_EDITED);
|
||||||
|
|||||||
Reference in New Issue
Block a user