# Add custom code in generated files

**URL:** <http://forum.squareline.io/t/add-custom-code-in-generated-files/1361>\
**Category:** Feature requests\
**Created:** [June 15, 2023, 9:37am UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361 "2023-06-15T09:37:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zebra](http://forum.squareline.io/letter_avatar_proxy/v4/letter/z/c0e974/32.png) [@Zebra](http://forum.squareline.io/u/Zebra)\
**Post date:** [June 15, 2023, 9:37am UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/1 "2023-06-15T09:37:10Z")

</div>

### 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

```auto
/*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

---

<div class="post-metadata">

**Author:** ![kisvegabor](http://forum.squareline.io/user_avatar/forum.squareline.io/kisvegabor/32/537_2.png) [@kisvegabor](http://forum.squareline.io/u/kisvegabor)\
**Post date:** [June 20, 2023, 12:10am UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/2 "2023-06-20T00:10:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zebra](http://forum.squareline.io/letter_avatar_proxy/v4/letter/z/c0e974/32.png) [@Zebra](http://forum.squareline.io/u/Zebra)\
**Post date:** [June 20, 2023, 9:00am UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/3 "2023-06-20T09:00:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kisvegabor](http://forum.squareline.io/user_avatar/forum.squareline.io/kisvegabor/32/537_2.png) [@kisvegabor](http://forum.squareline.io/u/kisvegabor)\
**Post date:** [June 20, 2023, 3:11pm UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/4 "2023-06-20T15:11:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Zebra](http://forum.squareline.io/letter_avatar_proxy/v4/letter/z/c0e974/32.png) [@Zebra](http://forum.squareline.io/u/Zebra)\
**Post date:** [June 20, 2023, 4:14pm UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/5 "2023-06-20T16:14:08Z")

</div>

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](https://docs.lvgl.io/master/API/lv_api_map.html#_CPPv422lv_obj_move_foregroundP8lv_obj_t)(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 🥴

---

<div class="post-metadata">

**Author:** ![Marian\_M](http://forum.squareline.io/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@Marian\_M](http://forum.squareline.io/u/Marian_M)\
**Post date:** [June 20, 2023, 5:09pm UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/6 "2023-06-20T17:09:08Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![kisvegabor](http://forum.squareline.io/user_avatar/forum.squareline.io/kisvegabor/32/537_2.png) [@kisvegabor](http://forum.squareline.io/u/kisvegabor)\
**Post date:** [June 21, 2023, 11:43am UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/7 "2023-06-21T11:43:30Z")

</div>

In the practice we usually do this:

```c
//New functions
void ui_init_ext(void)
{
   ui_init();

  //Customization on ui_screen1
  lv_btn_create(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`.

---

<div class="post-metadata">

**Author:** ![Zebra](http://forum.squareline.io/letter_avatar_proxy/v4/letter/z/c0e974/32.png) [@Zebra](http://forum.squareline.io/u/Zebra)\
**Post date:** [June 22, 2023, 9:29am UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/8 "2023-06-22T09:29:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zebra](http://forum.squareline.io/letter_avatar_proxy/v4/letter/z/c0e974/32.png) [@Zebra](http://forum.squareline.io/u/Zebra)\
**Post date:** [June 22, 2023, 9:47am UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/9 "2023-06-22T09:47:30Z")

</div>

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](http://forum.squareline.io/t/create-styles-and-custom-themes/1306), is it planned in future to have possibility of creating styles and apply it to object ?

---

<div class="post-metadata">

**Author:** ![kisvegabor](http://forum.squareline.io/user_avatar/forum.squareline.io/kisvegabor/32/537_2.png) [@kisvegabor](http://forum.squareline.io/u/kisvegabor)\
**Post date:** [June 23, 2023, 8:34am UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/10 "2023-06-23T08:34:23Z")

</div>

> [@Zebra](#):
>
> I didn’t get a response to [this post](http://forum.squareline.io/t/create-styles-and-custom-themes/1306), is it planned in future to have possibility of creating styles and apply it to object ?

Sorry, I’m responding now.

---

<div class="post-metadata">

**Author:** ![Marian\_M](http://forum.squareline.io/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@Marian\_M](http://forum.squareline.io/u/Marian_M)\
**Post date:** [June 23, 2023, 4:08pm UTC](http://forum.squareline.io/t/add-custom-code-in-generated-files/1361/11 "2023-06-23T16:08:59Z")

</div>

lv\_timers is not connect to screen or object. Timers is based on time and callback func.
