How to customize widget


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


What LVGL version are you using?


What do you want to achieve?

port the v7.11 to v8.2.0

What have you tried so far?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

Hi, Team @kisvegabor ,@embeddedt, @pete-pjb,
I am porting the old version v7.11 to v8.2.0. There have some customized widget in my project and were implemented as your old guide like the below and it works.
my_btn_ancestor_design= lv_obj_get_design_cb(btn_my)
lv_obj_set_design_cb(btn_my, my_btn_design);
lv_obj_set_signal_cb(btn_my, my_btn_signal);

But for v8.2.0, all drawing and signaling cb were changed to event cb and need to modfify them.
I want to implement the function as below:

  1. keep using the default drawing and signaling cb, just add some customized drawing or signaling on it.
  2. replace the default with my own drawing and signaling cb.

Is there any document or example now? Would like to have your help!

Best Regards,

As you’ve noted, objects now use event handlers for their own built-in logic as well. So…

If it’s a minor augmentation to the widget’s exist behavior, you can just add another event handler using lv_obj_add_event_cb and listen to the appropriate event that the widget itself does.

For this, you can use the class system to create your own widget that “extends” a built-in one. You can replace the built-in widget’s event handler by using the event_cb field on the class.

The button is a good example of how to get started with your own class, as it’s just a wrapper around the base object.

For an example of using a custom event handler, look at the checkbox. The file looks long, but most of it is just the drawing logic; the actual event logic is quite straightforward.

1 Like

Many Thanks!
I am working on it.
What is the purpose of the event sent below?
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc);
lv_draw_rect(draw_ctx, &indic_dsc, &marker_area_transf);
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc);

Best Regards,