diff --git a/main/WidgetManager.cpp b/main/WidgetManager.cpp index 4ce50a8..b18cb45 100644 --- a/main/WidgetManager.cpp +++ b/main/WidgetManager.cpp @@ -381,10 +381,10 @@ void WidgetManager::showScreen(uint8_t screenId) { } 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(cfg.action), cfg.targetScreen, static_cast(cfg.type)); - ESP_LOGI(TAG, "handleButtonAction: button=%d action=%d targetScreen=%d", - cfg.id, static_cast(cfg.action), cfg.targetScreen); + if (cfg.type != WidgetType::BUTTON) return; onUserActivity(); diff --git a/main/widgets/ButtonWidget.cpp b/main/widgets/ButtonWidget.cpp index a63ab4a..727e294 100644 --- a/main/widgets/ButtonWidget.cpp +++ b/main/widgets/ButtonWidget.cpp @@ -4,28 +4,27 @@ 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) : Widget(config) , label_(nullptr) { + } ButtonWidget::~ButtonWidget() { // Remove event callback BEFORE the base class destructor deletes the object if (obj_) { - lv_obj_remove_event_cb(obj_, button_event_cb); + lv_obj_remove_event_cb(obj_, clickCallback); } label_ = nullptr; } void ButtonWidget::clickCallback(lv_event_t* e) { - // Not used currently - (void)e; + ESP_LOGI(TAG, "clickCallback called"); + ButtonWidget* widget = static_cast(lv_event_get_user_data(e)); + if (!widget) return; + lv_obj_t* target = static_cast(lv_event_get_target(e)); + WidgetManager::instance().handleButtonAction(widget->getConfig(), target); } 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); // 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_); lv_label_set_text(label_, config_.text); diff --git a/main/widgets/Widget.cpp b/main/widgets/Widget.cpp index 34c53a8..85d960e 100644 --- a/main/widgets/Widget.cpp +++ b/main/widgets/Widget.cpp @@ -61,6 +61,7 @@ void Widget::applyCommonStyle() { } void Widget::applyShadowStyle() { + return; if (obj_ == nullptr || !config_.shadow.enabled) return; lv_obj_set_style_shadow_color(obj_, lv_color_make(