How to set the title for a window which is created by copying from another window?


I failed to set title of a window by using lv_win_set_title API.

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

Windows PC Simulation.

What LVGL version are you using?


What do you want to achieve?

I want to set the title for a window which is created by copying from another window.

What have you tried so far?

I have created a window and setup its style, size, etc. And I had tried to create a new window copy the whole setting from the old window. However, I find out I can not set the title for the new window if I create this new window by copying from another window…

Code to reproduce

void create_pos_window(){
    /* Create container */
    pos_windows_container = lv_cont_create(lv_scr_act(), NULL);
    lv_cont_set_fit(pos_windows_container, LV_FIT_TIGHT);
    lv_cont_set_layout(pos_windows_container, LV_LAYOUT_ROW_MID);
    lv_obj_align(pos_windows_container, NULL, LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_auto_realign(pos_windows_container, true);

    lv_obj_set_style_local_border_width(pos_windows_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 3);
    lv_obj_set_style_local_border_opa(pos_windows_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_100);
    lv_obj_set_style_local_border_color(pos_windows_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
    lv_obj_set_style_local_bg_color(pos_windows_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
    lv_obj_set_style_local_bg_opa(pos_windows_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_100);

    /* Create first window */
    work_pos_win = lv_win_create(pos_windows_container, NULL);
    lv_obj_set_size(work_pos_win, 180, 200);
    lv_win_set_title(work_pos_win, "window 1");
    lv_win_title_set_alignment(work_pos_win, LV_TXT_FLAG_CENTER);
    lv_win_set_header_height(work_pos_win, 40);

    /* window background style */
    static lv_style_t win_bg_style;
    lv_style_set_bg_color(&win_bg_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_style_set_pad_all(&win_bg_style, LV_STATE_DEFAULT, 0);
    lv_obj_add_style(work_pos_win, LV_WIN_PART_BG, &win_bg_style);

    /* window header style */
    static lv_style_t win_header_style;
    lv_style_set_bg_color(&win_header_style, LV_STATE_DEFAULT, LV_COLOR_MAKE(223, 223, 223));
    lv_obj_add_style(work_pos_win, LV_WIN_PART_HEADER, &win_header_style);
    /* Create second window */
    absolute_pos_win = lv_win_create(pos_windows_container, work_pos_win);
    lv_win_set_title(absolute_pos_win, "window 2");

Screenshot and/or video

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