mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
btnm, tabview: revers the button/tab order with RTL base dir
This commit is contained in:
parent
06746dfd63
commit
54e34c15b9
@ -207,6 +207,8 @@ void lv_btnm_set_map(const lv_obj_t * btnm, const char * map[])
|
||||
btn_h = lv_obj_get_height(btnm)- act_y - style_bg->body.padding.bottom - 1;
|
||||
}
|
||||
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(btnm);
|
||||
|
||||
/*Only deal with the non empty lines*/
|
||||
if(btn_cnt != 0) {
|
||||
/*Calculate the width of all units*/
|
||||
@ -214,7 +216,8 @@ void lv_btnm_set_map(const lv_obj_t * btnm, const char * map[])
|
||||
|
||||
/*Set the button size and positions and set the texts*/
|
||||
uint16_t i;
|
||||
lv_coord_t act_x = style_bg->body.padding.left;
|
||||
lv_coord_t act_x;
|
||||
|
||||
lv_coord_t act_unit_w;
|
||||
unit_act_cnt = 0;
|
||||
for(i = 0; i < btn_cnt; i++) {
|
||||
@ -225,9 +228,13 @@ void lv_btnm_set_map(const lv_obj_t * btnm, const char * map[])
|
||||
act_unit_w--; /*-1 because e.g. width = 100 means 101 pixels (0..100)*/
|
||||
|
||||
/*Always recalculate act_x because of rounding errors */
|
||||
if(base_dir == LV_BIDI_DIR_RTL) {
|
||||
act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * style_bg->body.padding.inner;
|
||||
act_x = lv_obj_get_width(btnm) - style_bg->body.padding.right - act_x - act_unit_w - 1;
|
||||
} else {
|
||||
act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * style_bg->body.padding.inner +
|
||||
style_bg->body.padding.left;
|
||||
|
||||
}
|
||||
/* Set the button's area.
|
||||
* If inner padding is zero then use the prev. button x2 as x1 to avoid rounding
|
||||
* errors*/
|
||||
|
@ -113,6 +113,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
lv_obj_set_drag(scrl, false);
|
||||
lv_page_set_scrl_fit2(new_ddlist, LV_FIT_FILL, LV_FIT_TIGHT);
|
||||
|
||||
/*Save (a later restore) the original X coordinate because it changes as the FITs applies*/
|
||||
lv_coord_t x;
|
||||
if(lv_obj_get_base_dir(new_ddlist) == LV_BIDI_DIR_RTL) x = lv_obj_get_x(new_ddlist) + lv_obj_get_width(new_ddlist);
|
||||
else x = lv_obj_get_x(new_ddlist);
|
||||
@ -124,7 +125,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
|
||||
lv_ddlist_set_options(new_ddlist, "Option 1\nOption 2\nOption 3");
|
||||
|
||||
|
||||
/*Restore the original X coordinate*/
|
||||
if(lv_obj_get_base_dir(new_ddlist) == LV_BIDI_DIR_RTL) lv_obj_set_x(new_ddlist, x - lv_obj_get_width(new_ddlist));
|
||||
else lv_obj_set_x(new_ddlist, x);
|
||||
|
||||
|
@ -131,6 +131,7 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
lv_obj_set_event_cb(new_kb, lv_kb_def_event_cb);
|
||||
lv_btnm_set_map(new_kb, kb_map_lc);
|
||||
lv_btnm_set_ctrl_map(new_kb, kb_ctrl_lc_map);
|
||||
lv_obj_set_base_dir(new_kb, LV_BIDI_DIR_LTR);
|
||||
|
||||
/*Set the default styles*/
|
||||
lv_theme_t * th = lv_theme_get_current();
|
||||
|
@ -351,6 +351,10 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t an
|
||||
|
||||
ext->tab_cur = id;
|
||||
|
||||
if(lv_obj_get_base_dir(tabview) == LV_BIDI_DIR_RTL) {
|
||||
id = (ext->tab_cnt - (id + 1));
|
||||
}
|
||||
|
||||
lv_coord_t cont_x;
|
||||
|
||||
switch(ext->btns_pos) {
|
||||
@ -400,13 +404,7 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t an
|
||||
case LV_TABVIEW_BTNS_POS_TOP:
|
||||
case LV_TABVIEW_BTNS_POS_BOTTOM:
|
||||
indic_size = lv_obj_get_width(ext->indic);
|
||||
if(lv_obj_get_base_dir(tabview) == LV_BIDI_DIR_RTL) {
|
||||
uint16_t id_rtl = (ext->tab_cnt - (id + 1));
|
||||
printf("id:%d, id_Rtl:%d\n", id, id_rtl);
|
||||
indic_pos = indic_size * id_rtl + tabs_style->body.padding.inner * id_rtl + tabs_style->body.padding.left;
|
||||
} else {
|
||||
indic_pos = indic_size * id + tabs_style->body.padding.inner * id + tabs_style->body.padding.left;
|
||||
}
|
||||
break;
|
||||
case LV_TABVIEW_BTNS_POS_LEFT:
|
||||
case LV_TABVIEW_BTNS_POS_RIGHT:
|
||||
@ -911,7 +909,11 @@ static void tabpage_pressing_handler(lv_obj_t * tabview, lv_obj_t * tabpage)
|
||||
p = ((tabpage->coords.x1 - tabview->coords.x1) * (indic_size + tabs_style->body.padding.inner)) /
|
||||
lv_obj_get_width(tabview);
|
||||
|
||||
lv_obj_set_x(ext->indic, indic_size * ext->tab_cur + tabs_style->body.padding.inner * ext->tab_cur +
|
||||
uint16_t id = ext->tab_cur;
|
||||
if(lv_obj_get_base_dir(tabview) == LV_BIDI_DIR_RTL) {
|
||||
id = (ext->tab_cnt - (id + 1));
|
||||
}
|
||||
lv_obj_set_x(ext->indic, indic_size * id + tabs_style->body.padding.inner * id +
|
||||
indic_style->body.padding.left - p);
|
||||
break;
|
||||
case LV_TABVIEW_BTNS_POS_LEFT:
|
||||
@ -954,13 +956,18 @@ static void tabpage_press_lost_handler(lv_obj_t * tabview, lv_obj_t * tabpage)
|
||||
lv_coord_t page_x2 = page_x1 + lv_obj_get_width(tabpage);
|
||||
lv_coord_t treshold = lv_obj_get_width(tabview) / 2;
|
||||
|
||||
uint16_t tab_cur = ext->tab_cur;
|
||||
int16_t tab_cur = ext->tab_cur;
|
||||
if(page_x1 > treshold) {
|
||||
if(tab_cur != 0) tab_cur--;
|
||||
if(lv_obj_get_base_dir(tabview) == LV_BIDI_DIR_RTL) tab_cur++;
|
||||
else tab_cur--;
|
||||
} else if(page_x2 < treshold) {
|
||||
if(tab_cur < ext->tab_cnt - 1) tab_cur++;
|
||||
if(lv_obj_get_base_dir(tabview) == LV_BIDI_DIR_RTL) tab_cur--;
|
||||
else tab_cur++;
|
||||
}
|
||||
|
||||
if(tab_cur > ext->tab_cnt - 1) tab_cur = ext->tab_cnt - 1;
|
||||
else if(tab_cur < 0) tab_cur = 0;
|
||||
|
||||
uint32_t id_prev = lv_tabview_get_tab_act(tabview);
|
||||
lv_tabview_set_tab_act(tabview, tab_cur, LV_ANIM_ON);
|
||||
uint32_t id_new = lv_tabview_get_tab_act(tabview);
|
||||
|
Loading…
x
Reference in New Issue
Block a user