Re implement display
This commit is contained in:
@@ -1,151 +0,0 @@
|
||||
#include "apps/demo_app.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#define TAG "DemoApp"
|
||||
|
||||
esp_err_t DemoApp::init(lv_obj_t* container) {
|
||||
if (!container) {
|
||||
ESP_LOGE(TAG, "Container is null");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
_container = container;
|
||||
ESP_LOGI(TAG, "Initializing demo app...");
|
||||
|
||||
// Header label
|
||||
_label_header = lv_label_create(_container);
|
||||
lv_label_set_text(_label_header, "Counter & Brightness Demo");
|
||||
lv_obj_set_style_text_color(_label_header, lv_color_black(), 0);
|
||||
lv_obj_align(_label_header, LV_ALIGN_TOP_MID, 0, 20);
|
||||
|
||||
// Counter label
|
||||
_label_counter = lv_label_create(_container);
|
||||
lv_label_set_text(_label_counter, "Count: 0");
|
||||
lv_obj_set_style_text_color(_label_counter, lv_color_black(), 0);
|
||||
lv_obj_align(_label_counter, LV_ALIGN_CENTER, 0, -80);
|
||||
|
||||
// Increment button
|
||||
_btn_increment = lv_btn_create(_container);
|
||||
lv_obj_set_size(_btn_increment, 150, 60);
|
||||
lv_obj_align(_btn_increment, LV_ALIGN_CENTER, -100, -20);
|
||||
lv_obj_add_event_cb(_btn_increment, btn_increment_event_cb, LV_EVENT_CLICKED, this);
|
||||
|
||||
lv_obj_t* label_inc = lv_label_create(_btn_increment);
|
||||
lv_label_set_text(label_inc, "+");
|
||||
lv_obj_set_style_text_color(label_inc, lv_color_black(), 0);
|
||||
lv_obj_center(label_inc);
|
||||
|
||||
// Decrement button
|
||||
_btn_decrement = lv_btn_create(_container);
|
||||
lv_obj_set_size(_btn_decrement, 150, 60);
|
||||
lv_obj_align(_btn_decrement, LV_ALIGN_CENTER, 100, -20);
|
||||
lv_obj_add_event_cb(_btn_decrement, btn_decrement_event_cb, LV_EVENT_CLICKED, this);
|
||||
|
||||
lv_obj_t* label_dec = lv_label_create(_btn_decrement);
|
||||
lv_label_set_text(label_dec, "-");
|
||||
lv_obj_set_style_text_color(label_dec, lv_color_black(), 0);
|
||||
lv_obj_center(label_dec);
|
||||
|
||||
// Slider
|
||||
_slider_brightness = lv_slider_create(_container);
|
||||
lv_obj_set_width(_slider_brightness, 400);
|
||||
lv_obj_align(_slider_brightness, LV_ALIGN_CENTER, 0, 80);
|
||||
lv_slider_set_range(_slider_brightness, 0, 100);
|
||||
lv_slider_set_value(_slider_brightness, 50, LV_ANIM_OFF);
|
||||
lv_obj_add_event_cb(_slider_brightness, slider_event_cb, LV_EVENT_VALUE_CHANGED, this);
|
||||
|
||||
// Slider value label
|
||||
_label_slider_value = lv_label_create(_container);
|
||||
lv_label_set_text(_label_slider_value, "Brightness: 50%");
|
||||
lv_obj_set_style_text_color(_label_slider_value, lv_color_black(), 0);
|
||||
lv_obj_align(_label_slider_value, LV_ALIGN_CENTER, 0, 130);
|
||||
|
||||
// Info text at bottom
|
||||
lv_obj_t* label_info = lv_label_create(_container);
|
||||
lv_label_set_text(label_info, "Touch buttons and slider to test");
|
||||
lv_obj_set_style_text_color(label_info, lv_color_black(), 0);
|
||||
lv_obj_align(label_info, LV_ALIGN_BOTTOM_MID, 0, -20);
|
||||
|
||||
ESP_LOGI(TAG, "Demo app initialized successfully");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t DemoApp::deinit(void) {
|
||||
ESP_LOGI(TAG, "Deinitializing demo app");
|
||||
|
||||
// All widgets will be automatically deleted when container is cleaned
|
||||
_label_header = nullptr;
|
||||
_label_counter = nullptr;
|
||||
_btn_increment = nullptr;
|
||||
_btn_decrement = nullptr;
|
||||
_slider_brightness = nullptr;
|
||||
_label_slider_value = nullptr;
|
||||
_counter = 0;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
std::string DemoApp::get_name(void) const {
|
||||
return "Demo";
|
||||
}
|
||||
|
||||
void DemoApp::btn_increment_event_cb(lv_event_t* e) {
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
if (code == LV_EVENT_CLICKED) {
|
||||
DemoApp* app = (DemoApp*)lv_event_get_user_data(e);
|
||||
if (app) {
|
||||
app->_counter++;
|
||||
lv_label_set_text_fmt(app->_label_counter, "Count: %d", app->_counter);
|
||||
ESP_LOGI(TAG, "Increment button clicked, count: %d", app->_counter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DemoApp::btn_decrement_event_cb(lv_event_t* e) {
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
if (code == LV_EVENT_CLICKED) {
|
||||
DemoApp* app = (DemoApp*)lv_event_get_user_data(e);
|
||||
if (app) {
|
||||
app->_counter--;
|
||||
lv_label_set_text_fmt(app->_label_counter, "Count: %d", app->_counter);
|
||||
ESP_LOGI(TAG, "Decrement button clicked, count: %d", app->_counter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DemoApp::slider_event_cb(lv_event_t* e) {
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
if (code == LV_EVENT_VALUE_CHANGED) {
|
||||
DemoApp* app = (DemoApp*)lv_event_get_user_data(e);
|
||||
if (app) {
|
||||
lv_obj_t* slider = (lv_obj_t*)lv_event_get_target(e);
|
||||
int32_t value = lv_slider_get_value(slider);
|
||||
lv_label_set_text_fmt(app->_label_slider_value, "Brightness: %d%%", (int)value);
|
||||
ESP_LOGI(TAG, "Slider value changed: %d", (int)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DemoAppDescriptor implementation
|
||||
DemoApp* DemoAppDescriptor::_app_instance = nullptr;
|
||||
|
||||
DemoAppDescriptor::DemoAppDescriptor()
|
||||
: AppDescriptor("Demo", nullptr) {
|
||||
// Create singleton app instance
|
||||
if (!_app_instance) {
|
||||
_app_instance = new DemoApp();
|
||||
}
|
||||
|
||||
// Register with AppRegistry
|
||||
AppRegistry::instance().register_app(this);
|
||||
ESP_LOGI(TAG, "DemoApp registered with AppRegistry");
|
||||
}
|
||||
|
||||
void DemoAppDescriptor::draw_icon(lv_obj_t* parent) {
|
||||
// Create a simple icon with text and a symbol
|
||||
lv_obj_t* icon_label = lv_label_create(parent);
|
||||
lv_label_set_text(icon_label, LV_SYMBOL_SETTINGS "\nDemo");
|
||||
lv_obj_set_style_text_color(icon_label, lv_color_white(), 0);
|
||||
lv_obj_set_style_text_align(icon_label, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_center(icon_label);
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ui/ui_app.h"
|
||||
#include "ui/app_registry.h"
|
||||
|
||||
/**
|
||||
* @brief Demo application - counter and brightness slider
|
||||
*
|
||||
* Demonstrates interactive UI components with touch input:
|
||||
* - Counter display with increment/decrement buttons
|
||||
* - Brightness slider
|
||||
*/
|
||||
class DemoApp : public UIApp {
|
||||
public:
|
||||
DemoApp() = default;
|
||||
virtual ~DemoApp() = default;
|
||||
|
||||
esp_err_t init(lv_obj_t* container) override;
|
||||
esp_err_t deinit(void) override;
|
||||
std::string get_name(void) const override;
|
||||
|
||||
private:
|
||||
// UI components
|
||||
lv_obj_t* _label_header= nullptr;
|
||||
lv_obj_t* _label_counter= nullptr;
|
||||
lv_obj_t* _btn_increment= nullptr;
|
||||
lv_obj_t* _btn_decrement= nullptr;
|
||||
lv_obj_t* _slider_brightness= nullptr;
|
||||
lv_obj_t* _label_slider_value= nullptr;
|
||||
|
||||
// State
|
||||
int _counter= 0;
|
||||
|
||||
// Event callbacks
|
||||
static void btn_increment_event_cb(lv_event_t* e);
|
||||
static void btn_decrement_event_cb(lv_event_t* e);
|
||||
static void slider_event_cb(lv_event_t* e);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief AppDescriptor for DemoApp
|
||||
*
|
||||
* Registers the demo app with the AppRegistry and provides
|
||||
* icon rendering functionality.
|
||||
*/
|
||||
class DemoAppDescriptor : public AppDescriptor {
|
||||
public:
|
||||
DemoAppDescriptor();
|
||||
void draw_icon(lv_obj_t* parent) override;
|
||||
|
||||
private:
|
||||
static DemoApp* _app_instance;
|
||||
};
|
||||
@@ -126,62 +126,86 @@ bool DiscordApp::on_back_button_pressed() {
|
||||
// ============================================================================
|
||||
|
||||
void DiscordApp::build_main_page(lv_obj_t* page) {
|
||||
// Status icon (large, centered)
|
||||
status_icon_label_ = lv_label_create(page);
|
||||
lv_label_set_text(status_icon_label_, LV_SYMBOL_MUTE);
|
||||
// Using default font (only montserrat_14 is enabled)
|
||||
lv_obj_align(status_icon_label_, LV_ALIGN_CENTER, 0, -80);
|
||||
// Set up main page with flex column layout
|
||||
lv_obj_set_flex_flow(page, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(page, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_set_style_pad_all(page, 10, 0);
|
||||
|
||||
// Status text
|
||||
status_text_label_ = lv_label_create(page);
|
||||
lv_label_set_text(status_text_label_, "Unknown Status");
|
||||
// Using default font
|
||||
lv_obj_align(status_text_label_, LV_ALIGN_CENTER, 0, -20);
|
||||
|
||||
// Mute button
|
||||
mute_button_ = lv_btn_create(page);
|
||||
lv_obj_set_size(mute_button_, 200, 60);
|
||||
lv_obj_align(mute_button_, LV_ALIGN_CENTER, 0, 50);
|
||||
lv_obj_add_event_cb(mute_button_, on_mute_button_clicked, LV_EVENT_CLICKED, this);
|
||||
|
||||
lv_obj_t* mute_label = lv_label_create(mute_button_);
|
||||
lv_label_set_text(mute_label, "MUTE");
|
||||
// Using default font
|
||||
lv_obj_center(mute_label);
|
||||
|
||||
// Settings button (gear icon in corner)
|
||||
lv_obj_t* settings_btn = lv_btn_create(page);
|
||||
lv_obj_set_size(settings_btn, 60, 60);
|
||||
lv_obj_align(settings_btn, LV_ALIGN_BOTTOM_RIGHT, -10, -10);
|
||||
lv_obj_add_event_cb(settings_btn, on_settings_button_clicked, LV_EVENT_CLICKED, this);
|
||||
|
||||
lv_obj_t* settings_icon = lv_label_create(settings_btn);
|
||||
lv_label_set_text(settings_icon, LV_SYMBOL_SETTINGS);
|
||||
// Using default font
|
||||
lv_obj_center(settings_icon);
|
||||
|
||||
// Error notification (hidden by default)
|
||||
// === Top Section: Error Notification ===
|
||||
error_notification_ = lv_obj_create(page);
|
||||
lv_obj_set_size(error_notification_, 250, 50);
|
||||
lv_obj_align(error_notification_, LV_ALIGN_TOP_MID, 0, 10);
|
||||
lv_obj_set_width(error_notification_, LV_PCT(90));
|
||||
lv_obj_set_height(error_notification_, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_bg_color(error_notification_, lv_color_hex(0xFF0000), 0);
|
||||
lv_obj_set_style_bg_opa(error_notification_, LV_OPA_70, 0);
|
||||
lv_obj_set_style_pad_all(error_notification_, 10, 0);
|
||||
lv_obj_set_style_radius(error_notification_, 8, 0);
|
||||
lv_obj_add_flag(error_notification_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_set_flex_flow(error_notification_, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(error_notification_, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
|
||||
lv_obj_t* error_label = lv_label_create(error_notification_);
|
||||
lv_label_set_text(error_label, LV_SYMBOL_WARNING " Connection Lost");
|
||||
lv_obj_set_style_text_color(error_label, lv_color_white(), 0);
|
||||
lv_obj_center(error_label);
|
||||
|
||||
// Show config prompt if not configured
|
||||
// === Center Section: Main Content ===
|
||||
lv_obj_t* center_container = lv_obj_create(page);
|
||||
lv_obj_set_size(center_container, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_bg_opa(center_container, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_border_width(center_container, 0, 0);
|
||||
lv_obj_set_style_pad_all(center_container, 0, 0);
|
||||
lv_obj_set_flex_flow(center_container, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(center_container, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_set_style_pad_row(center_container, 15, 0);
|
||||
lv_obj_set_flex_grow(center_container, 1);
|
||||
|
||||
// Status icon (large, centered)
|
||||
status_icon_label_ = lv_label_create(center_container);
|
||||
lv_label_set_text(status_icon_label_, LV_SYMBOL_MUTE);
|
||||
|
||||
// Status text
|
||||
status_text_label_ = lv_label_create(center_container);
|
||||
lv_label_set_text(status_text_label_, "Unknown Status");
|
||||
|
||||
// Mute button
|
||||
mute_button_ = lv_btn_create(center_container);
|
||||
lv_obj_set_size(mute_button_, 200, 60);
|
||||
lv_obj_add_event_cb(mute_button_, on_mute_button_clicked, LV_EVENT_CLICKED, this);
|
||||
|
||||
lv_obj_t* mute_label = lv_label_create(mute_button_);
|
||||
lv_label_set_text(mute_label, "MUTE");
|
||||
lv_obj_center(mute_label);
|
||||
|
||||
// === Bottom Section: Settings and Config Prompt ===
|
||||
lv_obj_t* bottom_container = lv_obj_create(page);
|
||||
lv_obj_set_size(bottom_container, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_bg_opa(bottom_container, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_border_width(bottom_container, 0, 0);
|
||||
lv_obj_set_style_pad_all(bottom_container, 0, 0);
|
||||
lv_obj_set_flex_flow(bottom_container, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(bottom_container, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
|
||||
// Config prompt (left side)
|
||||
if (!settings_configured_) {
|
||||
lv_obj_t* config_prompt = lv_label_create(page);
|
||||
lv_obj_t* config_prompt = lv_label_create(bottom_container);
|
||||
lv_label_set_text(config_prompt, "Tap " LV_SYMBOL_SETTINGS " to configure");
|
||||
// Using default font
|
||||
lv_obj_set_style_text_color(config_prompt, lv_color_hex(0x888888), 0);
|
||||
lv_obj_align(config_prompt, LV_ALIGN_BOTTOM_LEFT, 10, -10);
|
||||
} else {
|
||||
// Empty spacer if configured
|
||||
lv_obj_t* spacer = lv_obj_create(bottom_container);
|
||||
lv_obj_set_size(spacer, 0, 0);
|
||||
lv_obj_set_style_bg_opa(spacer, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_border_width(spacer, 0, 0);
|
||||
}
|
||||
|
||||
// Settings button (right side)
|
||||
lv_obj_t* settings_btn = lv_btn_create(bottom_container);
|
||||
lv_obj_set_size(settings_btn, 60, 60);
|
||||
lv_obj_add_event_cb(settings_btn, on_settings_button_clicked, LV_EVENT_CLICKED, this);
|
||||
|
||||
lv_obj_t* settings_icon = lv_label_create(settings_btn);
|
||||
lv_label_set_text(settings_icon, LV_SYMBOL_SETTINGS);
|
||||
lv_obj_center(settings_icon);
|
||||
|
||||
// Update display with current state
|
||||
update_status_display();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user