mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
improve slider
This commit is contained in:
parent
f9802421eb
commit
77083e9690
@ -3,6 +3,7 @@
|
||||
2021/06/01
|
||||
* 修复text selector通过widget\_get\_text返回NULL的问题。
|
||||
* 完善控件EVT\_VALUE\_CHANGED/EVT\_VALUE\_WILL\_CHANGE事件的文档。
|
||||
* 完善slider,支持点击修改。
|
||||
|
||||
2021/05/31
|
||||
* 完善vgcanvas\_null/vgcanvas\_nanovg\_soft的编译宏,方便制作keil的pack(感谢静儒提供补丁)
|
||||
|
@ -197,6 +197,7 @@ static ret_t slider_pointer_up_cleanup(widget_t* widget) {
|
||||
slider_t* slider = SLIDER(widget);
|
||||
return_value_if_fail(widget != NULL && slider != NULL, RET_BAD_PARAMS);
|
||||
|
||||
slider->pressed = FALSE;
|
||||
slider->dragging = FALSE;
|
||||
widget_ungrab(widget->parent, widget);
|
||||
widget_set_state(widget, WIDGET_STATE_NORMAL);
|
||||
@ -272,6 +273,7 @@ static ret_t slider_on_event(widget_t* widget, event_t* e) {
|
||||
widget_invalidate(widget, NULL);
|
||||
}
|
||||
slider->down = p;
|
||||
slider->pressed = TRUE;
|
||||
slider->saved_value = slider->value;
|
||||
ret = slider->dragging ? RET_STOP : RET_OK;
|
||||
break;
|
||||
@ -305,7 +307,23 @@ static ret_t slider_on_event(widget_t* widget, event_t* e) {
|
||||
case EVT_POINTER_UP: {
|
||||
if (slider->dragging) {
|
||||
slider_set_value_internal(widget, slider->value, EVT_VALUE_CHANGED, TRUE);
|
||||
} else if(slider->pressed) {
|
||||
double value = 0;
|
||||
double range = slider->max - slider->min;
|
||||
pointer_event_t* evt = (pointer_event_t*)e;
|
||||
point_t p = {evt->x, evt->y};
|
||||
|
||||
widget_to_local(widget, &p);
|
||||
if (slider->vertical) {
|
||||
value = slider->min + range - range * p.y / widget->h;
|
||||
} else {
|
||||
value = slider->min + range * p.x / widget->w;
|
||||
}
|
||||
|
||||
value = tk_clamp(value, slider->min, slider->max);
|
||||
slider_set_value(widget, value);
|
||||
}
|
||||
|
||||
slider_pointer_up_cleanup(widget);
|
||||
break;
|
||||
}
|
||||
|
@ -137,6 +137,7 @@ typedef struct _slider_t {
|
||||
bool_t slide_with_bar;
|
||||
|
||||
/*private*/
|
||||
bool_t pressed;
|
||||
bool_t dragging;
|
||||
double saved_value;
|
||||
point_t down;
|
||||
|
Loading…
Reference in New Issue
Block a user