Skip to content

Compilation error in lv_obj_get_style_opa() #861

@gwiethaus

Description

@gwiethaus

Describe the bug
Compilation error in lv_obj_get_style_opa()

Desktop (please complete the following information)

  • OS: Windows
  • Version 10

LVGL version (if used)

  • 9.3.0
  • 9.4.0

Resources version

  • esptool.py v4.9.0
  • EEZ Studio v0.24.0
  • Visual Studio Code v1.105.1
  • Platformio v3.3.4

Additional context

Platformio.ini


[env:esp32-s3-devkitc1-n16r8]
platform = espressif32
board = esp32-s3-devkitc1-n16r8
framework = arduino

upload_port = COM4
upload_speed = 115200
monitor_port = COM4
monitor_speed = 115200
monitor_filters = log2file
lib_deps = 
	${PROJECT_LIBDEPS_DIR}
	${PROJECT_LIB_DIR}
lib_extra_dirs = lib

[env]
build_unflags = -fpermissive

build_flags = 
	-D LV_LVGL_H_INCLUDE_SIMPLE
	-I ./include
	-I ./lib
	-I config
	-I src
	-fpermissive

Fragments of the code generated by EEZ Studio

eez_flow.cpp

...
ACTION_START(objGetStyleOpa)
    WIDGET_PROP(obj);
    int32_t opa = (int32_t)lv_obj_get_style_opa(obj, 0);
    RESULT(result, Value((int)opa, VALUE_TYPE_INT32));
ACTION_END
...
...
namespace flow {
static void anim_callback_set_x(void *obj, int32_t v) { lv_obj_set_x((lv_obj_t *)obj, v); }
static int32_t anim_callback_get_x(lv_anim_t * a) { return lv_obj_get_x_aligned((lv_obj_t *)a->user_data); }
static void anim_callback_set_y(void *obj, int32_t v) { lv_obj_set_y((lv_obj_t *)obj, v); }
static int32_t anim_callback_get_y(lv_anim_t * a) { return lv_obj_get_y_aligned((lv_obj_t *)a->user_data); }
static void anim_callback_set_width(void *obj, int32_t v) { lv_obj_set_width((lv_obj_t *)obj, v); }
static int32_t anim_callback_get_width(lv_anim_t * a) { return lv_obj_get_width((lv_obj_t *)a->user_data); }
static void anim_callback_set_height(void *obj, int32_t v) { lv_obj_set_height((lv_obj_t *)obj, v); }
static int32_t anim_callback_get_height(lv_anim_t * a) { return lv_obj_get_height((lv_obj_t *)a->user_data); }
static void anim_callback_set_opacity(void *obj, int32_t v) { lv_obj_set_style_opa((lv_obj_t *)obj, v, 0); }
static int32_t anim_callback_get_opacity(lv_anim_t * a) { return lv_obj_get_style_opa((lv_obj_t *)a->user_data, 0); }
static void anim_callback_set_image_zoom(void *obj, int32_t v) { lv_img_set_zoom((lv_obj_t *)obj, v); }
static int32_t anim_callback_get_image_zoom(lv_anim_t * a) { return lv_img_get_zoom((lv_obj_t *)a->user_data); }
static void anim_callback_set_image_angle(void *obj, int32_t v) { lv_img_set_angle((lv_obj_t *)obj, v); }
static int32_t anim_callback_get_image_angle(lv_anim_t * a) { return lv_img_get_angle((lv_obj_t *)a->user_data); }
...

Coimpilation Error message

...
src/ui/eez-flow.cpp: In function 'int32_t eez::flow::anim_callback_get_opacity(lv_anim_t*)':
src/ui/eez-flow.cpp:3837:113: error: invalid conversion from 'int' to 'lv_part_t' [-fpermissive]
 static int32_t anim_callback_get_opacity(lv_anim_t * a) { return lv_obj_get_style_opa((lv_obj_t *)a->user_data, 0); }
                                                                                                                 ^
In file included from lib/lvgl/src/core/lv_obj_style.h:262,
                 from lib/lvgl/src/core/lv_obj.h:27,
                 from lib/lvgl/lvgl.h:44,
                 from src/ui/eez-flow.h:19,
                 from src/ui/eez-flow.cpp:11:
lib/lvgl/src/core/lv_obj_style_gen.h:628:77: note:   initializing argument 2 of 'lv_opa_t lv_obj_get_style_opa(const lv_obj_t*, lv_part_t)'   
 static inline lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, lv_part_t part)
                                                                   ~~~~~~~~~~^~~~
src/ui/eez-flow.cpp: In function 'void eez::flow::objGetStyleOpa(eez::flow::FlowState*, unsigned int, const eez::ListOfAssetsPtr<eez::Property>&, uint32_t)':
src/ui/eez-flow.cpp:4404:54: error: invalid conversion from 'int' to 'lv_part_t' [-fpermissive]
     int32_t opa = (int32_t)lv_obj_get_style_opa(obj, 0);
                                                      ^
In file included from lib/lvgl/src/core/lv_obj_style.h:262,
                 from lib/lvgl/src/core/lv_obj.h:27,
                 from lib/lvgl/lvgl.h:44,
                 from src/ui/eez-flow.h:19,
                 from src/ui/eez-flow.cpp:11:
lib/lvgl/src/core/lv_obj_style_gen.h:628:77: note:   initializing argument 2 of 'lv_opa_t lv_obj_get_style_opa(const lv_obj_t*, lv_part_t)'   
 static inline lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, lv_part_t part)
....

possible solution to the problem

lv_obj_sytle.h

typedef enum {
    LV_PART_MAIN         = 0x000000,  /**< A background like rectangle*/
    LV_PART_SCROLLBAR    = 0x010000,  /**< The scrollbar(s)*/
    LV_PART_INDICATOR    = 0x020000,  /**< Indicator, e.g. for slider, bar, switch, or the tick box of the checkbox*/
    LV_PART_KNOB         = 0x030000,  /**< Like handle to grab to adjust the value*/
    LV_PART_SELECTED     = 0x040000,  /**< Indicate the currently selected option or section*/
    LV_PART_ITEMS        = 0x050000,  /**< Used if the widget has multiple similar elements (e.g. table cells)*/
    LV_PART_CURSOR       = 0x060000,  /**< Mark a specific place e.g. for text area's cursor or on a chart*/

    LV_PART_CUSTOM_FIRST = 0x080000,  /**< Extension point for custom widgets*/

    LV_PART_ANY          = 0x0F0000,  /**< Special value can be used in some functions to target all parts*/
} lv_part_t;

lv_obj_style_gen.h

...
static inline lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, lv_part_t part)
{
    lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OPA);
    return (lv_opa_t)v.num;
}

Replace all 0s or 1s passed to functions that now require lv_part_t or lv_state_t with the correct enum (LV_PART_MAIN, LV_STATE_DEFAULT, etc.).

// Now (LVGL 9.x)
int32_t opa = lv_obj_get_style_opa(obj, LV_PART_MAIN); // correct, type lv_part_t

In the previous LVGL 9.4 version, several functions changed their signatures to use stronger types, such as enums (lv_part_t, lv_state_t) instead of raw int.

As a result, code that previously compiled with a literal 0 now generates a conversion error in strict C++.

Correction:

Replace:

int32_t opa = (int32_t)lv_obj_get_style_opa(obj, 0);

static int32_t anim_callback_get_opacity(lv_anim_t * a) { return lv_obj_get_style_opa((lv_obj_t *)a->user_data, 0); }

Put:

int32_t opa = (int32_t)lv_obj_get_style_opa(obj, LV_PART_MAIN);

static int32_t anim_callback_get_opacity(lv_anim_t * a) { return lv_obj_get_style_opa((lv_obj_t *)a->user_data, LV_PART_MAIN); }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions