Add custom code in generated files

What do you want to achieve?

It would be very useful that we can add some come in generated without being erased,
like in screen.c file, adding a segment of comments as generated code by stm32cubemx,
for example user can add something to indicate to SLS to not touch this part in code

/*user code begin*/ 
custom code 
/*user code end*/

i don’t know if it will be possible, depending of how the code is exported by SLS, is it replacing files or scanning code first,

second option is to add a custom file and link it with ui files, that won’t be changed by SLS

Would like to have it in each screen init code? Or do you have other places in mind too?

yes in each screen init code, it would be cool, if it’s possible in ui.c too
for the events there’s is already an option to call function created in ui_events.c, but not all events trigger are supported yet

For components we already have ui_comp_hook.c. The functions in it are called after component creation. We could do something similar with the screens too.

What do you think?

Components are not made to have a lot of objects in it, and they are not declared as global variables, if i understand well your vision about ui_comp_hook.c is to add some functionnality that doesn’t exist yet in SLS,
i haven’t tried yet to use ui_comp_hook.c, i assume that if we add components it will add function for each component but the code inside function won’t be erased, is it working like that ?

when we export code from SLS, the files are replaced or just the code inside ?

I think as objects created in screens are global it’s okay to add a function like ui_comp_hook.c,
just in LVGL the order of creation is important for controlling layers (possible to use lv_obj_move_foreground(obj) ) , but for me i was thinking of adding widgets that are not existing in SLS (example : menu, list …) and have the possibility to declare as global variable in same file.

I don’t know if my idea is clear, Excuse my bad english :woozy_face:

Every screen have event part. Your user code now exist is simple Event onload start or onloaded. Then in files ui_events.c/h you can create code not rewrited…

1 Like

In the practice we usually do this:

//New functions
void ui_init_ext(void)

  //Customization on ui_screen1

  //Customization on ui_screen2
  lv_label_set_text(ui_screen2_label1, "Hello");

In the end you need to call ui_ext_init instead of ui_init.

1 Like

i don’t have many screens, i work in one screen but it contains a lot of objects (i don’t know if it’s a good way to do or the best is to use many screens and use the function lv_obj_set_parent to move object from one screen to another (example: header will be the same on all screens)

there is no event refresh, and i’ll need to add timers too for some events, so i thought of adding it directly in screens

Okay i’ll try to use this, I just thought if you could offer already a customization in code by SLS it would be great, it will give users more flexibility in code.

Thank you,

I didn’t get a response to this post, is it planned in future to have possibility of creating styles and apply it to object ?

Sorry, I’m responding now.

1 Like

lv_timers is not connect to screen or object. Timers is based on time and callback func.

1 Like