- 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.
127 lines
3.2 KiB
C++
127 lines
3.2 KiB
C++
#pragma once
|
|
#include "esp_err.h"
|
|
#include "esp_event.h"
|
|
#include "lvgl.h"
|
|
#include <string>
|
|
|
|
// Forward declaration to avoid circular dependency
|
|
class UIHandler;
|
|
|
|
class RootLayout {
|
|
public:
|
|
RootLayout() = default;
|
|
~RootLayout();
|
|
|
|
/**
|
|
* @brief Initialize the root layout within the given parent object
|
|
*
|
|
* Sets up the header, app container, and navigation bar.
|
|
*
|
|
* @param parent Parent LVGL object to contain the layout
|
|
* @return ESP_OK on success, error code otherwise
|
|
*/
|
|
esp_err_t init(lv_obj_t* parent, UIHandler* ui_handler);
|
|
|
|
/**
|
|
* @brief Deinitialize the root layout
|
|
*
|
|
* Cleans up references to layout components.
|
|
*
|
|
* @return ESP_OK on success, error code otherwise
|
|
*/
|
|
esp_err_t deinit(void);
|
|
|
|
/**
|
|
* @brief Show the back button in the navigation bar
|
|
*/
|
|
void show_back_button(void) const;
|
|
|
|
/**
|
|
* @brief Hide the back button in the navigation bar
|
|
*/
|
|
void hide_back_button(void) const;
|
|
|
|
/**
|
|
* @brief Show the home button in the navigation bar
|
|
*/
|
|
void show_home_button(void) const;
|
|
|
|
/**
|
|
* @brief Hide the home button in the navigation bar
|
|
*/
|
|
void hide_home_button(void) const;
|
|
|
|
/**
|
|
* @brief Show navigation bar
|
|
*
|
|
*/
|
|
void show_nav_bar(void) const;
|
|
|
|
/**
|
|
* @brief Hide navigation bar
|
|
*
|
|
*/
|
|
void hide_nav_bar(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @brief Register a callback for back button presses
|
|
*
|
|
*
|
|
* @param callback
|
|
* @param user_data
|
|
* @param out_event_dsc
|
|
* @return ESP_OK on success, error code otherwise
|
|
*/
|
|
esp_err_t register_back_button_callback(lv_event_cb_t callback, void* user_data, lv_event_dsc_t** out_event_dsc) const;
|
|
|
|
/**
|
|
* @brief Register a callback for home button presses
|
|
*
|
|
* @param callback
|
|
* @param user_data
|
|
* @param out_event_dsc
|
|
* @return ESP_OK on success, error code otherwise
|
|
*/
|
|
esp_err_t register_home_button_callback(lv_event_cb_t callback, void* user_data, lv_event_dsc_t** out_event_dsc) const;
|
|
|
|
/**
|
|
* @brief Update the header title text
|
|
*
|
|
* @param title New title text
|
|
* @return ESP_OK on success, error code otherwise
|
|
*/
|
|
esp_err_t update_header(const std::string& title) const;
|
|
|
|
/**
|
|
* @brief Get the app container object, which holds the active app's UI
|
|
* Caller can add/remove app UI elements to/from this container.
|
|
* Caller must not delete this object directly or edit its layout properties.
|
|
*
|
|
* @return lv_obj_t*
|
|
*/
|
|
lv_obj_t* get_app_container() const {
|
|
return app_container_;
|
|
}
|
|
|
|
private:
|
|
|
|
// Event handler for keyboard show/hide events
|
|
void on_keyboard_event_(void* handler_args, esp_event_base_t base, int32_t id, void* event_data);
|
|
|
|
// layout objects
|
|
// header
|
|
lv_obj_t* header_obj_ = nullptr; ///< Header area object
|
|
lv_obj_t* header_label_ = nullptr; ///< Header title label
|
|
// app container
|
|
lv_obj_t* app_container_ = nullptr; ///< App container object
|
|
// navigation bar
|
|
lv_obj_t* nav_bar_obj_ = nullptr; ///< Navigation bar object
|
|
lv_obj_t* back_button_ = nullptr; ///< Back button object
|
|
lv_obj_t* home_button_ = nullptr; ///< Home button object
|
|
|
|
esp_event_handler_instance_t keyboard_event_handler_instance_ = nullptr; ///< Event handler instance for keyboard events
|
|
};
|