Description
For a home automation system I am developing I am looking for a nice way to dynamically add “components” to my HMI.
Note, the “building” of the components only runs once at start based on a config file. (So before lv_task_handler()
is called)
What MCU/Processor/Board and compiler are you using?
The LVGL Simulator for visual studio
What LVGL version are you using?
V8.3.0 @Update ROADMAP.rst · lvgl/lvgl@ed681f9 · GitHub
What do you want to achieve?
Something that looks like the screenshots in this topic. How do you remove the padding of a page on a tabview page?
What have you tried so far?
Added the tabview widget with a bar on the 1st tab and now I am trying to add multiple buttons on a grid. However now I get everything on both pages.
Code to reproduce
lv_obj_t* AddClimate(lv_obj_t* parent)
{
static lv_style_t style_indic;
lv_style_init(&style_indic);
lv_style_set_bg_opa(&style_indic, LV_OPA_COVER);
lv_style_set_bg_color(&style_indic, lv_palette_main(LV_PALETTE_RED));
lv_style_set_bg_grad_color(&style_indic, lv_palette_main(LV_PALETTE_BLUE));
lv_style_set_bg_grad_dir(&style_indic, LV_GRAD_DIR_VER);
lv_obj_t* bar = lv_bar_create(parent);
lv_obj_add_style(bar, &style_indic, LV_PART_INDICATOR);
lv_obj_set_size(bar, 20, 200);
lv_obj_center(bar);
lv_bar_set_range(bar, -20, 40);
return NULL;
}
static void LightEventHandler(lv_event_t* e)
{
int* index = (int*)lv_event_get_user_data(e);
LV_LOG_USER("Light Toggled %d", *index);
}
lv_obj_t* AddLight(lv_obj_t* parent, const char* name, int* index)
{
lv_obj_t* button = lv_btn_create(parent);
lv_obj_add_event(button, LightEventHandler, LV_EVENT_VALUE_CHANGED, index);
lv_obj_add_flag(button, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_height(button, LV_SIZE_CONTENT);
lv_obj_center(button);
lv_obj_t* label = lv_label_create(button);
lv_label_set_text(label, name);
lv_obj_center(label);
return button;
}
void CreateScreen1(void)
{
/*Create a Tab view object*/
lv_obj_t* tabView = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 50);
lv_obj_t* tabContent = lv_tabview_get_content(tabView);
lv_obj_clear_flag(tabContent, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_layout(tabContent, LV_LAYOUT_GRID);
static lv_coord_t column_dsc[] = { 100, 100, LV_GRID_TEMPLATE_LAST }; /*2 columns with 100 and 400 ps width*/
static lv_coord_t row_dsc[] = { 100, 100, 100, LV_GRID_TEMPLATE_LAST }; /*3 100 px tall rows*/
//Add the climate group
lv_obj_t* climateTab = lv_tabview_add_tab(tabView, "Climate");
lv_obj_t* climate = AddClimate(climateTab);
lv_obj_t* lightTab = lv_tabview_add_tab(tabView, "Light");
static int mainIndex = 1;
lv_obj_t* mainLight = AddLight(lightTab, "Main", &mainIndex);
lv_obj_set_grid_cell(mainLight, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, 0, 1);
static int secondIndex = 2;
lv_obj_t* secondLight = AddLight(lightTab, "Second", &secondIndex);
lv_obj_set_grid_cell(secondLight, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, 1, 1);
}
Screenshot and/or video
Tab 1:
Tab 2: