mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
change slider min/max/value/step to double
This commit is contained in:
parent
9ca5c908d9
commit
ef44532d60
@ -38,9 +38,9 @@ static ret_t slider_load_icon(widget_t* widget, bitmap_t* img) {
|
||||
|
||||
static ret_t slider_update_dragger_rect(widget_t* widget, canvas_t* c) {
|
||||
bitmap_t img;
|
||||
float fvalue = 0;
|
||||
uint16_t value = 0;
|
||||
uint16_t range = 0;
|
||||
double fvalue = 0;
|
||||
double value = 0;
|
||||
double range = 0;
|
||||
float_t ratio = c->lcd->ratio;
|
||||
slider_t* slider = SLIDER(widget);
|
||||
rect_t* r = &(slider->dragger_rect);
|
||||
@ -48,7 +48,7 @@ static ret_t slider_update_dragger_rect(widget_t* widget, canvas_t* c) {
|
||||
|
||||
value = slider->value - slider->min;
|
||||
range = slider->max - slider->min;
|
||||
fvalue = (float)value / (float)range;
|
||||
fvalue = (double)value / (double)range;
|
||||
|
||||
if (slider_load_icon(widget, &img) == RET_OK) {
|
||||
r->w = img.w / ratio;
|
||||
@ -107,8 +107,8 @@ static uint32_t slider_get_bar_size(widget_t* widget) {
|
||||
static ret_t slider_on_paint_self(widget_t* widget, canvas_t* c) {
|
||||
rect_t r;
|
||||
style_t* style = NULL;
|
||||
uint16_t range = 0;
|
||||
uint16_t value = 0;
|
||||
double range = 0;
|
||||
double value = 0;
|
||||
float_t fvalue = 0;
|
||||
uint32_t radius = 0;
|
||||
const char* bg_image = 0;
|
||||
@ -184,8 +184,8 @@ static ret_t slider_pointer_up_cleanup(widget_t* widget) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t slider_add_value(widget_t* widget, int16_t delta) {
|
||||
int32_t new_value = 0;
|
||||
static ret_t slider_add_value(widget_t* widget, double delta) {
|
||||
double new_value = 0;
|
||||
slider_t* slider = SLIDER(widget);
|
||||
return_value_if_fail(widget != NULL && slider != NULL, RET_BAD_PARAMS);
|
||||
|
||||
@ -262,11 +262,11 @@ static ret_t slider_on_event(widget_t* widget, event_t* e) {
|
||||
case EVT_POINTER_MOVE: {
|
||||
pointer_event_t* evt = (pointer_event_t*)e;
|
||||
point_t p = {evt->x, evt->y};
|
||||
int32_t value = 0;
|
||||
double value = 0;
|
||||
if (slider->dragging) {
|
||||
int32_t delta = 0;
|
||||
double delta = 0;
|
||||
widget_to_local(widget, &p);
|
||||
int32_t range = slider->max - slider->min;
|
||||
double range = slider->max - slider->min;
|
||||
|
||||
if (slider->vertical) {
|
||||
delta = range * (slider->down.y - p.y) / (widget->h - slider->dragger_size);
|
||||
@ -276,7 +276,7 @@ static ret_t slider_on_event(widget_t* widget, event_t* e) {
|
||||
|
||||
value = slider->saved_value + delta;
|
||||
value = tk_clampi(value, slider->min, slider->max);
|
||||
slider_set_value_internal(widget, (uint16_t)value, EVT_VALUE_CHANGING, FALSE);
|
||||
slider_set_value_internal(widget, (double)value, EVT_VALUE_CHANGING, FALSE);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -320,19 +320,19 @@ static ret_t slider_on_event(widget_t* widget, event_t* e) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_t slider_set_value_internal(widget_t* widget, uint16_t value, event_type_t etype,
|
||||
bool_t force) {
|
||||
uint16_t step = 0;
|
||||
uint16_t offset = 0;
|
||||
ret_t slider_set_value_internal(widget_t* widget, double value, event_type_t etype, bool_t force) {
|
||||
double step = 0;
|
||||
double offset = 0;
|
||||
slider_t* slider = SLIDER(widget);
|
||||
return_value_if_fail(slider != NULL, RET_BAD_PARAMS);
|
||||
|
||||
step = slider->step;
|
||||
value = tk_max(tk_min(value, slider->max), slider->min);
|
||||
value = tk_clampi(value, slider->min, slider->max);
|
||||
|
||||
if (step > 1) {
|
||||
if (step > 0) {
|
||||
offset = value - slider->min;
|
||||
value = slider->min + ((offset + (step >> 1) - 1) / step) * step;
|
||||
offset = tk_roundi(offset / step) * step;
|
||||
value = slider->min + offset;
|
||||
}
|
||||
|
||||
if (slider->value != value || force) {
|
||||
@ -347,7 +347,7 @@ ret_t slider_set_value_internal(widget_t* widget, uint16_t value, event_type_t e
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t slider_set_value(widget_t* widget, uint16_t value) {
|
||||
ret_t slider_set_value(widget_t* widget, double value) {
|
||||
slider_t* slider = SLIDER(widget);
|
||||
return_value_if_fail(slider != NULL, RET_BAD_PARAMS);
|
||||
|
||||
@ -361,7 +361,7 @@ ret_t slider_set_value(widget_t* widget, uint16_t value) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t slider_set_min(widget_t* widget, uint16_t min) {
|
||||
ret_t slider_set_min(widget_t* widget, double min) {
|
||||
slider_t* slider = SLIDER(widget);
|
||||
return_value_if_fail(slider != NULL, RET_BAD_PARAMS);
|
||||
|
||||
@ -370,7 +370,7 @@ ret_t slider_set_min(widget_t* widget, uint16_t min) {
|
||||
return widget_invalidate(widget, NULL);
|
||||
}
|
||||
|
||||
ret_t slider_set_max(widget_t* widget, uint16_t max) {
|
||||
ret_t slider_set_max(widget_t* widget, double max) {
|
||||
slider_t* slider = SLIDER(widget);
|
||||
return_value_if_fail(slider != NULL, RET_BAD_PARAMS);
|
||||
|
||||
@ -379,9 +379,9 @@ ret_t slider_set_max(widget_t* widget, uint16_t max) {
|
||||
return widget_invalidate(widget, NULL);
|
||||
}
|
||||
|
||||
ret_t slider_set_step(widget_t* widget, uint16_t step) {
|
||||
ret_t slider_set_step(widget_t* widget, double step) {
|
||||
slider_t* slider = SLIDER(widget);
|
||||
return_value_if_fail(slider != NULL && step > 0, RET_BAD_PARAMS);
|
||||
return_value_if_fail(slider != NULL && step >= 0, RET_BAD_PARAMS);
|
||||
|
||||
slider->step = step;
|
||||
|
||||
@ -411,19 +411,19 @@ static ret_t slider_get_prop(widget_t* widget, const char* name, value_t* v) {
|
||||
return_value_if_fail(slider != NULL && name != NULL && v != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (tk_str_eq(name, WIDGET_PROP_VALUE)) {
|
||||
value_set_int(v, slider->value);
|
||||
value_set_double(v, slider->value);
|
||||
return RET_OK;
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_VERTICAL)) {
|
||||
value_set_bool(v, slider->vertical);
|
||||
return RET_OK;
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_MIN)) {
|
||||
value_set_int(v, slider->min);
|
||||
value_set_double(v, slider->min);
|
||||
return RET_OK;
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_MAX)) {
|
||||
value_set_int(v, slider->max);
|
||||
value_set_double(v, slider->max);
|
||||
return RET_OK;
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_STEP)) {
|
||||
value_set_int(v, slider->step);
|
||||
value_set_double(v, slider->step);
|
||||
return RET_OK;
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_BAR_SIZE)) {
|
||||
value_set_int(v, slider->bar_size);
|
||||
@ -437,15 +437,15 @@ static ret_t slider_set_prop(widget_t* widget, const char* name, const value_t*
|
||||
return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (tk_str_eq(name, WIDGET_PROP_VALUE)) {
|
||||
return slider_set_value(widget, value_int(v));
|
||||
return slider_set_value(widget, value_double(v));
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_VERTICAL)) {
|
||||
return slider_set_vertical(widget, value_bool(v));
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_MIN)) {
|
||||
return slider_set_min(widget, value_int(v));
|
||||
return slider_set_min(widget, value_double(v));
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_MAX)) {
|
||||
return slider_set_max(widget, value_int(v));
|
||||
return slider_set_max(widget, value_double(v));
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_STEP)) {
|
||||
return slider_set_step(widget, value_int(v));
|
||||
return slider_set_step(widget, value_double(v));
|
||||
} else if (tk_str_eq(name, WIDGET_PROP_BAR_SIZE)) {
|
||||
return slider_set_bar_size(widget, value_int(v));
|
||||
}
|
||||
|
@ -74,32 +74,32 @@ BEGIN_C_DECLS
|
||||
typedef struct _slider_t {
|
||||
widget_t widget;
|
||||
/**
|
||||
* @property {uint16_t} value
|
||||
* @property {double} value
|
||||
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
|
||||
* 值。
|
||||
*/
|
||||
uint16_t value;
|
||||
double value;
|
||||
|
||||
/**
|
||||
* @property {uint16_t} min
|
||||
* @property {double} min
|
||||
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
|
||||
* 最小值。
|
||||
*/
|
||||
uint16_t min;
|
||||
double min;
|
||||
|
||||
/**
|
||||
* @property {uint16_t} max
|
||||
* @property {double} max
|
||||
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
|
||||
* 最大值。
|
||||
*/
|
||||
uint16_t max;
|
||||
double max;
|
||||
|
||||
/**
|
||||
* @property {uint16_t} step
|
||||
* @property {double} step
|
||||
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
|
||||
* 拖动的最小单位。
|
||||
*/
|
||||
uint16_t step;
|
||||
double step;
|
||||
|
||||
/**
|
||||
* @property {bool_t} vertical
|
||||
@ -118,8 +118,8 @@ typedef struct _slider_t {
|
||||
/*private*/
|
||||
bool_t dragging;
|
||||
|
||||
uint16_t saved_value;
|
||||
uint16_t dragger_size;
|
||||
double saved_value;
|
||||
double dragger_size;
|
||||
point_t down;
|
||||
rect_t dragger_rect;
|
||||
|
||||
@ -169,44 +169,44 @@ widget_t* slider_cast(widget_t* widget);
|
||||
* 设置滑块的值。
|
||||
* @annotation ["scriptable"]
|
||||
* @param {widget_t*} widget 控件对象。
|
||||
* @param {uint16_t} value 值
|
||||
* @param {double} value 值
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t slider_set_value(widget_t* widget, uint16_t value);
|
||||
ret_t slider_set_value(widget_t* widget, double value);
|
||||
|
||||
/**
|
||||
* @method slider_set_min
|
||||
* 设置滑块的最小值。
|
||||
* @annotation ["scriptable"]
|
||||
* @param {widget_t*} widget 控件对象。
|
||||
* @param {uint16_t} min 最小值
|
||||
* @param {double} min 最小值
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t slider_set_min(widget_t* widget, uint16_t min);
|
||||
ret_t slider_set_min(widget_t* widget, double min);
|
||||
|
||||
/**
|
||||
* @method slider_set_max
|
||||
* 设置滑块的最大值。
|
||||
* @annotation ["scriptable"]
|
||||
* @param {widget_t*} widget 控件对象。
|
||||
* @param {uint16_t} max 最大值
|
||||
* @param {double} max 最大值
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t slider_set_max(widget_t* widget, uint16_t max);
|
||||
ret_t slider_set_max(widget_t* widget, double max);
|
||||
|
||||
/**
|
||||
* @method slider_set_step
|
||||
* 设置滑块的拖动的最小单位。
|
||||
* @annotation ["scriptable"]
|
||||
* @param {widget_t*} widget 控件对象。
|
||||
* @param {uint16_t} step 拖动的最小单位。
|
||||
* @param {double} step 拖动的最小单位。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t slider_set_step(widget_t* widget, uint16_t step);
|
||||
ret_t slider_set_step(widget_t* widget, double step);
|
||||
|
||||
/**
|
||||
* @method slider_set_bar_size
|
||||
@ -238,7 +238,7 @@ TK_EXTERN_VTABLE(slider);
|
||||
/*public for test*/
|
||||
ret_t slider_dec(widget_t* widget);
|
||||
ret_t slider_inc(widget_t* widget);
|
||||
ret_t slider_set_value_internal(widget_t* widget, uint16_t value, event_type_t etype, bool_t force);
|
||||
ret_t slider_set_value_internal(widget_t* widget, double value, event_type_t etype, bool_t force);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user