Upgrading from v6 to v7, trouble with styling base objects


My v6 GUI is mostly built of base objects (boxes) that are styled and arranged. Moving to v7, using styles, none of the base objects are taking the style properties. They are all white with black text.

Is there some secret to styling base objects in v7?

What MCU/Processor/Board and compiler are you using?

IMXRT1062, arm-gcc

What LVGL version are you using?


What do you want to achieve?

Styling of base objects

What have you tried so far?

Creating a style and applying it to the base object. Migrating v6 code. Using docs from: https://docs.lvgl.io/latest/en/html/widgets/obj.html#style

Code to reproduce

	static lv_style_t lv_style_plain;

	lv_style_copy(&style_box_no_border, &lv_style_plain);
	lv_style_set_bg_color(&style_box_no_border, LV_STATE_DEFAULT, LV_COLOR_BLACK);
	lv_style_set_bg_grad_color(&style_box_no_border, LV_STATE_DEFAULT, LV_COLOR_BLACK);
	lv_style_set_bg_opa(&style_box_no_border, LV_STATE_DEFAULT, LV_OPA_COVER);
	lv_style_set_pad_top(&style_box_no_border, LV_STATE_DEFAULT, 0);
	lv_style_set_pad_bottom(&style_box_no_border, LV_STATE_DEFAULT, 0);
	lv_style_set_pad_left(&style_box_no_border, LV_STATE_DEFAULT, 0);
	lv_style_set_pad_right(&style_box_no_border, LV_STATE_DEFAULT, 0);
	lv_style_set_pad_inner(&style_box_no_border, LV_STATE_DEFAULT, 0);
	lv_style_set_border_width(&style_box_no_border, LV_STATE_DEFAULT, 0);

	lv_obj_t *controller_bar;
	controller_bar = lv_obj_create(parent, NULL);
	lv_obj_set_size(controller_bar, 320, 18);
	lv_obj_align(controller_bar, NULL, LV_ALIGN_IN_TOP_MID, 0, -1);
	lv_obj_add_style(controller_bar, LV_OBJ_PART_MAIN, &style_box_no_border);

Screenshot and/or video


I assume that lv_style_plain has been initialized elsewhere, but I don’t see you calling lv_style_init on &style_box_no_border.

Thanks, I think that was it. The example in the docs doesn’t show the style_init, so it wasn’t clear, but makes sense now. https://docs.lvgl.io/latest/en/html/overview/style.html#initialize-styles-and-set-get-properties

Also, if the style is copied it shouldn’t be initialized, just to be clear.