mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 12:08:16 +08:00
improve edit
This commit is contained in:
parent
60c9769ec7
commit
93dd35fb29
@ -30,6 +30,13 @@
|
||||
|
||||
static ret_t edit_update_status(widget_t* widget);
|
||||
|
||||
static ret_t edit_dispatch_event(widget_t* widget, event_type_t type) {
|
||||
event_t evt = event_init(type, widget);
|
||||
widget_dispatch(widget, &evt);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t edit_update_caret(const timer_info_t* timer) {
|
||||
rect_t r;
|
||||
edit_t* edit = EDIT(timer->ctx);
|
||||
@ -147,7 +154,6 @@ static ret_t edit_delete_next_char(widget_t* widget) {
|
||||
}
|
||||
|
||||
static ret_t edit_input_char(widget_t* widget, wchar_t c) {
|
||||
event_t evt;
|
||||
edit_t* edit = EDIT(widget);
|
||||
wstr_t* text = &(widget->text);
|
||||
input_type_t input_type = edit->limit.type;
|
||||
@ -225,8 +231,7 @@ static ret_t edit_input_char(widget_t* widget, wchar_t c) {
|
||||
}
|
||||
}
|
||||
|
||||
evt = event_init(EVT_VALUE_CHANGING, widget);
|
||||
widget_dispatch(widget, &evt);
|
||||
edit_dispatch_event(widget, EVT_VALUE_CHANGING);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@ -438,7 +443,6 @@ ret_t edit_on_event(widget_t* widget, event_t* e) {
|
||||
break;
|
||||
}
|
||||
case EVT_BLUR: {
|
||||
event_t evt = event_init(EVT_VALUE_CHANGED, widget);
|
||||
input_method_request(input_method(), NULL);
|
||||
|
||||
edit_update_status(widget);
|
||||
@ -449,7 +453,7 @@ ret_t edit_on_event(widget_t* widget, event_t* e) {
|
||||
widget_set_state(widget, WIDGET_STATE_ERROR);
|
||||
}
|
||||
}
|
||||
widget_dispatch(widget, &evt);
|
||||
edit_dispatch_event(widget, EVT_VALUE_CHANGED);
|
||||
|
||||
break;
|
||||
}
|
||||
@ -727,11 +731,7 @@ static ret_t edit_add_float(edit_t* edit, double delta) {
|
||||
if (edit->limit.u.f.min < edit->limit.u.f.max) {
|
||||
if (v < edit->limit.u.f.min) {
|
||||
wstr_from_float(text, edit->limit.u.f.min);
|
||||
} else {
|
||||
wstr_add_float(text, delta);
|
||||
}
|
||||
|
||||
if (v > edit->limit.u.f.max) {
|
||||
} else if (v > edit->limit.u.f.max) {
|
||||
wstr_from_float(text, edit->limit.u.f.max);
|
||||
} else {
|
||||
wstr_add_float(text, delta);
|
||||
@ -740,7 +740,10 @@ static ret_t edit_add_float(edit_t* edit, double delta) {
|
||||
wstr_add_float(text, delta);
|
||||
}
|
||||
|
||||
return wstr_trim_float_zero(text);
|
||||
wstr_trim_float_zero(text);
|
||||
edit_dispatch_event(widget, EVT_VALUE_CHANGING);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t edit_add_int(edit_t* edit, int delta) {
|
||||
@ -761,7 +764,28 @@ static ret_t edit_add_int(edit_t* edit, int delta) {
|
||||
}
|
||||
}
|
||||
|
||||
return wstr_from_int(text, v);
|
||||
wstr_from_int(text, v);
|
||||
edit_dispatch_event(widget, EVT_VALUE_CHANGING);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t edit_get_int(widget_t* widget) {
|
||||
int32_t v = 0;
|
||||
return_value_if_fail(widget != NULL, 0);
|
||||
|
||||
wstr_to_int(&(widget->text), &v);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
double edit_get_double(widget_t* widget) {
|
||||
double v = 0;
|
||||
return_value_if_fail(widget != NULL, 0);
|
||||
|
||||
wstr_to_float(&(widget->text), &v);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
ret_t edit_inc(edit_t* edit) {
|
||||
@ -941,3 +965,4 @@ widget_t* edit_create_ex(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h,
|
||||
widget_t* edit_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
return edit_create_ex(parent, x, y, w, h, &s_edit_vtable);
|
||||
}
|
||||
|
||||
|
@ -157,6 +157,26 @@ typedef struct _edit_t {
|
||||
*/
|
||||
widget_t* edit_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);
|
||||
|
||||
/**
|
||||
* @method edit_get_int
|
||||
* 获取int类型的值。
|
||||
* @annotation ["scriptable"]
|
||||
* @param {widget_t*} widget widget对象。
|
||||
*
|
||||
* @return {int32_t} 返回int的值。
|
||||
*/
|
||||
int32_t edit_get_int(widget_t* widget);
|
||||
|
||||
/**
|
||||
* @method edit_get_double
|
||||
* 获取double类型的值。
|
||||
* @annotation ["scriptable"]
|
||||
* @param {widget_t*} widget widget对象。
|
||||
*
|
||||
* @return {double} 返回double的值。
|
||||
*/
|
||||
double edit_get_double(widget_t* widget);
|
||||
|
||||
/**
|
||||
* @method edit_set_text_limit
|
||||
* 设置为文本输入及其长度限制,不允许输入超过max个字符,少于min个字符时进入error状态。
|
||||
|
@ -28,7 +28,7 @@ BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* @class spin_box_t
|
||||
* @parent widget_t
|
||||
* @parent edit_t
|
||||
* @annotation ["scriptable"]
|
||||
* spinbox控件。
|
||||
*/
|
||||
@ -36,7 +36,7 @@ typedef edit_t spin_box_t;
|
||||
|
||||
/**
|
||||
* @method spin_box_create
|
||||
* @annotation ["constructor"]
|
||||
* @annotation ["constructor", "scriptable"]
|
||||
* 创建spin_box对象
|
||||
* @param {widget_t*} parent 父控件
|
||||
* @param {xy_t} x x坐标
|
||||
|
@ -2230,6 +2230,42 @@
|
||||
"desc": "对象。"
|
||||
}
|
||||
},
|
||||
{
|
||||
"params": [
|
||||
{
|
||||
"type": "widget_t*",
|
||||
"name": "widget",
|
||||
"desc": "widget对象。"
|
||||
}
|
||||
],
|
||||
"annotation": {
|
||||
"scriptable": true
|
||||
},
|
||||
"desc": "获取int类型的值。",
|
||||
"name": "edit_get_int",
|
||||
"return": {
|
||||
"type": "int32_t",
|
||||
"desc": "返回int的值。"
|
||||
}
|
||||
},
|
||||
{
|
||||
"params": [
|
||||
{
|
||||
"type": "widget_t*",
|
||||
"name": "widget",
|
||||
"desc": "widget对象。"
|
||||
}
|
||||
],
|
||||
"annotation": {
|
||||
"scriptable": true
|
||||
},
|
||||
"desc": "获取double类型的值。",
|
||||
"name": "edit_get_double",
|
||||
"return": {
|
||||
"type": "double",
|
||||
"desc": "返回double的值。"
|
||||
}
|
||||
},
|
||||
{
|
||||
"params": [
|
||||
{
|
||||
@ -8459,7 +8495,8 @@
|
||||
}
|
||||
],
|
||||
"annotation": {
|
||||
"constructor": true
|
||||
"constructor": true,
|
||||
"scriptable": true
|
||||
},
|
||||
"desc": "创建spin_box对象",
|
||||
"name": "spin_box_create",
|
||||
@ -8473,7 +8510,7 @@
|
||||
"header": "base/spin_box.h",
|
||||
"desc": "spinbox控件。",
|
||||
"name": "spin_box_t",
|
||||
"parent": "widget_t",
|
||||
"parent": "edit_t",
|
||||
"annotation": {
|
||||
"scriptable": true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user