How to align buttons to the bottom of a window?

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the FAQ and read the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

I’m Sorry for my poor English.
I want to align two buttons to the buttom of a window, one in the left and the another in the right, but it doesn’t work. But it performs well if i set the lv_scr_act() as the parent and align the buttons to the lv_scr_act(). Is there anything that i missed?

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

PC Simulator

What LVGL version are you using?

LVGL 7.4

What do you want to achieve?

align buttons to the bottom of a window like it proforms when align them to the bottom of the screen

What have you tried so far?

lv_obj_add_protect(obj, LV_PROTECT_POS);
lv_obj_align();
lv_obj_set_pos();

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/
lv_obj_t* win = lv_win_create(lv_scr_act(), NULL);
lv_obj_t* btn1 = lv_btn_create(win, NULL);
lv_obj_add_protect(btn1, LV_PROTECT_POS);
lv_obj_t* btn2 = lv_btn_create(win, NULL);
lv_obj_add_protect(btn2, LV_PROTECT_POS);
lv_obj_align(btn1, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_obj_align(btn2, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);

Screenshot and/or video

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


problem has been solved by set pad :
lv_style_set_pad_inner(win_style, LV_STATE_DEFAULT, 0);
lv_style_set_pad_left(win_style, LV_STATE_DEFAULT, 0);
lv_style_set_pad_right(win_style, LV_STATE_DEFAULT, 0);
lv_style_set_pad_top(win_style, LV_STATE_DEFAULT, 0);
lv_style_set_pad_bottom(win_style, LV_STATE_DEFAULT, 0);
lv_obj_add_style(win, LV_WIN_PART_CONTENT_SCROLLABLE, win_style);

1 Like

Great that you have found a solution.

If you are at the beginning of a project, I suggest updating to v8. These things are much simpler and more intuitive there :slight_smile: