Overriding default styles

Hi all,

LittlevGL contains a set of styles by default. One can take any of those, copy and modify. Still the default ones stay in the RAM - for nothing.

Suggestion: include a flag in lv_conf.h, something like

#define LV_STYLE_INIT_OVERRIDE my_style_init

If the above was set, the internal function lv_style_init() would be #defined out, instead the user had to declare her/his own function to make the default styles as required.

Of course no one forbids re-initializing those lv_style_* -structures after calling lv_init(), but getting rid of the “factory” initializations would save some constant memory estate (initializer constants could be discarded).

Am I totally off track with my thoughts?

Be safe,
-petri h

The style system has been completely rewritten for 7.0, so these styles will no longer exist.

If you’re interested in taking a look, here is a brief write-up by @kisvegabor.

Oh, that was fast - thank you! I will certainly have a look at this.

Meanwhile, another question of total different topic: object positioning (or should I open a new topic??).

Now when I call lv_obj_set_pos(...), the position will be the top left corner of that particular object.

I wonder if there’s a way to use the center of the object? Say, I have a labels with text of different widths and I’d like to arrange those center aligned on top of each other. Of course, e.g for X position I can use (lv_disp_get_hor_res(NULL) - (lv_obj_get_width(object) / 2), but is there any easier way? Inside a label I can adjust the alignment though.

The whole alignment system is still a little mystery … I have been fiddling around with LvGL couple of weeks now, but there are still many aspect not 100% clear to me.


Officially, you should open a new topic, but don’t worrry about it this time.

You can take advantage of the fact that lv_obj_align_origo moves the center of an object.

lv_obj_align_origo(obj, NULL, LV_ALIGN_IN_TOP_LEFT, x, y)

This will position the center of the object at (x,y) relative to its parent.

I suggest you create a container to hold all the labels, and set their text alignment to center. Then you can align the container on your screen however you wish.

1 Like

Thanks a lot. I will try this!