11#include "lvgl.h"
22#include "display/display.h"
3+ #include "display/utils.h"
34
45// Holds the home screen object.
56lv_obj_t * home_screen ;
@@ -9,14 +10,22 @@ lv_obj_t *label_day;
910
1011void home_screen_init () {
1112 // Create the screen object which is the LV object with no parent.
12- home_screen = lv_obj_create (NULL );
13- // Remove the ability to scroll the screen.
14- lv_obj_remove_flag (home_screen , LV_OBJ_FLAG_SCROLLABLE );
13+ home_screen = create_screen ();
14+
15+ // Create a vertical flex layout container centered in the screen.
16+ lv_obj_t * main_column = create_column (home_screen , 100 , 100 );
17+
18+ // Create a horizontal flex layout containers that will hold date and time labels.
19+ lv_obj_t * clock_label_row = create_row (main_column , 100 , 20 );
20+ lv_obj_t * date_day_row = create_row (main_column , 100 , 20 );
21+
22+ // Add spacing between rows.
23+ lv_obj_set_style_pad_row (main_column , 5 , LV_PART_MAIN );
1524
1625 // Render items in the screen.
17- render_clock_label ();
18- render_date_label ();
19- render_day_label ();
26+ render_clock_label (clock_label_row );
27+ render_date_label (date_day_row );
28+ render_day_label (date_day_row );
2029
2130 // Add an event handler for all possible events.
2231 lv_obj_add_event_cb (home_screen , home_screen_event , LV_EVENT_ALL , NULL );
@@ -26,53 +35,27 @@ void home_screen_event(lv_event_t * e) {
2635 // lv_event_code_t event_code = lv_event_get_code(e);lv_obj_t * target = lv_event_get_target(e);
2736}
2837
29- void render_clock_label () {
30- // Create a new label and expand its size to content size and align it to center.
31- label_clock = lv_label_create (home_screen );
38+ void render_clock_label (lv_obj_t * flex_element ) {
39+ label_clock = lv_label_create (flex_element );
3240 lv_obj_set_width (label_clock , LV_SIZE_CONTENT );
3341 lv_obj_set_height (label_clock , LV_SIZE_CONTENT );
34- lv_obj_set_align (label_clock , LV_ALIGN_CENTER );
35-
36- // Align to center but with upward Y offset.
37- lv_obj_align (label_clock , LV_ALIGN_CENTER , 0 , -20 );
38-
39- // Set the default text.
4042 lv_label_set_text (label_clock , "HH:mm" );
4143
42- // Format the clock text string.
43- /* 1. Set the letter spacing to 5. (Between letters)
44- * 2. Set the line spacing to 0. (Between new lines)
45- * 3. Align the text automatically.
46- * 4. Set no decoration on the text.
47- * 5. Set the font and the size to Montserrat 46.
48- */
4944 lv_obj_set_style_text_letter_space (label_clock , 5 , LV_PART_MAIN | LV_STATE_DEFAULT );
5045 lv_obj_set_style_text_line_space (label_clock , 0 , LV_PART_MAIN | LV_STATE_DEFAULT );
51- lv_obj_set_style_text_align (label_clock , LV_TEXT_ALIGN_AUTO , LV_PART_MAIN | LV_STATE_DEFAULT );
46+ lv_obj_set_style_text_align (label_clock , LV_TEXT_ALIGN_CENTER , LV_PART_MAIN | LV_STATE_DEFAULT );
5247 lv_obj_set_style_text_decor (label_clock , LV_TEXT_DECOR_NONE , LV_PART_MAIN | LV_STATE_DEFAULT );
5348 lv_obj_set_style_text_font (label_clock , & lv_font_montserrat_46 , LV_PART_MAIN | LV_STATE_DEFAULT );
5449}
5550
56- void render_date_label () {
57- // Create a new label and expand its size to content size and align it to center.
58- label_date = lv_label_create (home_screen );
59-
60- // Align it to the bottom of the clock label with a margin of 2x5y pixels.
61- lv_obj_align_to (label_date , label_clock , LV_ALIGN_OUT_BOTTOM_MID , -65 , 0 );
62-
63- // Set the default text.
51+ void render_date_label (lv_obj_t * flex_element ) {
52+ label_date = lv_label_create (flex_element );
6453 lv_label_set_text (label_date , "YYYY-MM-DD" );
6554 lv_obj_set_style_text_font (label_date , & lv_font_montserrat_18 , LV_PART_MAIN | LV_STATE_DEFAULT );
6655}
6756
68- void render_day_label () {
69- // Create a new label and expand its size to content size and align it to center.
70- label_day = lv_label_create (home_screen );
71-
72- // Align it to the bottom of the clock label with a margin of 2x5y pixels.
73- lv_obj_align_to (label_day , label_clock , LV_ALIGN_OUT_BOTTOM_MID , +45 , 0 );
74-
75- // Set the default text.
57+ void render_day_label (lv_obj_t * flex_element ) {
58+ label_day = lv_label_create (flex_element );
7659 lv_label_set_text (label_day , "DAY" );
7760 lv_obj_set_style_text_font (label_day , & lv_font_montserrat_18 , LV_PART_MAIN | LV_STATE_DEFAULT );
7861}
0 commit comments