Trying to move from LVGL 6 to 7, lots of problems :(

Description

Started a project with LVGL 6; now 7 breaks lots of things in my code and can’t find a tutorial about migrating from 6 to 7

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

Raspberry Pi, Raspberry OS, GCC

What LVGL version are you using?

7.9

What do you want to achieve?

Migrating my GUI from LVGL 6 to 7

What have you tried so far?

Tried to recompile my sources with the new LVGL 7, tons of errors

Code to reproduce

I don’t have a specific snippet; everything which uses a “style” does not compile anymore.
Just asking for a “upgrading to v7: howto” of sort.

Example: a very simple instruction block like this:

static void drawMainLabel(lv_align_t lAlignment, lv_coord_t lCorrectionX, lv_coord_t lCorrectionY)
{   
    lv_obj_t* pLabel;
    static lv_style_t labelStyle;

    pLabel = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_static_text(pLabel, MAIN_LABEL_TEXT);
    LV_FONT_DECLARE(audio_60);
    lv_style_copy(&labelStyle, &lv_style_plain);
    labelStyle.text.color = LV_COLOR_BLUE;
    labelStyle.text.font = &audio_60;
    lv_obj_set_style(pLabel, &labelStyle);
    // NULL = align on parent (the screen)
    lv_obj_align(pLabel, NULL, lAlignment, lCorrectionX, lCorrectionY);
}

does not compile anymore:

error: ‘lv_style_plain’ undeclared (first use in this function)
error: ‘lv_style_t’ {aka ‘struct ’} has no member named ‘text’
warning: implicit declaration of function ‘lv_obj_set_style’

and so on

I understand styles are changed in v7: I’m OK to “port” my code to v7, but I cannot find any guide or tutorial about what to do.

Officially, styles have to be migrated by hand. I would suggest reading through this page for an overview of how they work. That page has a list of all the style properties plus several examples about how to use the new APIs. If you still have questions, ask here. :slightly_smiling_face:

Unofficially, I have made a translation module that allows you to use legacy style syntax. This doesn’t work if you modify the style after it has been translated once, but it might be of use.

Finally, here is an example of how your current function would be written with v7 styles:

static void drawMainLabel(lv_align_t lAlignment, lv_coord_t lCorrectionX, lv_coord_t lCorrectionY)
{   
    lv_obj_t* pLabel;
    /*
     * Note: Styles should *not* be initialized a second time. This will result in memory leaks!
     * Create the style once and use it throughout the project, or use local styles on the label (see below).
     */
    static lv_style_t labelStyle;
    lv_style_init(&labelStyle);

    pLabel = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_static_text(pLabel, MAIN_LABEL_TEXT);
    LV_FONT_DECLARE(audio_60);
    /* lv_style_copy is no longer needed as objects can now have multiple styles applied */
    lv_style_set_text_color(&labelStyle, LV_STATE_DEFAULT, LV_COLOR_BLUE);
    lv_style_set_text_font(&labelStyle,  LV_STATE_DEFAULT, &audio_60);
    lv_obj_add_style(pLabel, LV_LABEL_PART_MAIN, &labelStyle);
    /*
     * To avoid needing to make an lv_style_t object, one can use the label's local style.
     * The code below is a no-op since a style has already been added,
     * but shows the equivalent local style syntax.
     */
    lv_obj_set_style_local_text_color(pLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLUE);
    lv_obj_set_style_local_text_font(pLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &audio_60);
    // NULL = align on parent (the screen)
    lv_obj_align(pLabel, NULL, lAlignment, lCorrectionX, lCorrectionY);
}
1 Like

Great!!
Thank you very much. :+1: