/* * home_screen.c * * Created on: Aug 7, 2023 * Author: leo */ #include #include #include #include "PSE_unit_edit_screen.h" #include "PSE_unit.h" #include "lvgl.h" static lv_obj_t* parent_screen; static void back_button_handler(lv_event_t * e){ lv_event_code_t code = lv_event_get_code(e); if(code == LV_EVENT_CLICKED) { // Save lv_scr_load_anim(parent_screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 100, true); } } static lv_coord_t widg_col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; static lv_coord_t widg_row_dsc[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; static lv_obj_t* flow_widget(lv_obj_t* parent, pse_unit* unit){ // The main container lv_obj_t* cont = lv_obj_create(parent); lv_obj_set_size(cont, lv_pct(24), lv_pct(100)); lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN); // lv_obj_add_event_cb(cont, unit_widget_clicked_handler, LV_EVENT_ALL, pse_unit); // flow setting lv_obj_t* flow = lv_label_create(cont); lv_obj_set_width(flow, lv_pct(100)); lv_obj_set_flex_grow(flow, 1); lv_label_set_text_fmt(flow, "Debit : \n%d.%d\nmL/mn", unit->flow / 1000, unit->flow % 1000); return cont; } void PSE_unit_edit_screen_Gen(lv_obj_t* parent, pse_unit* unit){ parent_screen = parent; // 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_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 back button lv_obj_t* back_button = lv_btn_create(top_menu); lv_obj_set_size(back_button, lv_pct(10), lv_pct(100)); lv_obj_set_align(back_button, LV_ALIGN_TOP_LEFT); lv_obj_add_event_cb(back_button, back_button_handler, LV_EVENT_ALL, NULL); // add the back label lv_obj_t* back_label = lv_label_create(back_button); lv_label_set_text(back_label, LV_SYMBOL_LEFT); lv_obj_center(back_label); // grid layout for the widgets lv_obj_t* units_grid = lv_obj_create(scr); lv_obj_align_to(units_grid, top_menu, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); lv_obj_set_size(units_grid, lv_pct(100), lv_pct(80)); lv_obj_set_style_pad_all(units_grid, 5, 0); lv_obj_set_layout(units_grid, LV_LAYOUT_GRID); lv_obj_set_grid_dsc_array(units_grid, widg_col_dsc, widg_row_dsc); // Flow widget lv_obj_t* obj = flow_widget(units_grid, unit); lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1); // fade in the new screen lv_scr_load_anim(scr, LV_SCR_LOAD_ANIM_FADE_ON, 100, 100, false); }