How to access a container object's properties from other external object

Before posting

Hello

Description

access a container object’s properties from other external (container OFF) object

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

STM32F767

What LVGL version are you using?

7.10.0-dev

What do you want to achieve?

i need to access and change some object settings from a button in tab2 TO tab1, i wrote a simple sample what i want to do.
How can i do it?

What have you tried so far?

finding children and so on but nothing happend

Code to reproduce

LV_IMG_DECLARE(img_cogwheel_argb);

//------------------------------------------------------------------------
void tab1_draw(lv_obj_t *parentX)
{
    lv_obj_t * cont;
    lv_obj_t * label;
    lv_obj_t * img;
    static lv_style_t style_Text;
    static lv_style_t style_Container;
    static lv_style_t style_Image;

    cont = lv_cont_create(parentX, NULL);
    lv_style_init(&style_Container);
    lv_style_set_bg_color(&style_Container, LV_STATE_DEFAULT, LV_COLOR_SILVER);
    lv_obj_add_style(cont, LV_OBJ_PART_MAIN, &style_Container);
    lv_obj_set_pos(cont, 500, 100);
    lv_obj_set_size(cont, 200, 200);


    label = lv_label_create(cont, NULL);
    lv_style_init(&style_Text);
    lv_style_set_text_color(&style_Text, LV_STATE_DEFAULT, LV_COLOR_RED);
    lv_obj_add_style(label, LV_OBJ_PART_MAIN, &style_Text);
    lv_label_set_text(label, "Hello");
    lv_obj_set_pos(label, 10, 10);

    img = lv_img_create(cont, NULL);
    lv_img_set_src(img, &img_cogwheel_argb);
    lv_obj_align(img, NULL, LV_ALIGN_CENTER, 0, -20);
    lv_style_init(&style_Image);
    lv_style_set_image_recolor(&style_Image, LV_STATE_DEFAULT, LV_COLOR_CYAN);
    lv_style_set_image_recolor_opa(&style_Image, LV_STATE_DEFAULT, LV_OPA_50);
    lv_obj_add_style(img, LV_OBJ_PART_MAIN, &style_Image);
}

//------------------------------------------------------------------------
void tab2_draw(lv_obj_t *parentX)
{ 
    lv_obj_t * label;
    label = lv_label_create(parentX, NULL);
    lv_label_set_text(label, "from here i need to \n  *change tab1/container/label TEXT and STYLE \n    **change tab1/container/img COLOR \n        ***change tab1/container bg_color");
    lv_obj_set_pos(label, 100, 100);

//HERE i want to change label TEXT "Hello" in tab1 to "OK"  <<<<<<<<<<<<<<
}
//------------------------------------------------------------------------
void TAB(void) 
{
    lv_obj_t * TAB;
    lv_obj_t * tab1;
    lv_obj_t * tab2;
    lv_obj_t * tab3;

    TAB = lv_tabview_create(lv_scr_act(), NULL);

    tab1 = lv_tabview_add_tab(TAB, "tab1");
    tab2 = lv_tabview_add_tab(TAB, "tab2");
    tab3 = lv_tabview_add_tab(TAB, "tab3");

    tab1_draw(tab1);
    tab2_draw(tab2);
}

//------------------------------------------------------------------------
//------------------------------------------------------------------------
main()
{
  TAB();
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

You can make the objs you want to change in other tabs to global vars.I think it’s the fastest way.

Ok lets say we have the cont and label and img are global, how can change the label text inside the cont?

If you have a global reference to the label object, you just call lv_label_set_text like you normally would.

1 Like

Thank you, also your reply to other topic is more accurate " An alternative approach might be to store object references in an allocated structure and point the user_data pointer of the parent object to that.".