#pragma once #include "lvgl.h" #include "esp_err.h" #include #include // Forward declaration class InteractionHandler; /** * @brief Base class for all UI applications * * All UI applications (apps) must inherit from this class. * Each app is responsible for managing its own widgets within * the provided LVGL container. The UIHandler will manage the * lifecycle of apps and event routing. */ class UIApp { public: virtual ~UIApp() = default; /** * @brief Initialize the app with the given container * * The app should create all its widgets as children of the * provided container. The container is already positioned * between the header and navigation bar. * * @param container LVGL container object for this app * @param interaction_handler Pointer to interaction handler for keyboard support * @return ESP_OK on success, error code otherwise */ virtual esp_err_t init(lv_obj_t* container, InteractionHandler* interaction_handler) = 0; /** * @brief Deinitialize and clean up app resources * * The app should delete all widgets and release any resources. * The container itself will be handled by UIHandler. * * @return ESP_OK on success, error code otherwise */ virtual esp_err_t deinit(void) = 0; /** * @brief Get the display name of this app * * Used for logging and potentially showing in navigation. * * @return std::string app name */ virtual std::string get_name(void) const = 0; /** * @brief Handle back button press * * Called when the back button is pressed. * The app can choose to handle it (e.g., close a dialog) * or return false to let UIHandler handle it (e.g., return to main screen). * * @return true if the event was handled, false otherwise */ virtual bool on_back_button_pressed(void) { return false; // default: not handled } protected: lv_obj_t* container_ = nullptr; ///< LVGL container provided by UIHandler }; class AppDescriptor { public: virtual ~AppDescriptor() = default; virtual void draw_icon(lv_obj_t* parent) = 0; std::string get_name() const { return name_; } UIApp* get_app_instance() const { return app_instance_.get(); } protected: AppDescriptor(std::string name, std::unique_ptr app_instance) : name_(name), app_instance_(std::move(app_instance)) { } std::string name_; std::unique_ptr app_instance_; };