feat(obj): merge signals into events
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_switch_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static lv_res_t lv_switch_signal(lv_obj_t * obj, lv_signal_t sign, void * param);
|
||||
static void lv_switch_event(lv_obj_t * obj, lv_event_t e);
|
||||
static lv_draw_res_t lv_switch_draw(lv_obj_t * sw, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
|
||||
/**********************
|
||||
@@ -42,7 +42,7 @@ static lv_draw_res_t lv_switch_draw(lv_obj_t * sw, const lv_area_t * clip_area,
|
||||
**********************/
|
||||
const lv_obj_class_t lv_switch_class = {
|
||||
.constructor_cb = lv_switch_constructor,
|
||||
.signal_cb = lv_switch_signal,
|
||||
.event_cb = lv_switch_event,
|
||||
.draw_cb = lv_switch_draw,
|
||||
.instance_size = sizeof(lv_switch_t),
|
||||
.base_class = &lv_obj_class
|
||||
@@ -166,16 +166,16 @@ static lv_draw_res_t lv_switch_draw(lv_obj_t * obj, const lv_area_t * clip_area,
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static lv_res_t lv_switch_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
||||
static void lv_switch_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = lv_obj_signal_base(MY_CLASS, obj, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
res = lv_obj_event_base(MY_CLASS, obj, e);
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
|
||||
if(sign == LV_SIGNAL_REFR_EXT_DRAW_SIZE) {
|
||||
if(e == LV_EVENT_REFR_EXT_DRAW_SIZE) {
|
||||
lv_coord_t knob_left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB);
|
||||
lv_coord_t knob_right = lv_obj_get_style_pad_right(obj, LV_PART_KNOB);
|
||||
lv_coord_t knob_top = lv_obj_get_style_pad_top(obj, LV_PART_KNOB);
|
||||
@@ -190,19 +190,17 @@ static lv_res_t lv_switch_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
||||
|
||||
knob_size = (knob_size - lv_obj_get_height(obj)) / 2;
|
||||
|
||||
lv_coord_t * s = param;
|
||||
lv_coord_t * s = lv_event_get_param();
|
||||
*s = LV_MAX(*s, knob_size);
|
||||
*s = LV_MAX(*s, lv_obj_calculate_ext_draw_size(obj, LV_PART_INDICATOR));
|
||||
}
|
||||
else if(sign == LV_SIGNAL_RELEASED) {
|
||||
else if(e == LV_EVENT_CLICKED) {
|
||||
uint32_t v = lv_obj_get_state(obj) & LV_STATE_CHECKED ? 1 : 0;
|
||||
res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, &v);
|
||||
if(res != LV_RES_OK) return res;
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user