fix(dropdown): automatically center dropdown content (#6881)
@ -862,7 +862,6 @@ static void draw_main(lv_event_t * e)
|
|||||||
int32_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
|
int32_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
|
||||||
int32_t left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN) + border_width;
|
int32_t left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN) + border_width;
|
||||||
int32_t right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN) + border_width;
|
int32_t right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN) + border_width;
|
||||||
int32_t top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN) + border_width;
|
|
||||||
|
|
||||||
lv_draw_label_dsc_t symbol_dsc;
|
lv_draw_label_dsc_t symbol_dsc;
|
||||||
lv_draw_label_dsc_init(&symbol_dsc);
|
lv_draw_label_dsc_init(&symbol_dsc);
|
||||||
@ -906,24 +905,22 @@ static void draw_main(lv_event_t * e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
lv_area_t symbol_area;
|
lv_area_t symbol_area;
|
||||||
|
symbol_area.y1 = obj->coords.y1;
|
||||||
|
symbol_area.y2 = symbol_area.y1 + symbol_h - 1;
|
||||||
|
symbol_area.x1 = obj->coords.x1;
|
||||||
|
symbol_area.x2 = symbol_area.x1 + symbol_w - 1;
|
||||||
if(symbol_to_left) {
|
if(symbol_to_left) {
|
||||||
symbol_area.x1 = obj->coords.x1 + left;
|
lv_area_align(&obj->coords, &symbol_area, LV_ALIGN_LEFT_MID, left, 0);
|
||||||
symbol_area.x2 = symbol_area.x1 + symbol_w - 1;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
symbol_area.x1 = obj->coords.x2 - right - symbol_w;
|
lv_area_align(&obj->coords, &symbol_area, LV_ALIGN_RIGHT_MID, -right, 0);
|
||||||
symbol_area.x2 = symbol_area.x1 + symbol_w - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(symbol_type == LV_IMAGE_SRC_SYMBOL) {
|
if(symbol_type == LV_IMAGE_SRC_SYMBOL) {
|
||||||
symbol_area.y1 = obj->coords.y1 + top;
|
|
||||||
symbol_area.y2 = symbol_area.y1 + symbol_h - 1;
|
|
||||||
symbol_dsc.text = dropdown->symbol;
|
symbol_dsc.text = dropdown->symbol;
|
||||||
lv_draw_label(layer, &symbol_dsc, &symbol_area);
|
lv_draw_label(layer, &symbol_dsc, &symbol_area);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
symbol_area.y1 = obj->coords.y1 + (lv_obj_get_height(obj) - symbol_h) / 2;
|
|
||||||
symbol_area.y2 = symbol_area.y1 + symbol_h - 1;
|
|
||||||
lv_draw_image_dsc_t img_dsc;
|
lv_draw_image_dsc_t img_dsc;
|
||||||
lv_draw_image_dsc_init(&img_dsc);
|
lv_draw_image_dsc_init(&img_dsc);
|
||||||
lv_obj_init_draw_image_dsc(obj, LV_PART_INDICATOR, &img_dsc);
|
lv_obj_init_draw_image_dsc(obj, LV_PART_INDICATOR, &img_dsc);
|
||||||
@ -943,22 +940,21 @@ static void draw_main(lv_event_t * e)
|
|||||||
label_dsc.flag);
|
label_dsc.flag);
|
||||||
|
|
||||||
lv_area_t txt_area;
|
lv_area_t txt_area;
|
||||||
txt_area.y1 = obj->coords.y1 + top;
|
txt_area.x1 = obj->coords.x1;
|
||||||
txt_area.y2 = txt_area.y1 + size.y;
|
txt_area.x2 = txt_area.x1 + size.x - 1;
|
||||||
|
txt_area.y1 = obj->coords.y1;
|
||||||
|
txt_area.y2 = txt_area.y1 + size.y - 1;
|
||||||
/*Center align the text if no symbol*/
|
/*Center align the text if no symbol*/
|
||||||
if(dropdown->symbol == NULL) {
|
if(dropdown->symbol == NULL) {
|
||||||
txt_area.x1 = obj->coords.x1 + (lv_obj_get_width(obj) - size.x) / 2;
|
lv_area_align(&obj->coords, &txt_area, LV_ALIGN_CENTER, 0, 0);
|
||||||
txt_area.x2 = txt_area.x1 + size.x;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/*Text to the right*/
|
/*Text to the right*/
|
||||||
if(symbol_to_left) {
|
if(symbol_to_left) {
|
||||||
txt_area.x1 = obj->coords.x2 - right - size.x;
|
lv_area_align(&obj->coords, &txt_area, LV_ALIGN_RIGHT_MID, -right, 0);
|
||||||
txt_area.x2 = txt_area.x1 + size.x;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
txt_area.x1 = obj->coords.x1 + left;
|
lv_area_align(&obj->coords, &txt_area, LV_ALIGN_LEFT_MID, left, 0);
|
||||||
txt_area.x2 = txt_area.x1 + size.x;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
@ -381,6 +381,7 @@ void test_dropdown_render_2(void)
|
|||||||
lv_dropdown_open(dd2);
|
lv_dropdown_open(dd2);
|
||||||
|
|
||||||
lv_obj_t * dd3 = lv_dropdown_create(lv_screen_active());
|
lv_obj_t * dd3 = lv_dropdown_create(lv_screen_active());
|
||||||
|
lv_obj_set_height(dd3, 70);
|
||||||
lv_dropdown_set_text(dd3, "Limit Down");
|
lv_dropdown_set_text(dd3, "Limit Down");
|
||||||
lv_dropdown_set_options(dd3, "1aaaaaaaaaaaaaaaa\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15");
|
lv_dropdown_set_options(dd3, "1aaaaaaaaaaaaaaaa\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15");
|
||||||
lv_obj_align(dd3, LV_ALIGN_LEFT_MID, 300, -10);
|
lv_obj_align(dd3, LV_ALIGN_LEFT_MID, 300, -10);
|
||||||
|