@@ -8,8 +8,6 @@ typedef struct {
88 int count_val ;
99} my_timer_context_t ;
1010
11- static lv_obj_t * img_text ;
12- static lv_obj_t * label_value ; // Label to display the value
1311
1412static void ota_button_event_handler (lv_event_t * e ) {
1513 lv_obj_t * btn = lv_event_get_target (e );
@@ -37,14 +35,20 @@ static void ota_button_event_handler(lv_event_t *e) {
3735 }
3836}
3937
40-
4138static void add_number_buttons (lv_obj_t * scr , lv_obj_t * ref_obj ) {
4239 int button_width = 50 ;
4340 int button_height = 60 ;
4441
4542 lv_obj_t * flex_cont = lv_obj_create (scr );
4643 lv_obj_set_size (flex_cont , 5 * button_width + 4 * 10 , button_height );
47- lv_obj_align_to (flex_cont , ref_obj , LV_ALIGN_OUT_TOP_MID , 0 , -10 );
44+
45+ // Check if ref_obj is provided, if not, align to the screen
46+ if (ref_obj ) {
47+ lv_obj_align_to (flex_cont , ref_obj , LV_ALIGN_OUT_TOP_MID , 0 , -10 );
48+ } else {
49+ lv_obj_align (flex_cont , LV_ALIGN_CENTER , 0 , 0 ); // Center the container on the screen
50+ }
51+
4852 lv_obj_set_flex_flow (flex_cont , LV_FLEX_FLOW_ROW );
4953 lv_obj_set_flex_align (flex_cont , LV_FLEX_ALIGN_SPACE_BETWEEN , LV_FLEX_ALIGN_CENTER , LV_FLEX_ALIGN_CENTER );
5054 lv_obj_set_scrollbar_mode (flex_cont , LV_SCROLLBAR_MODE_OFF );
@@ -71,60 +75,8 @@ static void add_number_buttons(lv_obj_t *scr, lv_obj_t *ref_obj) {
7175 }
7276}
7377
74- static void add_icon_buttons (lv_obj_t * scr , lv_obj_t * ref_obj ) {
75- int button_width = 60 ; // Button width
76- int button_height = 60 ; // Button height
77-
78- // Create a flex container for the icon buttons
79- lv_obj_t * icon_flex_cont = lv_obj_create (scr );
80- lv_obj_set_size (icon_flex_cont , 4 * button_width + 3 * 10 , button_height );
81- lv_obj_align_to (icon_flex_cont , ref_obj , LV_ALIGN_OUT_TOP_MID , 0 , - button_height - 20 );
82- lv_obj_set_flex_flow (icon_flex_cont , LV_FLEX_FLOW_ROW );
83- lv_obj_set_flex_align (icon_flex_cont , LV_FLEX_ALIGN_SPACE_BETWEEN , LV_FLEX_ALIGN_CENTER , LV_FLEX_ALIGN_CENTER );
84- lv_obj_set_scrollbar_mode (icon_flex_cont , LV_SCROLLBAR_MODE_OFF );
85-
86- // Array of raw images for icons
87- const lv_img_dsc_t * icons [] = {& cloud_raw , & sun_raw , & snowflake_raw , & wind_raw };
88-
89- // Create and position the buttons within the icon flex container
90- for (int i = 0 ; i < 4 ; i ++ ) {
91- lv_obj_t * btn = lv_btn_create (icon_flex_cont );
92- lv_obj_set_size (btn , button_width , button_height );
93-
94- // Create an image for the button with the icon
95- lv_obj_t * img = lv_img_create (btn );
96- lv_img_set_src (img , icons [i ]);
97- lv_obj_center (img ); // Center the image within the button
98- }
99- }
100-
10178
10279void bootloader_ui (lv_obj_t * scr ) {
103- // Create new image and make it transparent
104- img_text = lv_img_create (scr );
105- lv_img_set_src (img_text , & esp_text );
106- lv_obj_set_style_img_opa (img_text , 0 , 0 );
107-
108- // Create a label for displaying the slider value
109- label_value = lv_label_create (scr );
110- lv_label_set_text (label_value , "0°C" ); // Initialize with a default value
111-
112- // Create a slider
113- slider = lv_slider_create (scr );
114- lv_obj_set_width (slider , 200 ); // Set the slider's width
115-
116- // Position the slider at the bottom of the screen
117- lv_obj_align (slider , LV_ALIGN_BOTTOM_MID , 0 , -10 ); // -10 pixels from the bottom for some padding
118-
119- // Position the label above the slider
120- lv_obj_align_to (label_value , slider , LV_ALIGN_OUT_TOP_MID , 0 , -10 ); // Align above slider with some padding
121-
122- // Set the slider's range
123- lv_slider_set_range (slider , -20 , 40 );
124-
125- // Add event callback to the slider
126- lv_obj_add_event_cb (slider , slider_event_handler , LV_EVENT_VALUE_CHANGED , NULL );
12780
128- add_number_buttons (scr , label_value );
129- add_icon_buttons (scr , label_value );
81+ add_number_buttons (scr , NULL );
13082}
0 commit comments