use classes for ui

This commit is contained in:
2023-08-09 09:09:17 +02:00
parent a8169967e4
commit 1f30e92396
3 changed files with 25 additions and 13 deletions

View File

@@ -28,7 +28,9 @@ void setup()
lv_i18n_set_locale("de-DE"); lv_i18n_set_locale("de-DE");
lv_begin(); lv_begin();
ui_LaunchScreen_open();
LaunchScreen launchScreen;
launchScreen.show();
} }
void loop() void loop()

View File

@@ -16,25 +16,30 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
#include "ui/launch_screen.h" #include "launch_screen.h"
#include <lvgl.h> #include <lvgl.h>
#include "lv_i18n/lv_i18n.h" #include "lv_i18n/lv_i18n.h"
void ui_LaunchScreen_open() lv_obj_t *screen;
LaunchScreen::LaunchScreen()
{ {
auto ui_SplashScreen = lv_obj_create(NULL); screen = lv_obj_create(NULL);
lv_obj_clear_flag(ui_SplashScreen, LV_OBJ_FLAG_SCROLLABLE); lv_obj_clear_flag(screen, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_bg_color(ui_SplashScreen, lv_color_make(0x78, 0x94, 0xa7), 0); lv_obj_set_style_bg_color(screen, lv_color_make(0x78, 0x94, 0xa7), 0);
LV_IMG_DECLARE(os_railway_icon_lvgl); LV_IMG_DECLARE(os_railway_icon_lvgl);
auto *img = lv_img_create(ui_SplashScreen); auto *logo = lv_img_create(screen);
lv_img_set_src(img, &os_railway_icon_lvgl); lv_img_set_src(logo, &os_railway_icon_lvgl);
lv_obj_align(img, LV_ALIGN_CENTER, 0, 0); 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_label_set_text(label, _("appName"));
lv_obj_align(label, LV_ALIGN_BOTTOM_MID, 0, -25); lv_obj_align(label, LV_ALIGN_BOTTOM_MID, 0, -25);
}
lv_disp_load_scr(ui_SplashScreen);
void LaunchScreen::show()
{
lv_disp_load_scr(screen);
} }

View File

@@ -18,4 +18,9 @@
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
#pragma once #pragma once
void ui_LaunchScreen_open(); class LaunchScreen
{
public:
LaunchScreen();
void show();
};