improve edit

This commit is contained in:
xianjimli 2020-04-17 16:26:39 +08:00
parent 0344c51d85
commit 16b624df1f
3 changed files with 17 additions and 9 deletions

View File

@ -1115,8 +1115,10 @@ ret_t text_edit_set_cursor(text_edit_t* text_edit, uint32_t cursor) {
cursor = text->size;
}
impl->state.cursor = cursor;
text_edit_layout(text_edit);
if (impl->state.cursor != cursor) {
impl->state.cursor = cursor;
text_edit_layout(text_edit);
}
return RET_OK;
}
@ -1142,8 +1144,10 @@ ret_t text_edit_set_mask(text_edit_t* text_edit, bool_t mask) {
DECL_IMPL(text_edit);
return_value_if_fail(text_edit != NULL, RET_BAD_PARAMS);
impl->mask = mask;
text_edit_layout(text_edit);
if (impl->mask != mask) {
impl->mask = mask;
text_edit_layout(text_edit);
}
return RET_OK;
}

View File

@ -313,9 +313,6 @@ static ret_t combo_box_on_event(widget_t* widget, event_t* e) {
}
ret = edit_on_event(widget, e);
if (edit->readonly && e->type != EVT_DESTROY) {
edit_set_cursor(WIDGET(edit), 0);
}
return ret;
}

View File

@ -69,6 +69,14 @@ ret_t edit_on_paint_self(widget_t* widget, canvas_t* c) {
edit_t* edit = EDIT(widget);
return_value_if_fail(edit != NULL, RET_BAD_PARAMS);
edit->model->c = c;
if (edit->readonly) {
if (tk_str_eq(widget->vt->type, WIDGET_TYPE_COMBO_BOX))
text_edit_set_cursor(edit->model, 0);
else
text_edit_set_cursor(edit->model, 0xffffffff);
}
if (edit->input_type != INPUT_PASSWORD && edit->input_type != INPUT_CUSTOM_PASSWORD) {
text_edit_set_mask(edit->model, FALSE);
}
@ -519,8 +527,7 @@ ret_t edit_on_event(widget_t* widget, event_t* e) {
return_value_if_fail(widget != NULL && edit != NULL, RET_BAD_PARAMS);
return_value_if_fail(widget->visible, RET_OK);
if (edit->readonly && type != EVT_DESTROY) {
text_edit_set_cursor(edit->model, 0xffffffff);
if (edit->readonly) {
return RET_OK;
}