Skip to content

Commit d9f9b37

Browse files
committed
feat(ui): render wallpaper with launcher asset
1 parent 3dd4e62 commit d9f9b37

2 files changed

Lines changed: 52 additions & 25 deletions

File tree

custom/ui/ui_wallpaper.c

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@
55
*/
66
#include "ui_wallpaper.h"
77

8-
ui_wallpaper_t *ui_wallpaper_attach(lv_obj_t *parent)
8+
#include "app/assets/assets.h"
9+
10+
ui_wallpaper_t* ui_wallpaper_attach(lv_obj_t* parent)
911
{
10-
if (parent == NULL) {
12+
if (parent == NULL)
13+
{
1114
return NULL;
1215
}
1316

14-
ui_wallpaper_t *wallpaper = (ui_wallpaper_t *)lv_malloc(sizeof(ui_wallpaper_t));
15-
if (wallpaper == NULL) {
17+
ui_wallpaper_t* wallpaper = (ui_wallpaper_t*)lv_malloc(sizeof(ui_wallpaper_t));
18+
if (wallpaper == NULL)
19+
{
1620
return NULL;
1721
}
1822
lv_memset(wallpaper, 0, sizeof(ui_wallpaper_t));
1923

2024
wallpaper->layer = lv_obj_create(parent);
21-
if (wallpaper->layer == NULL) {
25+
if (wallpaper->layer == NULL)
26+
{
2227
lv_free(wallpaper);
2328
return NULL;
2429
}
@@ -27,22 +32,41 @@ ui_wallpaper_t *ui_wallpaper_attach(lv_obj_t *parent)
2732
lv_obj_set_size(wallpaper->layer, LV_PCT(100), LV_PCT(100));
2833
lv_obj_add_flag(wallpaper->layer, LV_OBJ_FLAG_IGNORE_LAYOUT);
2934
lv_obj_move_background(wallpaper->layer);
30-
lv_obj_set_style_bg_opa(wallpaper->layer, LV_OPA_COVER, LV_PART_MAIN);
31-
lv_obj_set_style_bg_color(wallpaper->layer, lv_color_hex(0xfcff9e), LV_PART_MAIN);
32-
lv_obj_set_style_bg_grad_color(wallpaper->layer, lv_color_hex(0xc67700), LV_PART_MAIN);
33-
lv_obj_set_style_bg_grad_dir(wallpaper->layer, LV_GRAD_DIR_HOR, LV_PART_MAIN);
35+
lv_obj_set_style_bg_opa(wallpaper->layer, LV_OPA_TRANSP, LV_PART_MAIN);
3436
lv_obj_set_style_border_width(wallpaper->layer, 0, LV_PART_MAIN);
3537

38+
wallpaper->image = lv_image_create(wallpaper->layer);
39+
if (wallpaper->image == NULL)
40+
{
41+
lv_obj_del(wallpaper->layer);
42+
lv_free(wallpaper);
43+
return NULL;
44+
}
45+
46+
lv_obj_remove_style_all(wallpaper->image);
47+
lv_image_set_src(wallpaper->image, &launcher_bg);
48+
lv_obj_set_align(wallpaper->image, LV_ALIGN_CENTER);
49+
lv_obj_add_flag(wallpaper->image, LV_OBJ_FLAG_IGNORE_LAYOUT);
50+
lv_obj_move_background(wallpaper->image);
51+
3652
return wallpaper;
3753
}
3854

39-
void ui_wallpaper_detach(ui_wallpaper_t *wallpaper)
55+
void ui_wallpaper_detach(ui_wallpaper_t* wallpaper)
4056
{
41-
if (wallpaper == NULL) {
57+
if (wallpaper == NULL)
58+
{
4259
return;
4360
}
4461

45-
if (wallpaper->layer != NULL) {
62+
if (wallpaper->image != NULL)
63+
{
64+
lv_obj_del(wallpaper->image);
65+
wallpaper->image = NULL;
66+
}
67+
68+
if (wallpaper->layer != NULL)
69+
{
4670
lv_obj_del(wallpaper->layer);
4771
wallpaper->layer = NULL;
4872
}

custom/ui/ui_wallpaper.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,32 @@
66
#pragma once
77

88
#ifdef __has_include
9-
#if __has_include("lvgl.h")
10-
#ifndef LV_LVGL_H_INCLUDE_SIMPLE
11-
#define LV_LVGL_H_INCLUDE_SIMPLE
12-
#endif
13-
#endif
9+
# if __has_include("lvgl.h")
10+
# ifndef LV_LVGL_H_INCLUDE_SIMPLE
11+
# define LV_LVGL_H_INCLUDE_SIMPLE
12+
# endif
13+
# endif
1414
#endif
1515

1616
#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
17-
#include "lvgl.h"
17+
# include "lvgl.h"
1818
#else
19-
#include "lvgl/lvgl.h"
19+
# include "lvgl/lvgl.h"
2020
#endif
2121

2222
#ifdef __cplusplus
23-
extern "C" {
23+
extern "C"
24+
{
2425
#endif
2526

26-
typedef struct ui_wallpaper_t {
27-
lv_obj_t *layer;
28-
} ui_wallpaper_t;
27+
typedef struct ui_wallpaper_t
28+
{
29+
lv_obj_t* layer;
30+
lv_obj_t* image;
31+
} ui_wallpaper_t;
2932

30-
ui_wallpaper_t *ui_wallpaper_attach(lv_obj_t *parent);
31-
void ui_wallpaper_detach(ui_wallpaper_t *wallpaper);
33+
ui_wallpaper_t* ui_wallpaper_attach(lv_obj_t* parent);
34+
void ui_wallpaper_detach(ui_wallpaper_t* wallpaper);
3235

3336
#ifdef __cplusplus
3437
}

0 commit comments

Comments
 (0)