improve text edit

This commit is contained in:
lixianjing 2021-11-03 17:35:28 +08:00
parent b7ae857d5c
commit 0e7df7ba2d
2 changed files with 14 additions and 18 deletions

View File

@ -3,6 +3,7 @@
2021/11/03
* 增加 fs\_foreach\_file
* 完善 demoui 界面(感谢兆坤提供补丁)
* 修复 mledit oy 不正确的问题(感谢兆坤提供补丁)
* 修复在 linuxfb 平台mledit 下按 capslock 键会输入字符的问题(感谢兆坤提供补丁)
* 修复在 linux 和 mac 平台,大键盘上的特殊字符(!@#¥)无法输入到 mledit 问题(感谢兆坤提供补丁)

View File

@ -224,6 +224,9 @@ static ret_t text_edit_set_caret_pos(text_edit_impl_t* impl, uint32_t x, uint32_
impl->caret.y = y;
if (!impl->lock_scrollbar_value) {
uint32_t total_line_height = (impl->last_line_number + 1) * impl->line_height;
uint32_t max_oy = (total_line_height > layout_info->h) ? total_line_height - layout_info->h : 0;
if (view_top > caret_top) {
layout_info->oy = caret_top - layout_info->margin_t;
}
@ -232,6 +235,8 @@ static ret_t text_edit_set_caret_pos(text_edit_impl_t* impl, uint32_t x, uint32_
layout_info->oy = caret_bottom - layout_info->h;
}
layout_info->oy = tk_min(layout_info->oy, max_oy);
if (view_left > caret_left) {
layout_info->ox = caret_left - layout_info->margin_l;
}
@ -407,14 +412,6 @@ static row_info_t* text_edit_multi_line_layout_line(text_edit_t* text_edit, uint
row->info.destroy(darray_pop(&row->info));
}
if (i == state->cursor && state->cursor == text->size) {
if (last_char == STB_TEXTEDIT_NEWLINE) {
text_edit_set_caret_pos(impl, 0, y + line_height, c->font_size);
} else {
text_edit_set_caret_pos(impl, x, y, c->font_size);
}
}
if (last_char == STB_TEXTEDIT_NEWLINE) {
impl->last_row_number = row_num + 1;
impl->last_line_number = line_index + 1;
@ -423,6 +420,14 @@ static row_info_t* text_edit_multi_line_layout_line(text_edit_t* text_edit, uint
impl->last_line_number = line_index;
}
if (i == state->cursor && state->cursor == text->size) {
if (last_char == STB_TEXTEDIT_NEWLINE) {
text_edit_set_caret_pos(impl, 0, y + line_height, c->font_size);
} else {
text_edit_set_caret_pos(impl, x, y, c->font_size);
}
}
last_line = (line_info_t*)darray_get(&row->info, row->line_num - 1);
memset(last_line, 0x00, sizeof(line_info_t));
last_line->text_w = x;
@ -435,14 +440,6 @@ static row_info_t* text_edit_multi_line_layout_line(text_edit_t* text_edit, uint
return row;
}
static ret_t text_edit_fix_oy(text_edit_impl_t* impl) {
text_layout_info_t* layout_info = &(impl->layout_info);
if ((impl->last_line_number + 1) * impl->line_height < layout_info->h) {
layout_info->oy = 0;
}
return RET_OK;
}
static row_info_t* text_edit_layout_line(text_edit_t* text_edit, uint32_t row_num,
uint32_t line_index, uint32_t offset) {
DECL_IMPL(text_edit);
@ -497,8 +494,6 @@ static ret_t text_edit_layout_impl(text_edit_t* text_edit) {
impl->rows->size = i;
text_edit_fix_oy(impl);
text_edit_notify(text_edit);
return RET_OK;