From 3e079a47aedd379184a4fa7e819c269207724ca9 Mon Sep 17 00:00:00 2001 From: Adam Martini Date: Sat, 20 Jun 2020 16:40:47 -0700 Subject: [PATCH] Pull btn functionality out for now, make checked state make DEAFULT. Add dragging value setters. --- src/lv_themes/lv_theme_material.c | 4 ++++ src/lv_widgets/lv_rotary.c | 32 +++++++++++-------------------- src/lv_widgets/lv_rotary.h | 13 +++---------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/lv_themes/lv_theme_material.c b/src/lv_themes/lv_theme_material.c index 54399c540..f02e122c7 100644 --- a/src/lv_themes/lv_theme_material.c +++ b/src/lv_themes/lv_theme_material.c @@ -814,6 +814,10 @@ static void rotary_init(void) lv_style_set_line_rounded(&styles->rotary_indic, LV_STATE_DEFAULT, true); style_init_reset(&styles->rotary_knob); + lv_style_set_bg_color(&styles->rotary_knob, LV_STATE_CHECKED, COLOR_BTN); + lv_style_set_border_opa(&styles->rotary_knob, LV_STATE_CHECKED, COLOR_BTN_BORDER); + lv_style_set_text_color(&styles->rotary_knob, LV_STATE_CHECKED, IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex(0xffffff)); + lv_style_set_value_color(&styles->rotary_knob, LV_STATE_CHECKED, IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex(0xffffff)); lv_style_set_bg_opa(&styles->rotary_knob, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&styles->rotary_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_radius(&styles->rotary_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); diff --git a/src/lv_widgets/lv_rotary.c b/src/lv_widgets/lv_rotary.c index 0fd4b5cc3..f948ce7d5 100644 --- a/src/lv_widgets/lv_rotary.c +++ b/src/lv_widgets/lv_rotary.c @@ -33,8 +33,6 @@ static lv_design_res_t lv_rotary_design(lv_obj_t * rotary, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_res_t lv_rotary_signal(lv_obj_t * rotary, lv_signal_t sign, void * param); static lv_style_list_t * lv_rotary_get_style(lv_obj_t * rotary, uint8_t part); -// static void draw_bg(lv_obj_t * rotary, const lv_area_t * clip_area); -// static void draw_indic(lv_obj_t * rotary, const lv_area_t * clip_area); static void draw_knob(lv_obj_t * rotary, const lv_area_t * clip_area); /********************** @@ -343,32 +341,24 @@ static lv_res_t lv_rotary_signal(lv_obj_t * rotary, lv_signal_t sign, void * par if(sign == LV_SIGNAL_PRESSED) { ext->dragging = true; } - else if(sign == LV_SIGNAL_PRESSING && ext->value_to_set != NULL) { + else if(sign == LV_SIGNAL_PRESSING && ext->last_drag_x != NULL) { lv_indev_get_point(param, &p); - // TODO: get new_value and set + if (ext->right_knob_area.y1 < p.y && p.y < ext->right_knob_area.y2) { + if (p.x > ext->last_drag_x && p.x < ext->right_knob_area.x2) { + lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) + 1, LV_ANIM_ON); + } + else if (p.x < ext->last_drag_x && p.x > ext->right_knob_area.x1) { + lv_rotary_set_value(rotary, lv_rotary_get_value(rotary) - 1, LV_ANIM_ON); + } + } + + ext->last_drag_x = p.x; } else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { ext->dragging = false; ext->value_to_set = NULL; - /*If not dragged and it was not long press action then - *change state and run the action*/ - if(lv_indev_is_dragging(param) == false && tgl) { - uint32_t toggled = 0; - if(lv_obj_get_state(rotary, LV_ROTARY_PART_KNOB) & LV_STATE_CHECKED) { - lv_btn_set_state(rotary, LV_ROTARY_STATE_RELEASED); - toggled = 0; - } - else { - lv_btn_set_state(rotary, LV_ROTARY_STATE_CHECKED_RELEASED); - toggled = 1; - } - - res = lv_event_send(rotary, LV_EVENT_ROTARY_TOGGLED, &toggled); - if(res != LV_RES_OK) return res; - } - #if LV_USE_GROUP /*Leave edit mode if released. (No need to wait for LONG_PRESS) */ lv_group_t * g = lv_obj_get_group(rotary); diff --git a/src/lv_widgets/lv_rotary.h b/src/lv_widgets/lv_rotary.h index 70f48ad84..f0fcdecb7 100644 --- a/src/lv_widgets/lv_rotary.h +++ b/src/lv_widgets/lv_rotary.h @@ -66,10 +66,9 @@ typedef struct { int16_t cur_value; /*Current value of the rotary*/ int16_t min_value; /*Minimum value of the rotary*/ int16_t max_value; /*Maximum value of the rotary*/ - int16_t * value_to_set; /*Start value of the rotary*/ uint16_t dragging :1; + lv_coord_t last_drag_x; /*Last drag x coordintate of the rotary*/ uint16_t sym :1; - uint8_t checkable :1; /* 1: Toggle enabled*/ } lv_rotary_ext_t; /** Built-in styles of rotary*/ @@ -77,16 +76,10 @@ enum { LV_ROTARY_PART_BG = LV_ARC_PART_BG, /** Rotary background style. */ LV_ROTARY_PART_INDIC = LV_ARC_PART_INDIC, /** Rotary indicator (filled area) style. */ LV_ROTARY_PART_KNOB = _LV_ARC_PART_VIRTUAL_LAST, /** Rotary knob style. */ - _LV_ROTARY_PART_VIRTUAL_LAST + _LV_ROTARY_PART_VIRTUAL_LAST, + _LV_ROTARY_PART_REAL_LAST = _LV_ARC_PART_REAL_LAST }; -/** Custom events of rotary*/ -enum { - LV_EVENT_ROTARY_TOGGLED = _LV_EVENT_LAST, - _LV_EVENT_ROTARY_LAST -}; -typedef uint8_t lv_rotary_event_t; - /********************** * GLOBAL PROTOTYPES **********************/