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:
GW_MC
2026-02-01 13:03:56 +08:00
parent 237a3a96c5
commit 06e81301b2
22 changed files with 880 additions and 2198 deletions

View File

@@ -0,0 +1,70 @@
#pragma once
#include "esp_err.h"
#include "lvgl.h"
#include "ui/events.h"
/**
* @brief Interaction Handler - manages user interactions
*
* This class is responsible for handling user inputs
* such as touch events, button presses, and gestures.
* It routes these interactions to the appropriate UI components
* or apps based on the current context. And it also handles the respective UI widgets.
*
* For example, it manages:
* Textarea focus and display of the on-screen keyboard
*/
class InteractionHandler {
public:
InteractionHandler() = default;
~InteractionHandler();
/**
* @brief Initialize the Interaction Handler
*
* Sets up necessary event listeners and state.
*
* @return ESP_OK on success, error code otherwise
*/
esp_err_t init(lv_obj_t* app_container);
/**
* @brief Deinitialize the Interaction Handler
*
* Cleans up resources and event listeners.
*
* @return ESP_OK on success, error code otherwise
*/
esp_err_t deinit(void);
/**
* @brief Add keyboard support to a textarea widget
*
* @param text_area Pointer to the textarea lvgl object
* @return esp_err_t ESP_OK on success, error code otherwise
*/
esp_err_t register_text_area_keyboard_support(lv_obj_t* text_area);
private:
// Event handler for keyboard show/hide events
// It should be registered with event callbacks of the keyboard object
void on_keyboard_event_(lv_event_t* e);
esp_err_t show_keyboard_for_textarea_(lv_obj_t* textarea);
esp_err_t hide_keyboard_(void);
// Pointers to key UI objects, owned by UIHandler
lv_obj_t* app_container_ = nullptr;
// owned keyboard object
lv_obj_t* keyboard_ = nullptr;
// Currently focused textarea, reference only
lv_obj_t* focused_textarea_ = nullptr;
InteractionHandler(const InteractionHandler&) = delete;
InteractionHandler& operator=(const InteractionHandler&) = delete;
};