run button

This commit is contained in:
leo 2023-08-08 16:31:09 +02:00
parent 2ec5147e7d
commit f6a2f62fad
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB

View File

@ -5,13 +5,48 @@
* Author: leo * Author: leo
*/ */
#include <stdio.h>
#include "lvgl.h" #include "lvgl.h"
void Home_Screen_Gen(void){ static void run_handler(lv_event_t * e){
lv_obj_t* scr = lv_obj_create(NULL); lv_event_code_t code = lv_event_get_code(e);
lv_obj_set_layout(scr, LV_LAYOUT_GRID);
lv_obj_t* run_button = lv_btn_create(scr); if(code == LV_EVENT_VALUE_CHANGED) {
lv_obj_t* button = lv_event_get_target(e);
lv_scr_load(scr); lv_obj_t* label = lv_obj_get_child(button, 0);
lv_state_t state = lv_obj_get_state(button);
if(state & LV_STATE_CHECKED){
lv_label_set_text(label, LV_SYMBOL_PAUSE);
}
else{
lv_label_set_text(label, LV_SYMBOL_PLAY);
}
}
}
void Home_Screen_Gen(void){
// Create a new screen
lv_obj_t* scr = lv_obj_create(NULL);
// create the top menu on the top 20%
lv_obj_t* top_menu = lv_obj_create(scr);
lv_obj_set_align(top_menu, LV_ALIGN_OUT_TOP_LEFT);
lv_obj_set_size(top_menu, lv_pct(100), lv_pct(20));
lv_obj_set_style_pad_all(top_menu, 5, 0);
// add a run button
lv_obj_t* run_button = lv_btn_create(top_menu);
lv_obj_set_size(run_button, lv_pct(10), lv_pct(100));
lv_obj_set_align(run_button, LV_ALIGN_TOP_LEFT);
lv_obj_add_flag(run_button, LV_OBJ_FLAG_CHECKABLE);
lv_obj_add_event_cb(run_button, run_handler, LV_EVENT_ALL, NULL);
// add the start label
lv_obj_t* run_label = lv_label_create(run_button);
lv_label_set_text(run_label, LV_SYMBOL_PLAY);
lv_obj_center(run_label);
// fade in the new screen
lv_scr_load_anim(scr, LV_SCR_LOAD_ANIM_FADE_ON, 100, 100, false);
} }