test(switch): add initial unit test (#2794)
* test(switch): Add test file and state at creation test * test(switch): Event handler called only once per click * test(switch): Add test state change when event bubbling is enabled * test(switch): Cleanup event bubbling test * tests(switch): Update memory test and add basic animation test * test(switch) Add helper to click on switch * test(switch) Add basic test for knob size calculation * misc(switch) Replace switch knob rounding error magic number with define * test(switch) Improve animation test Properly wait for 50ms after clicking on the switch using lv_test_indev_wait and also assert on switch state after the first and second clicks * test(switch) cleanup * misc(switch) Cleanup * switch: Expose _LV_SWITCH_KNOB_EXT_AREA_CORRECTION value So we can use it when testing extra draw size
This commit is contained in:
@@ -127,7 +127,7 @@ static void lv_switch_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
|
||||
/*The smaller size is the knob diameter*/
|
||||
lv_coord_t knob_size = LV_MAX4(knob_left, knob_right, knob_bottom, knob_top);
|
||||
knob_size += 2; /*For rounding error*/
|
||||
knob_size += _LV_SWITCH_KNOB_EXT_AREA_CORRECTION;
|
||||
knob_size += lv_obj_calculate_ext_draw_size(obj, LV_PART_KNOB);
|
||||
|
||||
lv_coord_t * s = lv_event_get_param(e);
|
||||
@@ -149,7 +149,6 @@ static void draw_main(lv_event_t * e)
|
||||
lv_switch_t * sw = (lv_switch_t *)obj;
|
||||
|
||||
const lv_area_t * clip_area = lv_event_get_param(e);
|
||||
lv_base_dir_t base_dir = lv_obj_get_style_base_dir(obj, LV_PART_MAIN);
|
||||
|
||||
/*Calculate the indicator area*/
|
||||
lv_coord_t bg_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
@@ -172,29 +171,25 @@ static void draw_main(lv_event_t * e)
|
||||
lv_draw_rect(&indic_area, clip_area, &draw_indic_dsc);
|
||||
|
||||
/*Draw the knob*/
|
||||
lv_coord_t objh = lv_obj_get_height(obj);
|
||||
lv_coord_t knob_size = objh;
|
||||
lv_area_t knob_area;
|
||||
|
||||
lv_coord_t anim_value_x = 0;
|
||||
lv_coord_t knob_size = lv_obj_get_height(obj);
|
||||
lv_coord_t anim_length = obj->coords.x2 - bg_right - obj->coords.x1 - bg_left - knob_size;
|
||||
|
||||
lv_coord_t anim_value_x;
|
||||
|
||||
bool chk = lv_obj_get_state(obj) & LV_STATE_CHECKED;
|
||||
|
||||
if(LV_SWITCH_IS_ANIMATING(sw)) {
|
||||
/* Use the animation's coordinate */
|
||||
anim_value_x = (anim_length * sw->anim_state) / LV_SWITCH_ANIM_STATE_END;
|
||||
}
|
||||
else {
|
||||
/* Use LV_STATE_CHECKED to decide the coordinate */
|
||||
bool chk = lv_obj_get_state(obj) & LV_STATE_CHECKED;
|
||||
anim_value_x = chk ? anim_length : 0;
|
||||
}
|
||||
|
||||
if(base_dir == LV_BASE_DIR_RTL) {
|
||||
if(LV_BASE_DIR_RTL == lv_obj_get_style_base_dir(obj, LV_PART_MAIN)) {
|
||||
anim_value_x = anim_length - anim_value_x;
|
||||
}
|
||||
|
||||
lv_area_t knob_area;
|
||||
knob_area.x1 = obj->coords.x1 + bg_left + anim_value_x;
|
||||
knob_area.x2 = knob_area.x1 + knob_size;
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ extern "C" {
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/** Switch knob extra area correction factor */
|
||||
#define _LV_SWITCH_KNOB_EXT_AREA_CORRECTION 2
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
Reference in New Issue
Block a user