From 1f30e9239643335c56a54e6b19c96baa8d60c286 Mon Sep 17 00:00:00 2001 From: Peter Siegmund Date: Wed, 9 Aug 2023 09:09:17 +0200 Subject: [PATCH] use classes for ui --- src/main.cpp | 4 +++- src/ui/launch_screen.cpp | 27 ++++++++++++++++----------- src/ui/launch_screen.h | 7 ++++++- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 375a6e3..7504f10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,7 +28,9 @@ void setup() lv_i18n_set_locale("de-DE"); lv_begin(); - ui_LaunchScreen_open(); + + LaunchScreen launchScreen; + launchScreen.show(); } void loop() diff --git a/src/ui/launch_screen.cpp b/src/ui/launch_screen.cpp index ceb73f6..cc3bdc3 100644 --- a/src/ui/launch_screen.cpp +++ b/src/ui/launch_screen.cpp @@ -16,25 +16,30 @@ // along with this program. If not, see . // //---------------------------------------------------------------------------- -#include "ui/launch_screen.h" +#include "launch_screen.h" #include #include "lv_i18n/lv_i18n.h" -void ui_LaunchScreen_open() +lv_obj_t *screen; + +LaunchScreen::LaunchScreen() { - auto ui_SplashScreen = lv_obj_create(NULL); - lv_obj_clear_flag(ui_SplashScreen, LV_OBJ_FLAG_SCROLLABLE); - lv_obj_set_style_bg_color(ui_SplashScreen, lv_color_make(0x78, 0x94, 0xa7), 0); + screen = lv_obj_create(NULL); + lv_obj_clear_flag(screen, LV_OBJ_FLAG_SCROLLABLE); + lv_obj_set_style_bg_color(screen, lv_color_make(0x78, 0x94, 0xa7), 0); LV_IMG_DECLARE(os_railway_icon_lvgl); - auto *img = lv_img_create(ui_SplashScreen); - lv_img_set_src(img, &os_railway_icon_lvgl); - lv_obj_align(img, LV_ALIGN_CENTER, 0, 0); + auto *logo = lv_img_create(screen); + lv_img_set_src(logo, &os_railway_icon_lvgl); + lv_obj_align(logo, LV_ALIGN_CENTER, 0, 0); - auto *label = lv_label_create(ui_SplashScreen); + auto *label = lv_label_create(screen); lv_label_set_text(label, _("appName")); lv_obj_align(label, LV_ALIGN_BOTTOM_MID, 0, -25); - - lv_disp_load_scr(ui_SplashScreen); +} + +void LaunchScreen::show() +{ + lv_disp_load_scr(screen); } diff --git a/src/ui/launch_screen.h b/src/ui/launch_screen.h index 5282dab..78b1b70 100644 --- a/src/ui/launch_screen.h +++ b/src/ui/launch_screen.h @@ -18,4 +18,9 @@ //---------------------------------------------------------------------------- #pragma once -void ui_LaunchScreen_open(); +class LaunchScreen +{ +public: + LaunchScreen(); + void show(); +};