Refactor RootLayout and UIHandler for improved structure and functionality
- Updated RootLayout to manage layout initialization and deinitialization more effectively. - Removed unnecessary dependencies and streamlined event handling for keyboard events. - Enhanced UIHandler to utilize shared pointers for app descriptors, improving memory management. - Added methods for showing and hiding navigation elements in RootLayout. - Introduced textarea widget with instant response by disabling animations. - Improved error handling and logging throughout the UI components.
This commit is contained in:
87
main/ui/apps/app.h
Normal file
87
main/ui/apps/app.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "esp_err.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @return ESP_OK on success, error code otherwise
|
||||
*/
|
||||
virtual esp_err_t init(lv_obj_t* container) = 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<UIApp> app_instance)
|
||||
: name_(name), app_instance_(std::move(app_instance)) { }
|
||||
|
||||
std::string name_;
|
||||
std::unique_ptr<UIApp> app_instance_;
|
||||
};
|
||||
Reference in New Issue
Block a user