139 lines
3.3 KiB
C++
139 lines
3.3 KiB
C++
#pragma once
|
|
|
|
#include "lvgl.h"
|
|
#include "esp_err.h"
|
|
#include <string>
|
|
|
|
// Forward declaration
|
|
class UIHandler;
|
|
|
|
/**
|
|
* @brief Root Layout Manager - manages the main screen layout
|
|
*
|
|
* The RootLayout class is responsible for:
|
|
* - Creating and managing the main screen structure (header, app container, nav bar)
|
|
* - Rendering app icons from the AppRegistry
|
|
* - Managing the back button
|
|
* - Updating header content
|
|
*/
|
|
class RootLayout {
|
|
public:
|
|
/**
|
|
* @brief Construct a new RootLayout object
|
|
*
|
|
* @param ui_handler Pointer to the UIHandler (for callbacks)
|
|
*/
|
|
RootLayout(UIHandler* ui_handler);
|
|
|
|
/**
|
|
* @brief Initialize the layout
|
|
*
|
|
* Creates the main screen with header, app container, and navigation bar.
|
|
*
|
|
* @param parent Parent LVGL object to attach layout to
|
|
* @return ESP_OK on success, error code otherwise
|
|
*/
|
|
esp_err_t init(lv_obj_t* parent);
|
|
|
|
/**
|
|
* @brief Deinitialize the layout
|
|
*
|
|
* Cleans up all layout widgets.
|
|
*
|
|
* @return ESP_OK on success, error code otherwise
|
|
*/
|
|
esp_err_t deinit(void);
|
|
|
|
/**
|
|
* @brief Render app icons in the navigation bar
|
|
*
|
|
* Queries the AppRegistry for all registered apps and
|
|
* renders their icons in the navigation bar. Also creates
|
|
* the back button.
|
|
*
|
|
* @return ESP_OK on success, error code otherwise
|
|
*/
|
|
esp_err_t render_app_icons(void);
|
|
|
|
/**
|
|
* @brief Update header with app name
|
|
*
|
|
* @param app_name Name to display in header (nullptr for default)
|
|
*/
|
|
void update_header(std::string app_name);
|
|
|
|
/**
|
|
* @brief Show the back button
|
|
*/
|
|
void show_back_button(void);
|
|
|
|
/**
|
|
* @brief Hide the back button
|
|
*/
|
|
void hide_back_button(void);
|
|
|
|
/**
|
|
* @brief Get the header object
|
|
*
|
|
* @return lv_obj_t* pointer to the header container
|
|
*/
|
|
lv_obj_t* get_header(void) const {
|
|
return _header;
|
|
}
|
|
|
|
/**
|
|
* @brief Get the app container (where apps render)
|
|
*
|
|
* @return lv_obj_t* pointer to the app container
|
|
*/
|
|
lv_obj_t* get_app_container(void) const {
|
|
return _app_container;
|
|
}
|
|
|
|
/**
|
|
* @brief Get the navigation bar object
|
|
*
|
|
* @return lv_obj_t* pointer to the navigation bar container
|
|
*/
|
|
lv_obj_t* get_nav_bar(void) const {
|
|
return _nav_bar;
|
|
}
|
|
|
|
private:
|
|
UIHandler* _ui_handler = nullptr; ///< Reference to UIHandler for callbacks
|
|
lv_obj_t* _header = nullptr; ///< Header area (top)
|
|
lv_obj_t* _header_label = nullptr; ///< Header text label
|
|
lv_obj_t* _app_container = nullptr; ///< Container for app widgets (middle)
|
|
lv_obj_t* _nav_bar = nullptr; ///< Navigation bar (bottom)
|
|
lv_obj_t* _back_button = nullptr; ///< Back button in navigation bar
|
|
|
|
/**
|
|
* @brief Create the layout structure
|
|
*
|
|
* Sets up header, app container, and navigation bar with
|
|
* appropriate dimensions and positioning.
|
|
*
|
|
* @param parent Parent object to attach layout to
|
|
* @return ESP_OK on success, error code otherwise
|
|
*/
|
|
esp_err_t create_layout(lv_obj_t* parent);
|
|
|
|
/**
|
|
* @brief Handle app icon click event
|
|
*
|
|
* Static callback for LVGL event handling.
|
|
*
|
|
* @param event LVGL event object
|
|
*/
|
|
static void on_app_icon_clicked(lv_event_t* event);
|
|
|
|
/**
|
|
* @brief Handle back button click event
|
|
*
|
|
* Static callback for LVGL event handling.
|
|
*
|
|
* @param event LVGL event object
|
|
*/
|
|
static void on_back_button_clicked(lv_event_t* event);
|
|
};
|