This commit is contained in:
Thomas Peterson 2026-01-24 19:22:12 +01:00
parent df29f89977
commit ed03347331
3 changed files with 12 additions and 12 deletions

View File

@ -381,10 +381,10 @@ void WidgetManager::showScreen(uint8_t screenId) {
} }
void WidgetManager::handleButtonAction(const WidgetConfig& cfg, lv_obj_t* target) { void WidgetManager::handleButtonAction(const WidgetConfig& cfg, lv_obj_t* target) {
if (cfg.type != WidgetType::BUTTON) return; ESP_LOGI(TAG, "handleButtonAction: button=%d action=%d targetScreen=%d type=%d",
cfg.id, static_cast<int>(cfg.action), cfg.targetScreen, static_cast<int>(cfg.type));
ESP_LOGI(TAG, "handleButtonAction: button=%d action=%d targetScreen=%d", if (cfg.type != WidgetType::BUTTON) return;
cfg.id, static_cast<int>(cfg.action), cfg.targetScreen);
onUserActivity(); onUserActivity();

View File

@ -4,28 +4,27 @@
static const char* TAG = "ButtonWidget"; static const char* TAG = "ButtonWidget";
// Free function instead of static member
static void button_event_cb(lv_event_t* e) {
ESP_LOGI(TAG, "button_event_cb called");
}
ButtonWidget::ButtonWidget(const WidgetConfig& config) ButtonWidget::ButtonWidget(const WidgetConfig& config)
: Widget(config) : Widget(config)
, label_(nullptr) , label_(nullptr)
{ {
} }
ButtonWidget::~ButtonWidget() { ButtonWidget::~ButtonWidget() {
// Remove event callback BEFORE the base class destructor deletes the object // Remove event callback BEFORE the base class destructor deletes the object
if (obj_) { if (obj_) {
lv_obj_remove_event_cb(obj_, button_event_cb); lv_obj_remove_event_cb(obj_, clickCallback);
} }
label_ = nullptr; label_ = nullptr;
} }
void ButtonWidget::clickCallback(lv_event_t* e) { void ButtonWidget::clickCallback(lv_event_t* e) {
// Not used currently ESP_LOGI(TAG, "clickCallback called");
(void)e; ButtonWidget* widget = static_cast<ButtonWidget*>(lv_event_get_user_data(e));
if (!widget) return;
lv_obj_t* target = static_cast<lv_obj_t*>(lv_event_get_target(e));
WidgetManager::instance().handleButtonAction(widget->getConfig(), target);
} }
lv_obj_t* ButtonWidget::create(lv_obj_t* parent) { lv_obj_t* ButtonWidget::create(lv_obj_t* parent) {
@ -35,7 +34,7 @@ lv_obj_t* ButtonWidget::create(lv_obj_t* parent) {
config_.height > 0 ? config_.height : 50); config_.height > 0 ? config_.height : 50);
// Test: free function callback // Test: free function callback
lv_obj_add_event_cb(obj_, button_event_cb, LV_EVENT_CLICKED, NULL); lv_obj_add_event_cb(obj_, clickCallback, LV_EVENT_CLICKED, this);
label_ = lv_label_create(obj_); label_ = lv_label_create(obj_);
lv_label_set_text(label_, config_.text); lv_label_set_text(label_, config_.text);

View File

@ -61,6 +61,7 @@ void Widget::applyCommonStyle() {
} }
void Widget::applyShadowStyle() { void Widget::applyShadowStyle() {
return;
if (obj_ == nullptr || !config_.shadow.enabled) return; if (obj_ == nullptr || !config_.shadow.enabled) return;
lv_obj_set_style_shadow_color(obj_, lv_color_make( lv_obj_set_style_shadow_color(obj_, lv_color_make(