mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
Merge branch 'dev-7.0' of https://github.com/littlevgl/lvgl into dev-7.0
This commit is contained in:
commit
89fd050df1
@ -406,6 +406,7 @@ static void draw_bg(lv_obj_t * bar, const lv_area_t * clip_area)
|
||||
static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(bar);
|
||||
|
||||
lv_coord_t objw = lv_obj_get_width(bar);
|
||||
lv_coord_t objh = lv_obj_get_height(bar);
|
||||
@ -469,7 +470,6 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
|
||||
anim_start_value_x = (((anim_start_value_end_x - anim_start_value_start_x) * ext->start_value_anim.anim_state) /
|
||||
LV_BAR_ANIM_STATE_END);
|
||||
|
||||
if(anim_start_value_end_x < anim_start_value_start_x)
|
||||
anim_start_value_x += anim_start_value_start_x;
|
||||
}
|
||||
else
|
||||
@ -485,11 +485,8 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
|
||||
lv_coord_t anim_cur_value_end_x =
|
||||
(int32_t)((int32_t)anim_length * (ext->cur_value_anim.anim_end - ext->min_value)) / range;
|
||||
|
||||
anim_cur_value_x = (((anim_cur_value_end_x - anim_cur_value_start_x) * ext->cur_value_anim.anim_state) /
|
||||
anim_cur_value_x = anim_cur_value_start_x + (((anim_cur_value_end_x - anim_cur_value_start_x) * ext->cur_value_anim.anim_state) /
|
||||
LV_BAR_ANIM_STATE_END);
|
||||
|
||||
if(anim_cur_value_end_x < anim_cur_value_start_x)
|
||||
anim_cur_value_x += anim_cur_value_start_x;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -497,14 +494,24 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
|
||||
anim_cur_value_x = (int32_t)((int32_t)anim_length * (ext->cur_value - ext->min_value)) / range;
|
||||
}
|
||||
|
||||
if(hor && base_dir == LV_BIDI_DIR_RTL) {
|
||||
/* Swap axes */
|
||||
lv_coord_t * tmp;
|
||||
tmp = axis1;
|
||||
axis1 = axis2;
|
||||
axis2 = tmp;
|
||||
anim_cur_value_x = -anim_cur_value_x;
|
||||
anim_start_value_x = -anim_start_value_x;
|
||||
}
|
||||
|
||||
/* Set the indicator length */
|
||||
if(hor) {
|
||||
*axis2 = *axis1 + anim_cur_value_x;
|
||||
*axis1 += anim_start_value_x;
|
||||
}
|
||||
else {
|
||||
*axis2 -= anim_start_value_x;
|
||||
*axis1 = *axis2 - anim_cur_value_x;
|
||||
*axis2 -= anim_start_value_x;
|
||||
}
|
||||
if(sym) {
|
||||
lv_coord_t zero;
|
||||
@ -719,8 +726,6 @@ static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_
|
||||
lv_anim_set_ready_cb(&a, lv_bar_anim_ready);
|
||||
lv_anim_set_time(&a, ext->anim_time);
|
||||
lv_anim_start(&a);
|
||||
|
||||
ext->cur_value = new_value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,6 +177,26 @@ void lv_dropdown_set_text(lv_obj_t * ddlist, const char * txt)
|
||||
lv_obj_invalidate(ddlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear any options in a drop down list. Static or dynamic.
|
||||
* @param ddlist pointer to drop down list object
|
||||
*/
|
||||
void lv_dropdown_clear_options(lv_obj_t * ddlist)
|
||||
{
|
||||
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
||||
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
if(ext->options == NULL) return;
|
||||
|
||||
if(ext->static_txt == 0)
|
||||
lv_mem_free(ext->options);
|
||||
|
||||
ext->options = NULL;
|
||||
ext->static_txt = 0;
|
||||
ext->option_cnt = 0;
|
||||
|
||||
lv_obj_invalidate(ddlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the options in a drop down list from a string
|
||||
* @param ddlist pointer to drop down list object
|
||||
@ -262,8 +282,18 @@ void lv_dropdown_add_option(lv_obj_t * ddlist, const char * option, uint16_t pos
|
||||
|
||||
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
|
||||
/*Can not append to static options*/
|
||||
if(ext->static_txt != 0) return;
|
||||
/*Convert static options to dynmaic*/
|
||||
if(ext->static_txt != 0) {
|
||||
char * static_options = ext->options;
|
||||
size_t len = strlen(static_options) + 1;
|
||||
|
||||
ext->options = lv_mem_alloc(len);
|
||||
LV_ASSERT_MEM(ext->options);
|
||||
if(ext->options == NULL) return;
|
||||
|
||||
strcpy(ext->options, static_options);
|
||||
ext->static_txt = 0;
|
||||
}
|
||||
|
||||
/*Allocate space for the new option*/
|
||||
size_t old_len = (ext->options == NULL) ? 0 : strlen(ext->options);
|
||||
|
@ -99,6 +99,12 @@ lv_obj_t * lv_dropdown_create(lv_obj_t * par, const lv_obj_t * copy);
|
||||
*/
|
||||
void lv_dropdown_set_text(lv_obj_t * ddlist, const char * txt);
|
||||
|
||||
/**
|
||||
* Clear any options in a drop down list. Static or dynamic.
|
||||
* @param ddlist pointer to drop down list object
|
||||
*/
|
||||
void lv_dropdown_clear_options(lv_obj_t * ddlist);
|
||||
|
||||
/**
|
||||
* Set the options in a drop down list from a string
|
||||
* @param ddlist pointer to drop down list object
|
||||
|
@ -23,6 +23,8 @@
|
||||
*********************/
|
||||
#define LV_OBJX_NAME "lv_slider"
|
||||
|
||||
#define LV_SLIDER_KNOB_COORD(hor, is_rtl, area) (hor ? (is_rtl ? area.x1 : area.x2) : (is_rtl ? area.y1 : area.y2))
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
@ -167,6 +169,7 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli
|
||||
ancestor_design_f(slider, clip_area, mode);
|
||||
|
||||
lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(slider);
|
||||
|
||||
lv_coord_t objw = lv_obj_get_width(slider);
|
||||
lv_coord_t objh = lv_obj_get_height(slider);
|
||||
@ -180,14 +183,14 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli
|
||||
/*Horizontal*/
|
||||
if(hor) {
|
||||
if(!sym) {
|
||||
knob_area.x1 = ext->bar.indic_area.x2;
|
||||
knob_area.x1 = LV_SLIDER_KNOB_COORD(hor, base_dir == LV_BIDI_DIR_RTL, ext->bar.indic_area);
|
||||
}
|
||||
else {
|
||||
if(ext->bar.cur_value >= 0) {
|
||||
knob_area.x1 = ext->bar.indic_area.x2;
|
||||
knob_area.x1 = LV_SLIDER_KNOB_COORD(hor, base_dir == LV_BIDI_DIR_RTL, ext->bar.indic_area);
|
||||
}
|
||||
else {
|
||||
knob_area.x1 = ext->bar.indic_area.x1;
|
||||
knob_area.x1 = LV_SLIDER_KNOB_COORD(hor, base_dir != LV_BIDI_DIR_RTL, ext->bar.indic_area);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -213,10 +216,10 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli
|
||||
if(lv_slider_get_type(slider) == LV_SLIDER_TYPE_RANGE) {
|
||||
/* Draw a second knob for the start_value side */
|
||||
if(hor) {
|
||||
knob_area.x1 = ext->bar.indic_area.x1;
|
||||
knob_area.x1 = LV_SLIDER_KNOB_COORD(hor, base_dir != LV_BIDI_DIR_RTL, ext->bar.indic_area);
|
||||
}
|
||||
else {
|
||||
knob_area.y1 = ext->bar.indic_area.y1;
|
||||
knob_area.y1 = ext->bar.indic_area.y2;
|
||||
}
|
||||
lv_slider_position_knob(slider, &knob_area, knob_size, hor);
|
||||
|
||||
@ -266,13 +269,14 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par
|
||||
else if(lv_slider_get_type(slider) == LV_SLIDER_TYPE_RANGE) {
|
||||
lv_indev_get_point(param, &p);
|
||||
bool hor = lv_obj_get_width(slider) >= lv_obj_get_height(slider);
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(slider);
|
||||
|
||||
lv_coord_t dist_left, dist_right;
|
||||
if(hor) {
|
||||
if(p.x > ext->right_knob_area.x2) {
|
||||
if((base_dir != LV_BIDI_DIR_RTL && p.x > ext->right_knob_area.x2) || (base_dir == LV_BIDI_DIR_RTL && p.x < ext->right_knob_area.x1)) {
|
||||
ext->value_to_set = &ext->bar.cur_value;
|
||||
}
|
||||
else if(p.x < ext->left_knob_area.x1) {
|
||||
else if((base_dir != LV_BIDI_DIR_RTL && p.x < ext->left_knob_area.x1) || (base_dir == LV_BIDI_DIR_RTL && p.x > ext->left_knob_area.x2)) {
|
||||
ext->value_to_set = &ext->bar.start_value;
|
||||
}
|
||||
else {
|
||||
@ -306,14 +310,15 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par
|
||||
}
|
||||
else if(sign == LV_SIGNAL_PRESSING && ext->value_to_set != NULL) {
|
||||
lv_indev_get_point(param, &p);
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(slider);
|
||||
|
||||
lv_coord_t w = lv_obj_get_width(slider);
|
||||
lv_coord_t h = lv_obj_get_height(slider);
|
||||
|
||||
lv_style_int_t bg_left = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG);
|
||||
lv_style_int_t bg_right = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG);
|
||||
lv_style_int_t bg_top = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG);
|
||||
lv_style_int_t bg_bottom = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG);
|
||||
lv_style_int_t bg_right = lv_obj_get_style_pad_right(slider, LV_SLIDER_PART_BG);
|
||||
lv_style_int_t bg_top = lv_obj_get_style_pad_top(slider, LV_SLIDER_PART_BG);
|
||||
lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(slider, LV_SLIDER_PART_BG);
|
||||
|
||||
int32_t range = ext->bar.max_value - ext->bar.min_value;
|
||||
int16_t new_value = 0;
|
||||
@ -322,6 +327,9 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par
|
||||
|
||||
if(w >= h) {
|
||||
lv_coord_t indic_w = w - bg_left - bg_right;
|
||||
if(base_dir == LV_BIDI_DIR_RTL)
|
||||
new_value = (slider->coords.x2 - bg_right) - p.x; /*Make the point relative to the indicator*/
|
||||
else
|
||||
new_value = p.x - (slider->coords.x1 + bg_left); /*Make the point relative to the indicator*/
|
||||
new_value = (new_value * range) / indic_w;
|
||||
new_value += ext->bar.min_value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user