My C++ Wrapper for LVGL

I wrapped my commonly used lv_obj_set interface with C++ (so that my create_ui interface no longer needs to pass a bunch of parameters), while enabling lv_obj and lv_timer to support adding lambda event callbacks.

For example:

auto bg_obj_setter = myui::create_obj_white_bg(lv_screen_active());
bg_obj_setter
    .size(600, 400)
    .center();

auto btn_setter = myui::create_btn(bg_obj_setter.get_obj());
btn_setter
    .get_obj_setter()
    .size(140, 48)
    .center();

auto btn_label_setter = myui::create_label(btn_setter.get_obj());
btn_label_setter
    .text_fmt("hello {}", "world")
    .get_obj_setter()
    .center()
    .get_origin_setter(btn_label_setter)        // just show get_origin_setter usage
    .text_color_hex(0x000000);

See lvw

1 Like

Thanks for sharing!

I hope this can help those who like using C++. By the way, if the event_cb is used only in one place, it’s really satisfying to write the event callback with a lambda.
As for performance, it mostly consists of inline functions and only uses stack memory ,without virtual function tables, so I think the impact is minimal.