8000 [lv_prop_id_t]: Correct LV_PROPERTY_ID_TYPE2 and LV_PROPERTY_ID_INDEX macro for paired properties · Issue #10981 · lvgl/lvgl · GitHub
[go: up one dir, main page]

Skip to content

[lv_prop_id_t]: Correct LV_PROPERTY_ID_TYPE2 and LV_PROPERTY_ID_INDEX macro for paired properties #10981

Open

Description

@fvanroie

Summary

LV_PROPERTY_ID_TYPE2 extracts the wrong bits and LV_PROPERTY_ID_INDEX includes TYPE2 for paired properties

LVGL version

v9.6.0

Platform

ESP32 / ESP-IDF 6.1.0 embedded project, using C++.

Compiler: GCC (ESP-IDF toolchain).

Configuration:

LV_USE_OBJ_PROPERTY = 1
LV_USE_OBJ_PROPERTY_NAME = 1

What happened?

The property ID decoding macros appear to be inconsistent with the documented encoding of LV_PROPERTY_ID2.

According to the documentation:

  • LV_PROPERTY_ID:
       - Bits 31–28: property value type.
       - Bits 27–0: property index.
    
  • LV_PROPERTY_ID2:
       - Bits 31–28: first argument type.
       - Bits 27–24: second argument type.
       - Bits 23–0: property index.
    

However, the current macros are:

#define LV_PROPERTY_ID_TYPE(id)  ((id) >> LV_PROPERTY_TYPE_SHIFT)
#define LV_PROPERTY_ID_TYPE2(id) ((id) >> LV_PROPERTY_TYPE_SHIFT)
#define LV_PROPERTY_ID_INDEX(id) ((id) & 0xfffffff)

LV_PROPERTY_ID_TYPE2 uses LV_PROPERTY_TYPE_SHIFT (28) instead of LV_PROPERTY_TYPE2_SHIFT (24), meaning it extracts the first argument type again rather than the second.

Additionally, LV_PROPERTY_ID_INDEX masks 28 bits, which includes the TYPE2 field for paired properties instead of extracting only bits 23–0.

I verified this at runtime using lv_obj_property_get_id() on actual LVGL widget instances.

The results were:

Property Encoded ID Expected TYPE2 Current TYPE2 Correct TYPE2
slider.value 0x1B000800 11 1 11
slider.left_value 0x1B000801 11 1 11
slider.range 0x11000802 1 1 1
animimage.src 0x51000900 1 5 1
roller.options 0x71000600 1 7 1
roller.selected 0x11000601 1 1 1

I independently verified TYPE2 using:

#define MY_PROPERTY_ID_TYPE2(id) \
    (((id) >> LV_PROPERTY_TYPE2_SHIFT) & 0x0F)

This correctly extracts the second argument type for all six properties.

The existing index macro also produces incorrect results for paired properties:

slider.value:
    LV_PROPERTY_ID_INDEX(id) = 0x0B000800
    Expected paired index    = 0x000800

What did you expect to happen?

The decoding macros should follow the documented bit layout.

For example:

#define LV_PROPERTY_ID_TYPE(id) \
    (((id) >> LV_PROPERTY_TYPE_SHIFT) & 0x0F)

#define LV_PROPERTY_ID_TYPE2(id) \
    (((id) >> LV_PROPERTY_TYPE2_SHIFT) & 0x0F)

For the property index, paired properties should extract only the lower 24 bits:

#define LV_PROPERTY_ID_INDEX2(id) \
    ((id) & 0x00FFFFFF)

Single-value properties retain their documented 28-bit index.

I think the existing LV_PROPERTY_ID_INDEX usage should be reviewed to ensure that paired IDs are decoded correctly without changing the semantics of single-value IDs.

How to reproduce?

Create instances of a slider, animimage and roller, then retrieve their property IDs:

lv_obj_t *slider = lv_slider_create(lv_screen_active());
lv_obj_t *animimage = lv_animimg_create(lv_screen_active());
lv_obj_t *roller = lv_roller_create(lv_screen_active());

lv_prop_id_t ids[] = {
    lv_obj_property_get_id(slider, "value"),
    lv_obj_property_get_id(slider, "left_value"),
    lv_obj_property_get_id(slider, "range"),
    lv_obj_property_get_id(animimage, "src"),
    lv_obj_property_get_id(roller, "options"),
    lv_obj_property_get_id(roller, "selected")
};

for (size_t i = 0; i < sizeof(ids) / sizeof(ids[0]); i++) {
    lv_prop_id_t id = ids[i];

    printf("ID: 0x%08X\n", (unsigned int)id);
    printf("TYPE: %u\n", (unsigned int)LV_PROPERTY_ID_TYPE(id));
    printf("TYPE2: %u\n", (unsigned int)LV_PROPERTY_ID_TYPE2(id));
    printf("INDEX: 0x%07X\n", (unsigned int)LV_PROPERTY_ID_INDEX(id));
    printf("INDEX24: 0x%06X\n", (unsigned int)(id & 0x00FFFFFF));
}

Output:

ID: 0x1B000800
TYPE: 1
TYPE2: 1
INDEX: 0xB000800
INDEX24: 0x000800
ID: 0x1B000801
TYPE: 1
TYPE2: 1
INDEX: 0xB000801
INDEX24: 0x000801
ID: 0x11000802
TYPE: 1
TYPE2: 1
INDEX: 0x1000802
INDEX24: 0x000802
ID: 0x51000900
TYPE: 5
TYPE2: 5
INDEX: 0x1000900
INDEX24: 0x000900
ID: 0x71000600
TYPE: 7
TYPE2: 7
INDEX: 0x1000600
INDEX24: 0x000600
ID: 0x11000601
TYPE: 1
TYPE2: 1
INDEX: 0x1000601
INDEX24: 0x000601

Compare the results against the documented LV_PROPERTY_ID2 bit layout. TYPE2 reports the value of TYPE1...

The discrepancy is reproducible with the existing LVGL property definitions and does not require custom property registration.

Activity

  1. changed the title [-]LV_PROPERTY_ID_TYPE2 extracts the wrong bits and LV_PROPERTY_ID_INDEX includes TYPE2 for paired properties[/-] [+][lv_prop_id_t]: Correct LV_PROPERTY_ID_TYPE2 and LV_PROPERTY_ID_INDEX macro for paired properties[/+] on Nov 10, 2026
  2. Wooohaaa commented on Nov 11, 2026

    @Wooohaaa

    A fix is up in #10984.

    LV_PROPERTY_ID_TYPE2() now decodes bits 27:24 as documented, instead of reusing LV_PROPERTY_TYPE_SHIFT (it was literally identical to LV_PROPERTY_ID_TYPE()). It drives the setter dispatch in lv_obj_property.c, so this also fixes which arg2 type is passed to a two-argument setter (for example ROLLER_OPTIONS was going through the pointer variant and SLIDER_VALUE through the integer one). A regression test asserts the decoded TYPE/TYPE2; it fails before the change and passes after.

    On LV_PROPERTY_ID_INDEX(): masking it down to 24 bits would truncate the 28-bit index of a single-valued LV_PROPERTY_ID, and the two layouts cannot be told apart from the value alone, so it keeps the low 28 bits of LV_PROPERTY_ID. For a paired LV_PROPERTY_ID2 the index is its low 24 bits (mask with 0xffffff once LV_PROPERTY_ID_TYPE2() says the id is paired); that is now documented next to the macro.

  3. fvanroie commented on Nov 11, 2026

    @fvanroie
    ContributorAuthor

    Thank you for your prompt response, testing and fix!

    One small follow-up thought: would it make sense to introduce an LV_PROPERTY_ID_INDEX2() macro for paired properties?

    LV_PROPERTY_ID_INDEX() extracts 28 bits, whereas paired IDs use bits 27:24 for TYPE2, leaving only 24 bits for the index.

    Having separate macros would make the distinction explicit and avoid callers accidentally treating TYPE2 as part of the index.

    Not necessarily something that needs to be addressed in this fix, just a thought for API consistency.

    I'm coming from LVGL v7, so I'm still getting my head around the Widget Properties API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0