mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
feat(widgets): migrate textinput editing to the stb_textedit kernel
- vendor stb_textedit and add the textedit core with canonical text - map edit indices to pd_text layout for caret, selection and hit testing - support caret movement, selection, clipboard, undo/redo, password, read-only and multiline editing - render selections with the accent color and configurable text color - fix caret scaling, input-group repaint and zero-size reflow regressions - add integration tests, a preview page and internals notes
This commit is contained in:
@@ -528,3 +528,31 @@ ui_mutation_observer_observe(observer, w, options); /* 观察自身 */
|
||||
`ui_widget_add_mutation_record`),所以观察自身同样收到整个子树的变更;而自身在 destroy 回调
|
||||
里仍然有效,无悬挂指针。scrollarea / combobox 也是观察自身。
|
||||
|
||||
|
||||
## textinput 编辑内核(stb_textedit)
|
||||
|
||||
`textinput` 的编辑状态由 `src/widgets/textedit.c` 封装 `stb_textedit.h` v1.16:
|
||||
|
||||
- canonical 文本是唯一事实来源(`wchar_t`,`\r\n`/`\r` 归一化为 `\n`);
|
||||
- `pd_text` 只是投影:每次编辑后 `pd_text_clear + pd_text_append` 重建,再
|
||||
`pd_text_update`,保证 stb 的后续布局查询看到最新行结构;
|
||||
- 索引映射:软换行不消耗字符,硬换行(`eol != PD_TEXT_EOL_NONE`)消耗 1 个字符;
|
||||
视觉行信息来自 `pd_text_get_line_eol` / `pd_text_get_line_char_start`;
|
||||
- `ui_textinput_update_caret` 必须使用文本层缓存的 `layer_scale`,不能用事件期的
|
||||
`ui_get_actual_scale()`(事件分发发生在 `ui_server_update()` 之外,全局 dpi 可能
|
||||
仍是默认值);
|
||||
- 选区由 textinput 在 `on_paint` 中先于 `pd_text_render_to` 绘制;
|
||||
- 选区颜色默认是实色 `primary`,文字用 `primary-foreground`(亮色主题白字、
|
||||
暗色主题深字);可用 `selection-color` / `selection-text-color` 属性或
|
||||
`ui_textinput_set_selection_color()` / `ui_textinput_set_selection_text_color()`;
|
||||
也支持 CSS 规则 `textinput .selection { background-color: ...; color: ...; }`。
|
||||
textinput 内部维护一个 0×0、绝对定位的 `.selection` 隐藏子部件,只用于承载
|
||||
这些样式,绘制时读取它的 computed `background-color` / `color`。属性/API 会写入
|
||||
该元素的 inline 样式,优先级高于 CSS 规则;两者都没有时回退到默认值;
|
||||
- 编辑场景不支持样式标签(canonical 索引会被 pd_text 消费);Windows 下通过
|
||||
`GETPREV/NEXTCHARINDEX` 跳过 UTF-16 代理对;
|
||||
- 当前重建是 O(N),定位为表单级文本(KB 级);GB 级文档需要 rope/piece table +
|
||||
虚拟化排版,不能沿用该实现。
|
||||
|
||||
测试:`tests/integration/test_textinput.c`、`test_textinput_edit.c`;
|
||||
可视诊断:`tests/previews/preview_textinput_edit.c`。
|
||||
@@ -0,0 +1,123 @@
|
||||
# textinput 编辑内核设计(stb_textedit)
|
||||
|
||||
## 目标
|
||||
|
||||
为 `textinput` 引入 `stb_textedit.h` v1.16 作为编辑状态内核,补齐多行编辑能力:
|
||||
光标、选区、撤销/重做、剪贴板快捷键、鼠标拖选。排版与绘制继续由 Pandagl 的
|
||||
`pd_text_t` 负责,避免两套字体/布局实现漂移。
|
||||
|
||||
## 范围
|
||||
|
||||
v1 包含:
|
||||
|
||||
- 单行 / 多行(硬换行 `\n`)
|
||||
- 软换行(依赖 `pd_text` 的 autowrap;索引映射需跳过软换行行尾)
|
||||
- 光标移动:Left/Right/Up/Down/Home/End/PageUp/PageDown
|
||||
- 选区:Shift + 方向键、Shift + Home/End、鼠标点击/拖拽
|
||||
- 撤销/重做:Ctrl+Z / Ctrl+Y
|
||||
- 剪贴板:Ctrl+A / Ctrl+C / Ctrl+X / Ctrl+V(有选区时复制/剪切选区)
|
||||
- 输入法提交文本(`textinput` 事件)作为一次编辑
|
||||
- 密码模式、只读模式、placeholder
|
||||
|
||||
v1 不包含:
|
||||
|
||||
- IME preedit(组合态)内联显示;只接收最终提交文本
|
||||
- 样式标签在编辑场景下的索引同步(编辑场景保持禁用)
|
||||
- 语法高亮、多光标、行号、bidi、grapheme cluster 级移动(仅保证不拆
|
||||
Windows 代理对)
|
||||
|
||||
## 分层
|
||||
|
||||
```
|
||||
PTK 输入事件
|
||||
↓
|
||||
textinput widget(焦点、只读、密码、剪贴板、IME 事件)
|
||||
↓
|
||||
textedit(canonical 文本 + stb 状态 + 索引映射 + 撤销栈)
|
||||
↓
|
||||
pd_text(排版、换行、行高、字符 advance、光标像素)
|
||||
↓
|
||||
Canvas 绘制(文本 + 选区 overlay + textcaret)
|
||||
```
|
||||
|
||||
## 数据结构
|
||||
|
||||
```c
|
||||
typedef struct ui_text_edit {
|
||||
wchar_t *text; /* canonical,统一使用 \n */
|
||||
int length;
|
||||
int capacity;
|
||||
STB_TexteditState state; /* cursor / selection / undo */
|
||||
pd_text_t *layer; /* 投影层,用于排版/渲染 */
|
||||
float layer_scale; /* 逻辑像素 -> 实际像素 */
|
||||
bool style_tag_enabled; /* v1 编辑时禁用 */
|
||||
} ui_text_edit_t;
|
||||
```
|
||||
|
||||
- canonical 是唯一事实来源;`pd_text` 是它的投影。
|
||||
- `\r\n` / `\r` 在进入 canonical 前统一归一化为 `\n`。
|
||||
- 公共读取 API(`ui_textinput_get_text_w` / `get_text_length`)改读 canonical。
|
||||
|
||||
## stb 配置
|
||||
|
||||
```c
|
||||
#define STB_TEXTEDIT_CHARTYPE wchar_t
|
||||
#define STB_TEXTEDIT_NEWLINE L'\n'
|
||||
#define STB_TEXTEDIT_STRING ui_text_edit_t
|
||||
#define STB_TEXTEDIT_STRINGLEN(e) ((e)->length)
|
||||
#define STB_TEXTEDIT_GETCHAR(e, i) ((e)->text[i])
|
||||
#define STB_TEXTEDIT_INSERTCHARS(e, i, c, n) ui_text_edit_insert_raw(e, i, c, n)
|
||||
#define STB_TEXTEDIT_DELETECHARS(e, i, n) ui_text_edit_delete_raw(e, i, n)
|
||||
#define STB_TEXTEDIT_LAYOUTROW(r, e, i) ui_text_edit_layout_row(r, e, i)
|
||||
#define STB_TEXTEDIT_GETWIDTH(e, start, i) ui_text_edit_get_width(e, start, i)
|
||||
#define STB_TEXTEDIT_GETPREVCHARINDEX(e, i) ui_text_edit_prev_index(e, i)
|
||||
#define STB_TEXTEDIT_GETNEXTCHARINDEX(e, i) ui_text_edit_next_index(e, i)
|
||||
#define STB_TEXTEDIT_IS_SPACE(ch) iswspace(ch)
|
||||
```
|
||||
|
||||
- 不定义 `STB_TEXTEDIT_KEYTOTEXT`;字符输入统一走 `stb_textedit_text()`,避免
|
||||
stb 把按键与字符混在一起。
|
||||
- Undo 使用默认 99 条 / 999 字符;后续如需要可在 `textedit.c` 内调整宏。
|
||||
|
||||
## 索引映射
|
||||
|
||||
- canonical 索引 ↔ pd_text 视觉行列通过一次线性扫描完成:
|
||||
- 每个视觉行消耗 `line->length` 个字符;
|
||||
- 硬换行(`eol != PD_TEXT_EOL_NONE`)额外消耗 1 个 `\n`;
|
||||
- 软换行(`eol == PD_TEXT_EOL_NONE`)不消耗字符。
|
||||
- `LAYOUTROW(r, e, index)`:从 `index` 开始找到视觉行,`num_chars = 行剩余
|
||||
字符数 + (硬换行 ? 1 : 0)`,`baseline_y_delta = line->height`。
|
||||
- `GETWIDTH` 直接读 `line->string[col]->bitmap->metrics.hori_advance`,不调用
|
||||
`pd_text_get_char_pixel()`,避免 O(N²)。
|
||||
|
||||
## 排版同步
|
||||
|
||||
- 每次 `INSERTCHARS` / `DELETECHARS` 后:
|
||||
1. 更新 canonical;
|
||||
2. 用 `pd_text_clear` + `pd_text_append` 重建投影层(小文本可接受);
|
||||
3. 立即 `pd_text_update()`,保证 stb 后续查询看到新行结构。
|
||||
- caret 像素由 `pd_text_set_caret()` + `pd_text_get_caret_pixel()` 提供;
|
||||
textinput 负责除以 `layer_scale` 转逻辑像素。
|
||||
|
||||
## 选区绘制
|
||||
|
||||
- 在 `ui_textinput_on_paint()` 中、`pd_text_render_to()` 之前绘制。
|
||||
- 按视觉行拆分 `[select_start, select_end)`,用 `pd_text_get_char_pixel()` 取
|
||||
每行起止 x,`line->height` 取高度。
|
||||
- 选区颜色使用主题 `primary/20` 或 `foreground/15`(实现时二选一并加测试)。
|
||||
- 密码模式可选:v1 允许选中,但绘制仍显示屏蔽字符;不额外暴露明文。
|
||||
|
||||
## 失败模式(Review Focus)
|
||||
|
||||
1. 软换行边界:光标落在软换行行尾/下一行行首时必须只对应一个 canonical 索引。
|
||||
2. 硬换行删除:Backspace 跨行合并、Delete 行尾合并必须与 canonical 一致。
|
||||
3. Windows 代理对(emoji):左右移动和退格不能拆代理对。
|
||||
4. 排版延迟:插入/删除后未立即 `pd_text_update()` 会导致光标/选区错位。
|
||||
5. CRLF:canonical 必须归一化,否则 `pd_text->length` 与 canonical 索引错位。
|
||||
6. 密码/只读:只读仍允许选择与复制;密码模式不能把明文写进剪贴板以外的地方。
|
||||
7. 样式标签:编辑场景若开启会破坏索引,v1 必须显式拒绝或忽略。
|
||||
|
||||
## 许可
|
||||
|
||||
`stb_textedit.h` 为 MIT 或公有领域双许可,与 LCUI 的 MIT 兼容。vendor 时保留
|
||||
文件头与许可证原文,并在 `src/widgets/third-party/README.md` 记录来源与版本。
|
||||
@@ -31,28 +31,43 @@
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
/** Enable style tag parser */
|
||||
/** Enable the style tag parser (read-only display only; ignored while editable)
|
||||
*/
|
||||
LCUI_API void ui_textinput_enable_style_tag(ui_widget_t *widget, bool enable);
|
||||
|
||||
LCUI_API void ui_textinput_enable_multiline(ui_widget_t *widget, bool enable);
|
||||
|
||||
/** 设置只读状态:仍可移动光标和选择/复制,但不能修改文本 */
|
||||
LCUI_API void ui_textinput_set_read_only(ui_widget_t *widget, bool read_only);
|
||||
|
||||
/** 设置选区背景色(支持 rgba;默认实色 primary) */
|
||||
LCUI_API void ui_textinput_set_selection_color(ui_widget_t *widget,
|
||||
pd_color_t color);
|
||||
|
||||
/** 设置选区文字颜色(默认 primary-foreground) */
|
||||
LCUI_API void ui_textinput_set_selection_text_color(ui_widget_t *widget,
|
||||
pd_color_t color);
|
||||
|
||||
LCUI_API void ui_textinput_move_caret(ui_widget_t *widget, int row, int col);
|
||||
|
||||
/** 清空文本内容 */
|
||||
LCUI_API void ui_textinput_clear_text(ui_widget_t *widget);
|
||||
|
||||
/** 获取文本内容 */
|
||||
/**
|
||||
* 获取文本内容。start 是包含换行符的扁平字符索引;
|
||||
* 文本写入时 CRLF / CR 已归一化为 LF。
|
||||
*/
|
||||
LCUI_API size_t ui_textinput_get_text_w(ui_widget_t *w, size_t start,
|
||||
size_t max_len, wchar_t *buf);
|
||||
|
||||
/** 获取文本长度 */
|
||||
/** 获取文本长度(CRLF 已归一化) */
|
||||
LCUI_API size_t ui_textinput_get_text_length(ui_widget_t *w);
|
||||
|
||||
/** 设置文本编辑框内的光标,指定是否闪烁、闪烁时间间隔 */
|
||||
LCUI_API void ui_textinput_set_caret_blink(ui_widget_t *w, bool visible,
|
||||
int time);
|
||||
|
||||
/** 为文本框设置文本(宽字符版) */
|
||||
/** 为文本框设置文本(宽字符版);CRLF / CR 会归一化为 LF */
|
||||
LCUI_API int ui_textinput_set_text_w(ui_widget_t *widget, const wchar_t *wstr);
|
||||
|
||||
LCUI_API int ui_textinput_set_text(ui_widget_t *widget, const char *utf8_str);
|
||||
|
||||
@@ -142,6 +142,15 @@ PD_PUBLIC int pd_text_get_line_height(pd_text_t *layer, int line_num);
|
||||
/** 获取指定文本行的文本长度 */
|
||||
PD_PUBLIC int pd_text_get_line_length(pd_text_t *layer, int line_num);
|
||||
|
||||
/** 获取指定视觉行的行尾类型(越界返回 PD_TEXT_EOL_NONE) */
|
||||
PD_PUBLIC pd_text_eol_t pd_text_get_line_eol(pd_text_t *layer, int line_num);
|
||||
|
||||
/**
|
||||
* 获取指定视觉行首字符在扁平文本中的索引(包含前序硬换行的字符数)。
|
||||
* 软换行不消耗字符,越界返回 -1。
|
||||
*/
|
||||
PD_PUBLIC int pd_text_get_line_char_start(pd_text_t *layer, int line_num);
|
||||
|
||||
/** 添加 更新文本排版 的任务 */
|
||||
PD_PUBLIC void pd_text_request_typeset(pd_text_t *layer, int start_row);
|
||||
|
||||
@@ -171,6 +180,14 @@ PD_PUBLIC int pd_text_get_char_pixel(pd_text_t *layer, int line_num, int col,
|
||||
/** 获取文本光标的像素坐标 */
|
||||
PD_PUBLIC int pd_text_get_caret_pixel(pd_text_t *layer, pd_pos_t *pixel_pos);
|
||||
|
||||
/**
|
||||
* 获取视觉行中 [start_col, end_col] 字符范围的矩形(实际像素坐标,
|
||||
* 包含 offset 与对齐偏移)。返回 0 表示有效区域。
|
||||
*/
|
||||
PD_PUBLIC int pd_text_get_line_rect(pd_text_t *layer, int line_num,
|
||||
int start_col, int end_col,
|
||||
pd_rect_t *rect);
|
||||
|
||||
/** 清空文本 */
|
||||
PD_PUBLIC void pd_text_clear(pd_text_t *layer);
|
||||
|
||||
|
||||
@@ -349,6 +349,43 @@ int pd_text_get_line_length(pd_text_t *text, int line_num)
|
||||
return text->lines[line_num]->length;
|
||||
}
|
||||
|
||||
static int pd_text_eol_length(pd_text_eol_t eol)
|
||||
{
|
||||
switch (eol) {
|
||||
case PD_TEXT_EOL_CR:
|
||||
case PD_TEXT_EOL_LF:
|
||||
return 1;
|
||||
case PD_TEXT_EOL_CR_LF:
|
||||
return 2;
|
||||
case PD_TEXT_EOL_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pd_text_eol_t pd_text_get_line_eol(pd_text_t *text, int line_num)
|
||||
{
|
||||
if (line_num < 0 || line_num >= text->lines_length) {
|
||||
return PD_TEXT_EOL_NONE;
|
||||
}
|
||||
return text->lines[line_num]->eol;
|
||||
}
|
||||
|
||||
int pd_text_get_line_char_start(pd_text_t *text, int line_num)
|
||||
{
|
||||
int i, start = 0;
|
||||
|
||||
if (line_num < 0 || line_num >= text->lines_length) {
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < line_num; ++i) {
|
||||
start += text->lines[i]->length +
|
||||
pd_text_eol_length(text->lines[i]->eol);
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
void pd_text_request_typeset(pd_text_t *text, int start_line)
|
||||
{
|
||||
if (start_line < text->task.typeset_start_line) {
|
||||
@@ -364,7 +401,7 @@ int pd_text_get_line_rect(pd_text_t *text, int line_num, int start_col,
|
||||
int i;
|
||||
pd_text_line_t *line;
|
||||
|
||||
if (line_num >= text->lines_length) {
|
||||
if (line_num < 0 || line_num >= text->lines_length) {
|
||||
return -1;
|
||||
}
|
||||
/* 先计算在有效区域内的起始行的y轴坐标 */
|
||||
@@ -374,6 +411,14 @@ int pd_text_get_line_rect(pd_text_t *text, int line_num, int start_col,
|
||||
rect->y += text->lines[i]->height;
|
||||
}
|
||||
line = text->lines[line_num];
|
||||
if (start_col < 0) {
|
||||
start_col = 0;
|
||||
} else if (start_col > line->length) {
|
||||
start_col = line->length;
|
||||
}
|
||||
if (end_col < start_col) {
|
||||
end_col = start_col - 1;
|
||||
}
|
||||
if (end_col < 0 || end_col >= line->length) {
|
||||
end_col = line->length - 1;
|
||||
}
|
||||
@@ -383,7 +428,7 @@ int pd_text_get_line_rect(pd_text_t *text, int line_num, int start_col,
|
||||
rect->width = line->width;
|
||||
} else {
|
||||
for (i = 0; i < start_col; ++i) {
|
||||
if (!line->string[i]->bitmap) {
|
||||
if (!line->string[i] || !line->string[i]->bitmap) {
|
||||
continue;
|
||||
}
|
||||
rect->x +=
|
||||
@@ -391,7 +436,7 @@ int pd_text_get_line_rect(pd_text_t *text, int line_num, int start_col,
|
||||
}
|
||||
rect->width = 0;
|
||||
for (i = start_col; i <= end_col && i < line->length; ++i) {
|
||||
if (!line->string[i]->bitmap) {
|
||||
if (!line->string[i] || !line->string[i]->bitmap) {
|
||||
continue;
|
||||
}
|
||||
rect->width +=
|
||||
|
||||
@@ -285,54 +285,61 @@ int pd_text_write(pd_text_t *text, const wchar_t *wstr, list_t *tag_stack)
|
||||
size_t pd_text_read(pd_text_t *text, size_t start_pos, size_t max_len,
|
||||
wchar_t *wstr_buff)
|
||||
{
|
||||
size_t i, line_num, col;
|
||||
size_t i, out = 0;
|
||||
int col, line_num;
|
||||
pd_text_line_t *line;
|
||||
|
||||
if (max_len == 0) {
|
||||
wstr_buff[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
/* 先根据一维坐标计算行列坐标 */
|
||||
for (i = 0, line_num = 0, col = 0; line_num < text->lines_length;
|
||||
++line_num) {
|
||||
if (i >= start_pos) {
|
||||
col = start_pos - i;
|
||||
break;
|
||||
}
|
||||
i += text->lines[line_num]->length;
|
||||
}
|
||||
for (i = 0; line_num < text->lines_length && i < max_len; ++line_num) {
|
||||
/* 一维坐标包含行尾换行符,与编辑器内核的字符索引保持一致 */
|
||||
for (i = 0, line_num = 0; line_num < text->lines_length; ++line_num) {
|
||||
line = text->lines[line_num];
|
||||
for (; col < line->length && i < max_len; ++col, ++i) {
|
||||
wstr_buff[i] = line->string[col]->code;
|
||||
for (col = 0; col < line->length && out < max_len; ++col) {
|
||||
if (i >= start_pos) {
|
||||
wstr_buff[out++] = line->string[col]->code;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
/* 进入下一行前,按行尾符还原对应的换行字符 */
|
||||
if (i >= max_len) {
|
||||
if (out >= max_len) {
|
||||
break;
|
||||
}
|
||||
switch (line->eol) {
|
||||
case PD_TEXT_EOL_CR:
|
||||
wstr_buff[i++] = L'\r';
|
||||
if (i >= start_pos) {
|
||||
wstr_buff[out++] = L'\r';
|
||||
}
|
||||
++i;
|
||||
break;
|
||||
case PD_TEXT_EOL_LF:
|
||||
wstr_buff[i++] = L'\n';
|
||||
if (i >= start_pos) {
|
||||
wstr_buff[out++] = L'\n';
|
||||
}
|
||||
++i;
|
||||
break;
|
||||
case PD_TEXT_EOL_CR_LF:
|
||||
wstr_buff[i++] = L'\r';
|
||||
if (i >= max_len) {
|
||||
break;
|
||||
if (i >= start_pos) {
|
||||
wstr_buff[out++] = L'\r';
|
||||
}
|
||||
++i;
|
||||
if (out < max_len) {
|
||||
if (i >= start_pos) {
|
||||
wstr_buff[out++] = L'\n';
|
||||
}
|
||||
++i;
|
||||
}
|
||||
wstr_buff[i++] = L'\n';
|
||||
break;
|
||||
case PD_TEXT_EOL_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* 切换到下一行时必须重置列号 */
|
||||
col = 0;
|
||||
if (out >= max_len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
wstr_buff[i] = 0;
|
||||
return i;
|
||||
wstr_buff[out] = 0;
|
||||
return out;
|
||||
}
|
||||
|
||||
wchar_t *pd_text_to_wcs(pd_text_t *text)
|
||||
|
||||
@@ -207,6 +207,41 @@ static void should_dump_respect_max_len(void)
|
||||
pd_text_destroy(text);
|
||||
}
|
||||
|
||||
static void should_dump_from_multiline_offset(void)
|
||||
{
|
||||
pd_text_t *text = pd_text_create();
|
||||
wchar_t buf[16];
|
||||
|
||||
pd_text_set_multiline(text, true);
|
||||
pd_text_write(text, L"abc\ndef", NULL);
|
||||
/* 一维索引包含换行符:0..2=abc, 3=\n, 4..6=def */
|
||||
ctest_equal_uint("should read from the second line",
|
||||
(unsigned)pd_text_read(text, 4, 16, buf), 3u);
|
||||
ctest_equal_wcs("should return the second line text", buf, L"def");
|
||||
ctest_equal_uint("should read starting at the newline",
|
||||
(unsigned)pd_text_read(text, 3, 16, buf), 4u);
|
||||
ctest_equal_wcs("should include the newline", buf, L"\ndef");
|
||||
pd_text_destroy(text);
|
||||
}
|
||||
|
||||
static void should_report_line_char_start(void)
|
||||
{
|
||||
pd_text_t *text = pd_text_create();
|
||||
|
||||
pd_text_set_multiline(text, true);
|
||||
pd_text_write(text, L"abc\ndef", NULL);
|
||||
ctest_equal_int("line 0 should start at 0",
|
||||
pd_text_get_line_char_start(text, 0), 0);
|
||||
ctest_equal_int("line 1 should follow the newline",
|
||||
pd_text_get_line_char_start(text, 1), 4);
|
||||
ctest_equal_bool("line 0 eol is LF",
|
||||
pd_text_get_line_eol(text, 0) == PD_TEXT_EOL_LF, true);
|
||||
ctest_equal_bool("line 1 eol is none",
|
||||
pd_text_get_line_eol(text, 1) == PD_TEXT_EOL_NONE,
|
||||
true);
|
||||
pd_text_destroy(text);
|
||||
}
|
||||
|
||||
static void should_to_wcs_return_full_text(void)
|
||||
{
|
||||
pd_text_t *text = pd_text_create();
|
||||
@@ -346,6 +381,9 @@ void test_pandagl_text_edit(void)
|
||||
ctest_describe("text dump trailing newline",
|
||||
should_dump_multiline_with_trailing_newline);
|
||||
ctest_describe("text dump max len", should_dump_respect_max_len);
|
||||
ctest_describe("text dump multiline offset",
|
||||
should_dump_from_multiline_offset);
|
||||
ctest_describe("text line char start", should_report_line_char_start);
|
||||
ctest_describe("text to_wcs full text", should_to_wcs_return_full_text);
|
||||
ctest_describe("text to_wcs empty", should_to_wcs_handle_empty_text);
|
||||
ctest_describe("text escape open bracket", should_escape_open_bracket);
|
||||
|
||||
@@ -87,6 +87,10 @@ static const ui_theme_rule_t ui_theme_rules[] = {
|
||||
{ "checkbox:indeterminate", "background-color", UI_THEME_TOKEN_PRIMARY, 1, -1 },
|
||||
{ "checkbox:checked", "color", UI_THEME_TOKEN_PRIMARY_FOREGROUND, 1, -1 },
|
||||
{ "checkbox:indeterminate", "color", UI_THEME_TOKEN_PRIMARY_FOREGROUND, 1, -1 },
|
||||
{ "textinput .selection", "background-color", UI_THEME_TOKEN_PRIMARY, 0, -1 },
|
||||
{ "textinput .selection", "color", UI_THEME_TOKEN_PRIMARY_FOREGROUND, 0, -1 },
|
||||
{ "textinput .selection", "background-color", UI_THEME_TOKEN_PRIMARY, 1, -1 },
|
||||
{ "textinput .selection", "color", UI_THEME_TOKEN_PRIMARY_FOREGROUND, 1, -1 },
|
||||
{ ".sidebar-menu-button:hover", "background-color", UI_THEME_TOKEN_SIDEBAR_ACCENT, 0, -1 },
|
||||
{ ".sidebar-menu-button:hover", "color", UI_THEME_TOKEN_SIDEBAR_ACCENT_FOREGROUND, 0, -1 },
|
||||
{ ".sidebar-menu-button:hover", "background-color", UI_THEME_TOKEN_SIDEBAR_ACCENT, 1, -1 },
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-amber textinput .selection {
|
||||
background-color: rgba(217, 119, 6, 1);
|
||||
}
|
||||
|
||||
.accent-amber textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-amber.dark textinput .selection {
|
||||
background-color: rgba(251, 191, 36, 1);
|
||||
}
|
||||
|
||||
.accent-amber.dark textinput .selection {
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-amber .sidebar-menu-button:hover {
|
||||
background-color: rgba(217, 119, 6, 0.1);
|
||||
}
|
||||
|
||||
@@ -197,8 +197,16 @@ static const struct {
|
||||
{ " background-color: rgba(251, 191, 36, 0.15);\n", 46 },
|
||||
{ " color: rgba(251, 191, 36, 1);\n", 32 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-amber textinput .selection {\n", 37 },
|
||||
{ " background-color: rgba(217, 119, 6, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-amber.dark textinput .selection {\n", 42 },
|
||||
{ " background-color: rgba(251, 191, 36, 1);\n", 43 },
|
||||
{ " color: rgba(23, 23, 23, 1);\n", 30 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_amber_total_length = 5402;
|
||||
static const size_t css_str_amber_total_length = 5633;
|
||||
static inline void ui_load_css_string_amber_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-blue textinput .selection {
|
||||
background-color: rgba(37, 99, 235, 1);
|
||||
}
|
||||
|
||||
.accent-blue textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-blue.dark textinput .selection {
|
||||
background-color: rgba(96, 165, 250, 1);
|
||||
}
|
||||
|
||||
.accent-blue.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-blue .sidebar-menu-button:hover {
|
||||
background-color: rgba(37, 99, 235, 0.1);
|
||||
}
|
||||
|
||||
@@ -195,8 +195,16 @@ static const struct {
|
||||
{ " background-color: rgba(96, 165, 250, 0.15);\n", 46 },
|
||||
{ " color: rgba(96, 165, 250, 1);\n", 32 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-blue textinput .selection {\n", 36 },
|
||||
{ " background-color: rgba(37, 99, 235, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-blue.dark textinput .selection {\n", 41 },
|
||||
{ " background-color: rgba(96, 165, 250, 1);\n", 43 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_blue_total_length = 5375;
|
||||
static const size_t css_str_blue_total_length = 5607;
|
||||
static inline void ui_load_css_string_blue_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-cyan textinput .selection {
|
||||
background-color: rgba(8, 145, 178, 1);
|
||||
}
|
||||
|
||||
.accent-cyan textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-cyan.dark textinput .selection {
|
||||
background-color: rgba(34, 211, 238, 1);
|
||||
}
|
||||
|
||||
.accent-cyan.dark textinput .selection {
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-cyan .sidebar-menu-button:hover {
|
||||
background-color: rgba(8, 145, 178, 0.1);
|
||||
}
|
||||
|
||||
@@ -195,8 +195,16 @@ static const struct {
|
||||
{ " background-color: rgba(34, 211, 238, 0.15);\n", 46 },
|
||||
{ " color: rgba(34, 211, 238, 1);\n", 32 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-cyan textinput .selection {\n", 36 },
|
||||
{ " background-color: rgba(8, 145, 178, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-cyan.dark textinput .selection {\n", 41 },
|
||||
{ " background-color: rgba(34, 211, 238, 1);\n", 43 },
|
||||
{ " color: rgba(23, 23, 23, 1);\n", 30 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_cyan_total_length = 5342;
|
||||
static const size_t css_str_cyan_total_length = 5571;
|
||||
static inline void ui_load_css_string_cyan_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-emerald textinput .selection {
|
||||
background-color: rgba(5, 150, 105, 1);
|
||||
}
|
||||
|
||||
.accent-emerald textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-emerald.dark textinput .selection {
|
||||
background-color: rgba(52, 211, 153, 1);
|
||||
}
|
||||
|
||||
.accent-emerald.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-emerald .sidebar-menu-button:hover {
|
||||
background-color: rgba(5, 150, 105, 0.1);
|
||||
}
|
||||
|
||||
@@ -199,8 +199,16 @@ static const struct {
|
||||
{ " background-color: rgba(52, 211, 153, 0.15);\n", 46 },
|
||||
{ " color: rgba(52, 211, 153, 1);\n", 32 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-emerald textinput .selection {\n", 39 },
|
||||
{ " background-color: rgba(5, 150, 105, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-emerald.dark textinput .selection {\n", 44 },
|
||||
{ " background-color: rgba(52, 211, 153, 1);\n", 43 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_emerald_total_length = 5555;
|
||||
static const size_t css_str_emerald_total_length = 5793;
|
||||
static inline void ui_load_css_string_emerald_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-fuchsia textinput .selection {
|
||||
background-color: rgba(192, 38, 211, 1);
|
||||
}
|
||||
|
||||
.accent-fuchsia textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-fuchsia.dark textinput .selection {
|
||||
background-color: rgba(232, 121, 249, 1);
|
||||
}
|
||||
|
||||
.accent-fuchsia.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-fuchsia .sidebar-menu-button:hover {
|
||||
background-color: rgba(192, 38, 211, 0.1);
|
||||
}
|
||||
|
||||
@@ -199,8 +199,16 @@ static const struct {
|
||||
{ " background-color: rgba(232, 121, 249, 0.15);\n", 47 },
|
||||
{ " color: rgba(232, 121, 249, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-fuchsia textinput .selection {\n", 39 },
|
||||
{ " background-color: rgba(192, 38, 211, 1);\n", 43 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-fuchsia.dark textinput .selection {\n", 44 },
|
||||
{ " background-color: rgba(232, 121, 249, 1);\n", 44 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_fuchsia_total_length = 5609;
|
||||
static const size_t css_str_fuchsia_total_length = 5849;
|
||||
static inline void ui_load_css_string_fuchsia_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-green textinput .selection {
|
||||
background-color: rgba(22, 163, 74, 1);
|
||||
}
|
||||
|
||||
.accent-green textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-green.dark textinput .selection {
|
||||
background-color: rgba(74, 222, 128, 1);
|
||||
}
|
||||
|
||||
.accent-green.dark textinput .selection {
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-green .sidebar-menu-button:hover {
|
||||
background-color: rgba(22, 163, 74, 0.1);
|
||||
}
|
||||
|
||||
@@ -197,8 +197,16 @@ static const struct {
|
||||
{ " background-color: rgba(74, 222, 128, 0.15);\n", 46 },
|
||||
{ " color: rgba(74, 222, 128, 1);\n", 32 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-green textinput .selection {\n", 37 },
|
||||
{ " background-color: rgba(22, 163, 74, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-green.dark textinput .selection {\n", 42 },
|
||||
{ " background-color: rgba(74, 222, 128, 1);\n", 43 },
|
||||
{ " color: rgba(23, 23, 23, 1);\n", 30 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_green_total_length = 5402;
|
||||
static const size_t css_str_green_total_length = 5633;
|
||||
static inline void ui_load_css_string_green_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-indigo textinput .selection {
|
||||
background-color: rgba(79, 70, 229, 1);
|
||||
}
|
||||
|
||||
.accent-indigo textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-indigo.dark textinput .selection {
|
||||
background-color: rgba(129, 140, 248, 1);
|
||||
}
|
||||
|
||||
.accent-indigo.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-indigo .sidebar-menu-button:hover {
|
||||
background-color: rgba(79, 70, 229, 0.1);
|
||||
}
|
||||
|
||||
@@ -199,8 +199,16 @@ static const struct {
|
||||
{ " background-color: rgba(129, 140, 248, 0.15);\n", 47 },
|
||||
{ " color: rgba(129, 140, 248, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-indigo textinput .selection {\n", 38 },
|
||||
{ " background-color: rgba(79, 70, 229, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-indigo.dark textinput .selection {\n", 43 },
|
||||
{ " background-color: rgba(129, 140, 248, 1);\n", 44 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_indigo_total_length = 5522;
|
||||
static const size_t css_str_indigo_total_length = 5759;
|
||||
static inline void ui_load_css_string_indigo_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-lime textinput .selection {
|
||||
background-color: rgba(101, 163, 13, 1);
|
||||
}
|
||||
|
||||
.accent-lime textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-lime.dark textinput .selection {
|
||||
background-color: rgba(163, 230, 53, 1);
|
||||
}
|
||||
|
||||
.accent-lime.dark textinput .selection {
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-lime .sidebar-menu-button:hover {
|
||||
background-color: rgba(101, 163, 13, 0.1);
|
||||
}
|
||||
|
||||
@@ -195,8 +195,16 @@ static const struct {
|
||||
{ " background-color: rgba(163, 230, 53, 0.15);\n", 46 },
|
||||
{ " color: rgba(163, 230, 53, 1);\n", 32 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-lime textinput .selection {\n", 36 },
|
||||
{ " background-color: rgba(101, 163, 13, 1);\n", 43 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-lime.dark textinput .selection {\n", 41 },
|
||||
{ " background-color: rgba(163, 230, 53, 1);\n", 43 },
|
||||
{ " color: rgba(23, 23, 23, 1);\n", 30 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_lime_total_length = 5369;
|
||||
static const size_t css_str_lime_total_length = 5599;
|
||||
static inline void ui_load_css_string_lime_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-neutral textinput .selection {
|
||||
background-color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-neutral textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-neutral.dark textinput .selection {
|
||||
background-color: rgba(245, 245, 245, 1);
|
||||
}
|
||||
|
||||
.accent-neutral.dark textinput .selection {
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-neutral .sidebar-menu-button:hover {
|
||||
background-color: rgba(23, 23, 23, 0.1);
|
||||
}
|
||||
|
||||
@@ -199,8 +199,16 @@ static const struct {
|
||||
{ " background-color: rgba(245, 245, 245, 0.15);\n", 47 },
|
||||
{ " color: rgba(245, 245, 245, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-neutral textinput .selection {\n", 39 },
|
||||
{ " background-color: rgba(23, 23, 23, 1);\n", 41 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-neutral.dark textinput .selection {\n", 44 },
|
||||
{ " background-color: rgba(245, 245, 245, 1);\n", 44 },
|
||||
{ " color: rgba(23, 23, 23, 1);\n", 30 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_neutral_total_length = 5522;
|
||||
static const size_t css_str_neutral_total_length = 5757;
|
||||
static inline void ui_load_css_string_neutral_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-orange textinput .selection {
|
||||
background-color: rgba(234, 88, 12, 1);
|
||||
}
|
||||
|
||||
.accent-orange textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-orange.dark textinput .selection {
|
||||
background-color: rgba(251, 146, 60, 1);
|
||||
}
|
||||
|
||||
.accent-orange.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-orange .sidebar-menu-button:hover {
|
||||
background-color: rgba(234, 88, 12, 0.1);
|
||||
}
|
||||
|
||||
@@ -199,8 +199,16 @@ static const struct {
|
||||
{ " background-color: rgba(251, 146, 60, 0.15);\n", 46 },
|
||||
{ " color: rgba(251, 146, 60, 1);\n", 32 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-orange textinput .selection {\n", 38 },
|
||||
{ " background-color: rgba(234, 88, 12, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-orange.dark textinput .selection {\n", 43 },
|
||||
{ " background-color: rgba(251, 146, 60, 1);\n", 43 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_orange_total_length = 5495;
|
||||
static const size_t css_str_orange_total_length = 5731;
|
||||
static inline void ui_load_css_string_orange_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-pink textinput .selection {
|
||||
background-color: rgba(219, 39, 119, 1);
|
||||
}
|
||||
|
||||
.accent-pink textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-pink.dark textinput .selection {
|
||||
background-color: rgba(244, 114, 182, 1);
|
||||
}
|
||||
|
||||
.accent-pink.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-pink .sidebar-menu-button:hover {
|
||||
background-color: rgba(219, 39, 119, 0.1);
|
||||
}
|
||||
|
||||
@@ -195,8 +195,16 @@ static const struct {
|
||||
{ " background-color: rgba(244, 114, 182, 0.15);\n", 47 },
|
||||
{ " color: rgba(244, 114, 182, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-pink textinput .selection {\n", 36 },
|
||||
{ " background-color: rgba(219, 39, 119, 1);\n", 43 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-pink.dark textinput .selection {\n", 41 },
|
||||
{ " background-color: rgba(244, 114, 182, 1);\n", 44 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_pink_total_length = 5429;
|
||||
static const size_t css_str_pink_total_length = 5663;
|
||||
static inline void ui_load_css_string_pink_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-purple textinput .selection {
|
||||
background-color: rgba(147, 51, 234, 1);
|
||||
}
|
||||
|
||||
.accent-purple textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-purple.dark textinput .selection {
|
||||
background-color: rgba(192, 132, 252, 1);
|
||||
}
|
||||
|
||||
.accent-purple.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-purple .sidebar-menu-button:hover {
|
||||
background-color: rgba(147, 51, 234, 0.1);
|
||||
}
|
||||
|
||||
@@ -199,8 +199,16 @@ static const struct {
|
||||
{ " background-color: rgba(192, 132, 252, 0.15);\n", 47 },
|
||||
{ " color: rgba(192, 132, 252, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-purple textinput .selection {\n", 38 },
|
||||
{ " background-color: rgba(147, 51, 234, 1);\n", 43 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-purple.dark textinput .selection {\n", 43 },
|
||||
{ " background-color: rgba(192, 132, 252, 1);\n", 44 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_purple_total_length = 5549;
|
||||
static const size_t css_str_purple_total_length = 5787;
|
||||
static inline void ui_load_css_string_purple_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-red textinput .selection {
|
||||
background-color: rgba(220, 38, 38, 1);
|
||||
}
|
||||
|
||||
.accent-red textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-red.dark textinput .selection {
|
||||
background-color: rgba(248, 113, 113, 1);
|
||||
}
|
||||
|
||||
.accent-red.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-red .sidebar-menu-button:hover {
|
||||
background-color: rgba(220, 38, 38, 0.1);
|
||||
}
|
||||
|
||||
@@ -193,8 +193,16 @@ static const struct {
|
||||
{ " background-color: rgba(248, 113, 113, 0.15);\n", 47 },
|
||||
{ " color: rgba(248, 113, 113, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-red textinput .selection {\n", 35 },
|
||||
{ " background-color: rgba(220, 38, 38, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-red.dark textinput .selection {\n", 40 },
|
||||
{ " background-color: rgba(248, 113, 113, 1);\n", 44 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_red_total_length = 5342;
|
||||
static const size_t css_str_red_total_length = 5573;
|
||||
static inline void ui_load_css_string_red_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-rose textinput .selection {
|
||||
background-color: rgba(225, 29, 72, 1);
|
||||
}
|
||||
|
||||
.accent-rose textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-rose.dark textinput .selection {
|
||||
background-color: rgba(251, 113, 133, 1);
|
||||
}
|
||||
|
||||
.accent-rose.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-rose .sidebar-menu-button:hover {
|
||||
background-color: rgba(225, 29, 72, 0.1);
|
||||
}
|
||||
|
||||
@@ -195,8 +195,16 @@ static const struct {
|
||||
{ " background-color: rgba(251, 113, 133, 0.15);\n", 47 },
|
||||
{ " color: rgba(251, 113, 133, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-rose textinput .selection {\n", 36 },
|
||||
{ " background-color: rgba(225, 29, 72, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-rose.dark textinput .selection {\n", 41 },
|
||||
{ " background-color: rgba(251, 113, 133, 1);\n", 44 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_rose_total_length = 5402;
|
||||
static const size_t css_str_rose_total_length = 5635;
|
||||
static inline void ui_load_css_string_rose_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-sky textinput .selection {
|
||||
background-color: rgba(2, 132, 199, 1);
|
||||
}
|
||||
|
||||
.accent-sky textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-sky.dark textinput .selection {
|
||||
background-color: rgba(56, 189, 248, 1);
|
||||
}
|
||||
|
||||
.accent-sky.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-sky .sidebar-menu-button:hover {
|
||||
background-color: rgba(2, 132, 199, 0.1);
|
||||
}
|
||||
|
||||
@@ -193,8 +193,16 @@ static const struct {
|
||||
{ " background-color: rgba(56, 189, 248, 0.15);\n", 46 },
|
||||
{ " color: rgba(56, 189, 248, 1);\n", 32 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-sky textinput .selection {\n", 35 },
|
||||
{ " background-color: rgba(2, 132, 199, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-sky.dark textinput .selection {\n", 40 },
|
||||
{ " background-color: rgba(56, 189, 248, 1);\n", 43 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_sky_total_length = 5315;
|
||||
static const size_t css_str_sky_total_length = 5545;
|
||||
static inline void ui_load_css_string_sky_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-teal textinput .selection {
|
||||
background-color: rgba(13, 148, 136, 1);
|
||||
}
|
||||
|
||||
.accent-teal textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-teal.dark textinput .selection {
|
||||
background-color: rgba(45, 212, 191, 1);
|
||||
}
|
||||
|
||||
.accent-teal.dark textinput .selection {
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-teal .sidebar-menu-button:hover {
|
||||
background-color: rgba(13, 148, 136, 0.1);
|
||||
}
|
||||
|
||||
@@ -195,8 +195,16 @@ static const struct {
|
||||
{ " background-color: rgba(45, 212, 191, 0.15);\n", 46 },
|
||||
{ " color: rgba(45, 212, 191, 1);\n", 32 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-teal textinput .selection {\n", 36 },
|
||||
{ " background-color: rgba(13, 148, 136, 1);\n", 43 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-teal.dark textinput .selection {\n", 41 },
|
||||
{ " background-color: rgba(45, 212, 191, 1);\n", 43 },
|
||||
{ " color: rgba(23, 23, 23, 1);\n", 30 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_teal_total_length = 5369;
|
||||
static const size_t css_str_teal_total_length = 5599;
|
||||
static inline void ui_load_css_string_teal_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-violet textinput .selection {
|
||||
background-color: rgba(124, 58, 237, 1);
|
||||
}
|
||||
|
||||
.accent-violet textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-violet.dark textinput .selection {
|
||||
background-color: rgba(167, 139, 250, 1);
|
||||
}
|
||||
|
||||
.accent-violet.dark textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-violet .sidebar-menu-button:hover {
|
||||
background-color: rgba(124, 58, 237, 0.1);
|
||||
}
|
||||
|
||||
@@ -199,8 +199,16 @@ static const struct {
|
||||
{ " background-color: rgba(167, 139, 250, 0.15);\n", 47 },
|
||||
{ " color: rgba(167, 139, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-violet textinput .selection {\n", 38 },
|
||||
{ " background-color: rgba(124, 58, 237, 1);\n", 43 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-violet.dark textinput .selection {\n", 43 },
|
||||
{ " background-color: rgba(167, 139, 250, 1);\n", 44 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_violet_total_length = 5549;
|
||||
static const size_t css_str_violet_total_length = 5787;
|
||||
static inline void ui_load_css_string_violet_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -238,6 +238,22 @@
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-yellow textinput .selection {
|
||||
background-color: rgba(202, 138, 4, 1);
|
||||
}
|
||||
|
||||
.accent-yellow textinput .selection {
|
||||
color: rgba(250, 250, 250, 1);
|
||||
}
|
||||
|
||||
.accent-yellow.dark textinput .selection {
|
||||
background-color: rgba(250, 204, 21, 1);
|
||||
}
|
||||
|
||||
.accent-yellow.dark textinput .selection {
|
||||
color: rgba(23, 23, 23, 1);
|
||||
}
|
||||
|
||||
.accent-yellow .sidebar-menu-button:hover {
|
||||
background-color: rgba(202, 138, 4, 0.1);
|
||||
}
|
||||
|
||||
@@ -199,8 +199,16 @@ static const struct {
|
||||
{ " background-color: rgba(250, 204, 21, 0.15);\n", 46 },
|
||||
{ " color: rgba(250, 204, 21, 1);\n", 32 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-yellow textinput .selection {\n", 38 },
|
||||
{ " background-color: rgba(202, 138, 4, 1);\n", 42 },
|
||||
{ " color: rgba(250, 250, 250, 1);\n", 33 },
|
||||
{ "}\n", 2 },
|
||||
{ ".accent-yellow.dark textinput .selection {\n", 43 },
|
||||
{ " background-color: rgba(250, 204, 21, 1);\n", 43 },
|
||||
{ " color: rgba(23, 23, 23, 1);\n", 30 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_yellow_total_length = 5462;
|
||||
static const size_t css_str_yellow_total_length = 5695;
|
||||
static inline void ui_load_css_string_yellow_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -1657,6 +1657,20 @@ textinput {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* textcaret: structural rules live in src/widgets/textcaret.c; its color
|
||||
* follows the theme foreground so it stays visible on every background. */
|
||||
textcaret {
|
||||
@apply bg-foreground dark:bg-foreground-dark;
|
||||
}
|
||||
|
||||
/* textinput selection: solid accent background with its foreground color.
|
||||
* The widget renders this hidden element's computed style over the selection
|
||||
* range and draws the selected glyphs again in the foreground color. */
|
||||
textinput .selection {
|
||||
@apply bg-primary text-primary-foreground;
|
||||
@apply dark:bg-primary-dark dark:text-primary-foreground-dark;
|
||||
}
|
||||
|
||||
textinput:focus {
|
||||
@apply border-foreground dark:border-foreground-dark;
|
||||
box-shadow: theme("boxShadow.focus");
|
||||
|
||||
@@ -2311,6 +2311,12 @@ static const struct {
|
||||
{ "textinput {\r\n", 13 },
|
||||
{ " box-sizing: border-box;\n", 26 },
|
||||
{ "}\n", 2 },
|
||||
{ "textcaret {\r\n", 13 },
|
||||
{ " background-color: #0a0a0a;\n", 29 },
|
||||
{ "}\n", 2 },
|
||||
{ ".dark textcaret {\r\n", 19 },
|
||||
{ " background-color: #fafafa;\n", 29 },
|
||||
{ "}\n", 2 },
|
||||
{ "textinput:focus {\r\n", 19 },
|
||||
{ " border-color: #0a0a0a;\n", 25 },
|
||||
{ "}\n", 2 },
|
||||
@@ -2521,8 +2527,16 @@ static const struct {
|
||||
{ ".dark scrollbar-thumb:active {\r\n", 32 },
|
||||
{ " background-color: rgb(250 250 250 / 0.6);\n", 44 },
|
||||
{ "}\n", 2 },
|
||||
{ "textinput .selection {\r\n", 24 },
|
||||
{ " background-color: #171717;\r\n", 30 },
|
||||
{ " color: #fafafa;\n", 18 },
|
||||
{ "}\n", 2 },
|
||||
{ ".dark textinput .selection {\r\n", 30 },
|
||||
{ " background-color: #fafafa;\r\n", 30 },
|
||||
{ " color: #171717;\n", 18 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_style_nova_total_length = 50776;
|
||||
static const size_t css_str_style_nova_total_length = 51024;
|
||||
static inline void ui_load_css_string_style_nova_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -212,11 +212,15 @@ static bool ui_input_group_is_button(ui_widget_t *target, ui_widget_t *stop)
|
||||
static void ui_input_group_on_focus(ui_widget_t *w, ui_event_t *e, void *arg)
|
||||
{
|
||||
ui_widget_add_status(w, "focused");
|
||||
ui_widget_mark_dirty_rect(w, NULL, UI_BOX_TYPE_GRAPH_BOX);
|
||||
ui_widget_request_update(w);
|
||||
}
|
||||
|
||||
static void ui_input_group_on_blur(ui_widget_t *w, ui_event_t *e, void *arg)
|
||||
{
|
||||
ui_widget_remove_status(w, "focused");
|
||||
ui_widget_mark_dirty_rect(w, NULL, UI_BOX_TYPE_GRAPH_BOX);
|
||||
ui_widget_request_update(w);
|
||||
}
|
||||
|
||||
static void ui_input_group_on_disabled(ui_widget_t *w, ui_event_t *e, void *arg)
|
||||
|
||||
@@ -38,7 +38,6 @@ textcaret {\
|
||||
width: 1px;\
|
||||
height: 14px;\
|
||||
position: absolute;\
|
||||
background-color: #000;\
|
||||
}";
|
||||
|
||||
void ui_textcaret_refresh(ui_widget_t *widget)
|
||||
|
||||
@@ -0,0 +1,789 @@
|
||||
/*
|
||||
* src/widgets/textedit.c: -- text editing state used by textinput.
|
||||
*
|
||||
* Copyright (c) 2026, Liu Chao <hello@lcui.dev> All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* This file is part of LCUI, distributed under the MIT License found
|
||||
* in the LICENSE.TXT file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wctype.h>
|
||||
#include <pandagl.h>
|
||||
#include "textedit.h"
|
||||
|
||||
#define STB_TEXTEDIT_CHARTYPE wchar_t
|
||||
#define STB_TEXTEDIT_NEWLINE L'\n'
|
||||
#define STB_TEXTEDIT_GETWIDTH_NEWLINE (-1)
|
||||
|
||||
#include "third-party/stb_textedit.h"
|
||||
|
||||
typedef struct ui_text_edit {
|
||||
wchar_t *text;
|
||||
int length;
|
||||
int capacity;
|
||||
pd_text_t *layer;
|
||||
STB_TexteditState state;
|
||||
} ui_text_edit_t;
|
||||
|
||||
static bool ui_text_edit_index_to_caret(ui_text_edit_t *edit, int index,
|
||||
int *row, int *col);
|
||||
static int ui_text_edit_eol_length(pd_text_eol_t eol);
|
||||
static void ui_text_edit_on_changed(ui_text_edit_t *edit);
|
||||
|
||||
static void ui_text_edit_rebuild_layer(ui_text_edit_t *edit)
|
||||
{
|
||||
list_t rects;
|
||||
|
||||
if (!edit->layer) {
|
||||
return;
|
||||
}
|
||||
pd_text_clear(edit->layer);
|
||||
if (edit->length > 0) {
|
||||
pd_text_append(edit->layer, edit->text, NULL);
|
||||
}
|
||||
list_create(&rects);
|
||||
pd_text_update(edit->layer, &rects);
|
||||
pd_rects_clear(&rects);
|
||||
}
|
||||
|
||||
void ui_text_edit_sync_caret(ui_text_edit_t *edit)
|
||||
{
|
||||
int row = 0, col = 0;
|
||||
|
||||
if (!edit->layer) {
|
||||
return;
|
||||
}
|
||||
ui_text_edit_index_to_caret(edit, edit->state.cursor, &row, &col);
|
||||
pd_text_set_caret(edit->layer, row, col);
|
||||
}
|
||||
|
||||
void ui_text_edit_sync_layer(ui_text_edit_t *edit)
|
||||
{
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
ui_text_edit_rebuild_layer(edit);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
|
||||
void ui_text_edit_set_layer(ui_text_edit_t *edit, pd_text_t *layer)
|
||||
{
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
edit->layer = layer;
|
||||
ui_text_edit_sync_layer(edit);
|
||||
}
|
||||
|
||||
void ui_text_edit_set_page_rows(ui_text_edit_t *edit, int rows)
|
||||
{
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
edit->state.row_count_per_page = rows > 0 ? rows : 1;
|
||||
}
|
||||
|
||||
int ui_text_edit_get_caret_row(ui_text_edit_t *edit)
|
||||
{
|
||||
return (edit && edit->layer) ? edit->layer->caret.y : 0;
|
||||
}
|
||||
|
||||
int ui_text_edit_get_caret_col(ui_text_edit_t *edit)
|
||||
{
|
||||
return (edit && edit->layer) ? edit->layer->caret.x : 0;
|
||||
}
|
||||
|
||||
static void ui_text_edit_on_changed(ui_text_edit_t *edit)
|
||||
{
|
||||
if (!edit->layer) {
|
||||
return;
|
||||
}
|
||||
ui_text_edit_rebuild_layer(edit);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
|
||||
static bool ui_text_edit_index_to_caret(ui_text_edit_t *edit, int index,
|
||||
int *row, int *col)
|
||||
{
|
||||
int i, start, len, lines;
|
||||
|
||||
*row = 0;
|
||||
*col = 0;
|
||||
if (!edit->layer) {
|
||||
return false;
|
||||
}
|
||||
lines = pd_text_get_lines_length(edit->layer);
|
||||
if (lines <= 0) {
|
||||
return false;
|
||||
}
|
||||
for (i = 0, start = 0; i < lines; ++i) {
|
||||
len = pd_text_get_line_length(edit->layer, i);
|
||||
if (index < start) {
|
||||
continue;
|
||||
}
|
||||
if (index < start + len) {
|
||||
*row = i;
|
||||
*col = index - start;
|
||||
return true;
|
||||
}
|
||||
if (index == start + len) {
|
||||
if (i + 1 < lines &&
|
||||
pd_text_get_line_eol(edit->layer, i) ==
|
||||
PD_TEXT_EOL_NONE) {
|
||||
/* Soft wrap: the index belongs to the next
|
||||
* visual line for display; stb layout uses
|
||||
* layout_row_at for the same boundary. */
|
||||
start += len;
|
||||
continue;
|
||||
}
|
||||
*row = i;
|
||||
*col = len;
|
||||
return true;
|
||||
}
|
||||
start += len + ui_text_edit_eol_length(
|
||||
pd_text_get_line_eol(edit->layer, i));
|
||||
}
|
||||
*row = lines - 1;
|
||||
*col = pd_text_get_line_length(edit->layer, lines - 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int ui_text_edit_reserve(ui_text_edit_t *edit, int capacity)
|
||||
{
|
||||
wchar_t *text;
|
||||
|
||||
if (capacity < 0 || capacity > INT_MAX - 1) {
|
||||
return -1;
|
||||
}
|
||||
if (capacity <= edit->capacity) {
|
||||
return 0;
|
||||
}
|
||||
text = realloc(edit->text, sizeof(wchar_t) * (capacity + 1));
|
||||
if (!text) {
|
||||
return -1;
|
||||
}
|
||||
edit->text = text;
|
||||
edit->capacity = capacity;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ui_text_edit_raw_insert(ui_text_edit_t *edit, int at,
|
||||
const wchar_t *text, int len)
|
||||
{
|
||||
if (len <= 0 || at < 0 || at > edit->length) {
|
||||
return 0;
|
||||
}
|
||||
if (ui_text_edit_reserve(edit, edit->length + len) != 0) {
|
||||
return 0;
|
||||
}
|
||||
memmove(edit->text + at + len, edit->text + at,
|
||||
sizeof(wchar_t) * (edit->length - at));
|
||||
memcpy(edit->text + at, text, sizeof(wchar_t) * len);
|
||||
edit->length += len;
|
||||
edit->text[edit->length] = 0;
|
||||
ui_text_edit_on_changed(edit);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ui_text_edit_raw_delete(ui_text_edit_t *edit, int at, int len)
|
||||
{
|
||||
if (len <= 0 || at < 0 || at + len > edit->length) {
|
||||
return 0;
|
||||
}
|
||||
memmove(edit->text + at, edit->text + at + len,
|
||||
sizeof(wchar_t) * (edit->length - at - len + 1));
|
||||
edit->length -= len;
|
||||
ui_text_edit_on_changed(edit);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ui_text_edit_eol_length(pd_text_eol_t eol)
|
||||
{
|
||||
switch (eol) {
|
||||
case PD_TEXT_EOL_CR:
|
||||
case PD_TEXT_EOL_LF:
|
||||
return 1;
|
||||
case PD_TEXT_EOL_CR_LF:
|
||||
return 2;
|
||||
case PD_TEXT_EOL_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool ui_text_edit_is_high_surrogate(wchar_t ch)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return ch >= 0xD800 && ch <= 0xDBFF;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool ui_text_edit_is_low_surrogate(wchar_t ch)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return ch >= 0xDC00 && ch <= 0xDFFF;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int ui_text_edit_next_index(ui_text_edit_t *edit, int i)
|
||||
{
|
||||
if (i < 0 || i >= edit->length) {
|
||||
return edit->length;
|
||||
}
|
||||
if (i + 1 < edit->length &&
|
||||
ui_text_edit_is_high_surrogate(edit->text[i]) &&
|
||||
ui_text_edit_is_low_surrogate(edit->text[i + 1])) {
|
||||
return i + 2;
|
||||
}
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
static int ui_text_edit_prev_index(ui_text_edit_t *edit, int i)
|
||||
{
|
||||
if (i <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if (i >= 2 && ui_text_edit_is_low_surrogate(edit->text[i - 1]) &&
|
||||
ui_text_edit_is_high_surrogate(edit->text[i - 2])) {
|
||||
return i - 2;
|
||||
}
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
static bool ui_text_edit_layout_row_at(ui_text_edit_t *edit, int at, int *row,
|
||||
int *col)
|
||||
{
|
||||
int i, start, len, lines;
|
||||
|
||||
*row = 0;
|
||||
*col = 0;
|
||||
if (!edit->layer) {
|
||||
return false;
|
||||
}
|
||||
lines = pd_text_get_lines_length(edit->layer);
|
||||
if (lines <= 0) {
|
||||
return false;
|
||||
}
|
||||
for (i = 0, start = 0; i < lines; ++i) {
|
||||
len = pd_text_get_line_length(edit->layer, i);
|
||||
if (at == start) {
|
||||
*row = i;
|
||||
*col = 0;
|
||||
return true;
|
||||
}
|
||||
if (at > start && at < start + len) {
|
||||
*row = i;
|
||||
*col = at - start;
|
||||
return true;
|
||||
}
|
||||
if (at == start + len) {
|
||||
if (i + 1 < lines &&
|
||||
pd_text_get_line_eol(edit->layer, i) ==
|
||||
PD_TEXT_EOL_NONE) {
|
||||
/* Soft wrap: the next visual line starts at
|
||||
* this index, so LAYOUTROW must use it. */
|
||||
start += len;
|
||||
continue;
|
||||
}
|
||||
*row = i;
|
||||
*col = len;
|
||||
return true;
|
||||
}
|
||||
start += len + ui_text_edit_eol_length(
|
||||
pd_text_get_line_eol(edit->layer, i));
|
||||
}
|
||||
*row = lines - 1;
|
||||
*col = pd_text_get_line_length(edit->layer, lines - 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ui_text_edit_layout_row(ui_text_edit_t *edit, int at,
|
||||
StbTexteditRow *row)
|
||||
{
|
||||
int line, col, len;
|
||||
pd_pos_t pos;
|
||||
pd_text_line_t *text_line;
|
||||
|
||||
row->x0 = 0;
|
||||
row->x1 = 0;
|
||||
row->baseline_y_delta = 0;
|
||||
row->ymin = 0;
|
||||
row->ymax = 0;
|
||||
row->num_chars = 0;
|
||||
if (!edit->layer ||
|
||||
!ui_text_edit_layout_row_at(edit, at, &line, &col)) {
|
||||
return;
|
||||
}
|
||||
text_line = edit->layer->lines[line];
|
||||
if (!text_line) {
|
||||
return;
|
||||
}
|
||||
len = text_line->length;
|
||||
if (col > len) {
|
||||
col = len;
|
||||
}
|
||||
row->num_chars =
|
||||
len - col +
|
||||
ui_text_edit_eol_length(pd_text_get_line_eol(edit->layer, line));
|
||||
row->baseline_y_delta =
|
||||
(float)pd_text_get_line_height(edit->layer, line);
|
||||
row->ymin = 0;
|
||||
row->ymax = row->baseline_y_delta;
|
||||
if (pd_text_get_char_pixel(edit->layer, line, 0, &pos) == 0) {
|
||||
row->x0 = (float)pos.x;
|
||||
row->x1 = row->x0 + (float)text_line->width;
|
||||
}
|
||||
}
|
||||
|
||||
static int ui_text_edit_get_width(ui_text_edit_t *edit, int row_start, int i)
|
||||
{
|
||||
int line, col;
|
||||
pd_text_line_t *text_line;
|
||||
pd_char_t *ch;
|
||||
|
||||
if (!edit->layer ||
|
||||
!ui_text_edit_layout_row_at(edit, row_start, &line, &col)) {
|
||||
return 0;
|
||||
}
|
||||
text_line = edit->layer->lines[line];
|
||||
if (!text_line || col + i >= text_line->length) {
|
||||
return STB_TEXTEDIT_GETWIDTH_NEWLINE;
|
||||
}
|
||||
ch = text_line->string[col + i];
|
||||
if (!ch || !ch->bitmap) {
|
||||
return 0;
|
||||
}
|
||||
return ch->bitmap->metrics.hori_advance;
|
||||
}
|
||||
|
||||
#define STB_TEXTEDIT_STRING ui_text_edit_t
|
||||
#define STB_TEXTEDIT_STRINGLEN(e) ((e)->length)
|
||||
#define STB_TEXTEDIT_GETCHAR(e, i) ((e)->text[i])
|
||||
#define STB_TEXTEDIT_INSERTCHARS(e, i, c, n) \
|
||||
ui_text_edit_raw_insert(e, i, c, (int)(n))
|
||||
#define STB_TEXTEDIT_DELETECHARS(e, i, n) \
|
||||
ui_text_edit_raw_delete(e, i, (int)(n))
|
||||
#define STB_TEXTEDIT_LAYOUTROW(r, e, i) ui_text_edit_layout_row(e, i, r)
|
||||
#define STB_TEXTEDIT_GETWIDTH(e, s, i) ui_text_edit_get_width(e, s, i)
|
||||
#define STB_TEXTEDIT_IS_SPACE(ch) iswspace(ch)
|
||||
|
||||
#define STB_TEXTEDIT_K_SHIFT UI_TEXT_EDIT_KEY_SHIFT
|
||||
#define STB_TEXTEDIT_K_LEFT UI_TEXT_EDIT_KEY_LEFT
|
||||
#define STB_TEXTEDIT_K_RIGHT UI_TEXT_EDIT_KEY_RIGHT
|
||||
#define STB_TEXTEDIT_K_UP UI_TEXT_EDIT_KEY_UP
|
||||
#define STB_TEXTEDIT_K_DOWN UI_TEXT_EDIT_KEY_DOWN
|
||||
#define STB_TEXTEDIT_K_PGUP UI_TEXT_EDIT_KEY_PGUP
|
||||
#define STB_TEXTEDIT_K_PGDOWN UI_TEXT_EDIT_KEY_PGDOWN
|
||||
#define STB_TEXTEDIT_K_LINESTART UI_TEXT_EDIT_KEY_LINESTART
|
||||
#define STB_TEXTEDIT_K_LINEEND UI_TEXT_EDIT_KEY_LINEEND
|
||||
#define STB_TEXTEDIT_K_TEXTSTART UI_TEXT_EDIT_KEY_TEXTSTART
|
||||
#define STB_TEXTEDIT_K_TEXTEND UI_TEXT_EDIT_KEY_TEXTEND
|
||||
#define STB_TEXTEDIT_K_DELETE UI_TEXT_EDIT_KEY_DELETE
|
||||
#define STB_TEXTEDIT_K_BACKSPACE UI_TEXT_EDIT_KEY_BACKSPACE
|
||||
#define STB_TEXTEDIT_K_UNDO UI_TEXT_EDIT_KEY_UNDO
|
||||
#define STB_TEXTEDIT_K_REDO UI_TEXT_EDIT_KEY_REDO
|
||||
#define STB_TEXTEDIT_K_WORDLEFT UI_TEXT_EDIT_KEY_WORDLEFT
|
||||
#define STB_TEXTEDIT_K_WORDRIGHT UI_TEXT_EDIT_KEY_WORDRIGHT
|
||||
#define STB_TEXTEDIT_GETPREVCHARINDEX(e, i) ui_text_edit_prev_index(e, i)
|
||||
#define STB_TEXTEDIT_GETNEXTCHARINDEX(e, i) ui_text_edit_next_index(e, i)
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#elif defined(__GNUC__)
|
||||
/* stb_textedit is vendored as-is; it contains helpers (and a dead local) that
|
||||
* our integration does not call. Silence those diagnostics only for the
|
||||
* implementation translation unit so -Werror does not reject the header. */
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#endif
|
||||
#define STB_TEXTEDIT_IMPLEMENTATION
|
||||
#include "third-party/stb_textedit.h"
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#elif defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
ui_text_edit_t *ui_text_edit_create(void)
|
||||
{
|
||||
ui_text_edit_t *edit = calloc(1, sizeof(ui_text_edit_t));
|
||||
|
||||
if (!edit) {
|
||||
return NULL;
|
||||
}
|
||||
ui_text_edit_reserve(edit, 32);
|
||||
stb_textedit_initialize_state(&edit->state, 0);
|
||||
return edit;
|
||||
}
|
||||
|
||||
void ui_text_edit_destroy(ui_text_edit_t *edit)
|
||||
{
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
free(edit->text);
|
||||
free(edit);
|
||||
}
|
||||
|
||||
void ui_text_edit_set_text(ui_text_edit_t *edit, const wchar_t *text,
|
||||
size_t len)
|
||||
{
|
||||
size_t i;
|
||||
int j = 0;
|
||||
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
if (!text) {
|
||||
len = 0;
|
||||
}
|
||||
if (len > (size_t)INT_MAX) {
|
||||
return;
|
||||
}
|
||||
if (ui_text_edit_reserve(edit, (int)len) != 0) {
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (text[i] == L'\r') {
|
||||
if (i + 1 < len && text[i + 1] == L'\n') {
|
||||
++i;
|
||||
}
|
||||
edit->text[j++] = L'\n';
|
||||
} else {
|
||||
edit->text[j++] = text[i];
|
||||
}
|
||||
}
|
||||
edit->length = j;
|
||||
edit->text[edit->length] = 0;
|
||||
stb_textedit_initialize_state(&edit->state, 0);
|
||||
/* Match the previous textinput behavior: after set_text the caret is
|
||||
* at the end, so subsequent typing appends. */
|
||||
edit->state.cursor = edit->length;
|
||||
edit->state.select_start = edit->length;
|
||||
edit->state.select_end = edit->length;
|
||||
ui_text_edit_sync_layer(edit);
|
||||
}
|
||||
|
||||
size_t ui_text_edit_get_text(ui_text_edit_t *edit, size_t start, size_t max_len,
|
||||
wchar_t *buf)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
if (!buf || max_len == 0) {
|
||||
if (buf) {
|
||||
buf[0] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (!edit || start >= (size_t)edit->length) {
|
||||
buf[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
while (n < max_len && start + n < (size_t)edit->length) {
|
||||
buf[n] = edit->text[start + n];
|
||||
++n;
|
||||
}
|
||||
buf[n] = 0;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ui_text_edit_get_length(ui_text_edit_t *edit)
|
||||
{
|
||||
return edit ? (size_t)edit->length : 0;
|
||||
}
|
||||
|
||||
void ui_text_edit_text_input(ui_text_edit_t *edit, const wchar_t *text,
|
||||
size_t len)
|
||||
{
|
||||
size_t i, j;
|
||||
wchar_t *normalized;
|
||||
bool has_cr = false;
|
||||
|
||||
if (!edit || !text || len == 0) {
|
||||
return;
|
||||
}
|
||||
if (len > (size_t)INT_MAX) {
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (text[i] == L'\r') {
|
||||
has_cr = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has_cr) {
|
||||
stb_textedit_text(edit, &edit->state, (wchar_t *)text,
|
||||
(int)len);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
return;
|
||||
}
|
||||
normalized = malloc(sizeof(wchar_t) * (len + 1));
|
||||
if (!normalized) {
|
||||
return;
|
||||
}
|
||||
for (i = 0, j = 0; i < len; ++i) {
|
||||
if (text[i] == L'\r') {
|
||||
if (i + 1 < len && text[i + 1] == L'\n') {
|
||||
++i;
|
||||
}
|
||||
normalized[j++] = L'\n';
|
||||
} else {
|
||||
normalized[j++] = text[i];
|
||||
}
|
||||
}
|
||||
stb_textedit_text(edit, &edit->state, normalized, (int)j);
|
||||
free(normalized);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
|
||||
void ui_text_edit_key(ui_text_edit_t *edit, int key)
|
||||
{
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
stb_textedit_key(edit, &edit->state, key);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
|
||||
static int ui_text_edit_clamp_index(ui_text_edit_t *edit, int index)
|
||||
{
|
||||
if (index < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (index > edit->length) {
|
||||
return edit->length;
|
||||
}
|
||||
if (index > 0 && index < edit->length &&
|
||||
ui_text_edit_is_low_surrogate(edit->text[index]) &&
|
||||
ui_text_edit_is_high_surrogate(edit->text[index - 1])) {
|
||||
--index;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
void ui_text_edit_move_caret_extend(ui_text_edit_t *edit, int row, int col,
|
||||
bool extend)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
if (edit->layer) {
|
||||
int lines = pd_text_get_lines_length(edit->layer);
|
||||
if (row < 0) {
|
||||
row = 0;
|
||||
} else if (lines > 0 && row >= lines) {
|
||||
row = lines - 1;
|
||||
}
|
||||
index = pd_text_get_line_char_start(edit->layer, row);
|
||||
col = pd_text_get_line_length(edit->layer, row) < col
|
||||
? pd_text_get_line_length(edit->layer, row)
|
||||
: col;
|
||||
if (col < 0) {
|
||||
col = 0;
|
||||
}
|
||||
index += col;
|
||||
}
|
||||
index = ui_text_edit_clamp_index(edit, index);
|
||||
if (extend) {
|
||||
if (edit->state.select_start == edit->state.select_end) {
|
||||
edit->state.select_start = edit->state.cursor;
|
||||
}
|
||||
edit->state.cursor = index;
|
||||
edit->state.select_end = index;
|
||||
} else {
|
||||
edit->state.cursor = index;
|
||||
edit->state.select_start = index;
|
||||
edit->state.select_end = index;
|
||||
}
|
||||
edit->state.has_preferred_x = 0;
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
|
||||
void ui_text_edit_move_caret(ui_text_edit_t *edit, int row, int col)
|
||||
{
|
||||
ui_text_edit_move_caret_extend(edit, row, col, false);
|
||||
}
|
||||
|
||||
void ui_text_edit_move_vertical(ui_text_edit_t *edit, int delta, bool extend)
|
||||
{
|
||||
int row, col, lines, target, i, start, len, best_col = 0;
|
||||
int target_x, best_dx = INT_MAX;
|
||||
pd_pos_t pos;
|
||||
|
||||
if (!edit || !edit->layer || delta == 0) {
|
||||
return;
|
||||
}
|
||||
ui_text_edit_index_to_caret(edit, edit->state.cursor, &row, &col);
|
||||
if (!edit->state.has_preferred_x) {
|
||||
if (pd_text_get_char_pixel(edit->layer, row, col, &pos) != 0) {
|
||||
return;
|
||||
}
|
||||
edit->state.preferred_x = (float)pos.x;
|
||||
edit->state.has_preferred_x = 1;
|
||||
}
|
||||
target_x = (int)edit->state.preferred_x;
|
||||
lines = pd_text_get_lines_length(edit->layer);
|
||||
target = row + delta;
|
||||
if (target < 0) {
|
||||
target = 0;
|
||||
} else if (target >= lines) {
|
||||
target = lines - 1;
|
||||
}
|
||||
start = pd_text_get_line_char_start(edit->layer, target);
|
||||
len = pd_text_get_line_length(edit->layer, target);
|
||||
for (i = 0; i <= len; ++i) {
|
||||
int dx;
|
||||
|
||||
if (pd_text_get_char_pixel(edit->layer, target, i, &pos) != 0) {
|
||||
break;
|
||||
}
|
||||
dx = pos.x - target_x;
|
||||
if (dx < 0) {
|
||||
dx = -dx;
|
||||
}
|
||||
if (dx < best_dx) {
|
||||
best_dx = dx;
|
||||
best_col = i;
|
||||
}
|
||||
}
|
||||
if (extend) {
|
||||
if (edit->state.select_start == edit->state.select_end) {
|
||||
edit->state.select_start = edit->state.cursor;
|
||||
}
|
||||
edit->state.cursor =
|
||||
ui_text_edit_clamp_index(edit, start + best_col);
|
||||
edit->state.select_end = edit->state.cursor;
|
||||
} else {
|
||||
edit->state.cursor =
|
||||
ui_text_edit_clamp_index(edit, start + best_col);
|
||||
edit->state.select_start = edit->state.cursor;
|
||||
edit->state.select_end = edit->state.cursor;
|
||||
}
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
|
||||
void ui_text_edit_append_text(ui_text_edit_t *edit, const wchar_t *text,
|
||||
size_t len)
|
||||
{
|
||||
if (!edit || !text || len == 0 || len > (size_t)INT_MAX) {
|
||||
return;
|
||||
}
|
||||
edit->state.cursor = edit->length;
|
||||
edit->state.select_start = edit->length;
|
||||
edit->state.select_end = edit->length;
|
||||
ui_text_edit_text_input(edit, text, len);
|
||||
}
|
||||
|
||||
void ui_text_edit_click(ui_text_edit_t *edit, float x, float y)
|
||||
{
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
stb_textedit_click(edit, &edit->state, x, y);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
|
||||
void ui_text_edit_drag(ui_text_edit_t *edit, float x, float y)
|
||||
{
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
stb_textedit_drag(edit, &edit->state, x, y);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
|
||||
bool ui_text_edit_has_selection(ui_text_edit_t *edit)
|
||||
{
|
||||
return edit && edit->state.select_start != edit->state.select_end;
|
||||
}
|
||||
|
||||
void ui_text_edit_selection(ui_text_edit_t *edit, size_t *start, size_t *end)
|
||||
{
|
||||
size_t a = 0, b = 0;
|
||||
|
||||
if (edit) {
|
||||
a = (size_t)edit->state.select_start;
|
||||
b = (size_t)edit->state.select_end;
|
||||
}
|
||||
if (a > b) {
|
||||
size_t tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
if (start) {
|
||||
*start = a;
|
||||
}
|
||||
if (end) {
|
||||
*end = b;
|
||||
}
|
||||
}
|
||||
|
||||
void ui_text_edit_select_all(ui_text_edit_t *edit)
|
||||
{
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
edit->state.select_start = 0;
|
||||
edit->state.select_end = edit->length;
|
||||
edit->state.cursor = edit->length;
|
||||
edit->state.has_preferred_x = 0;
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
|
||||
void ui_text_edit_clear_selection(ui_text_edit_t *edit)
|
||||
{
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
edit->state.select_start = edit->state.cursor;
|
||||
edit->state.select_end = edit->state.cursor;
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
|
||||
size_t ui_text_edit_copy(ui_text_edit_t *edit, wchar_t *buf, size_t max_len)
|
||||
{
|
||||
size_t start, end, n = 0;
|
||||
|
||||
if (!buf || max_len == 0) {
|
||||
if (buf) {
|
||||
buf[0] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
ui_text_edit_selection(edit, &start, &end);
|
||||
if (!edit) {
|
||||
buf[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
while (n < max_len && start + n < end) {
|
||||
buf[n] = edit->text[start + n];
|
||||
++n;
|
||||
}
|
||||
buf[n] = 0;
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ui_text_edit_cut(ui_text_edit_t *edit, wchar_t *buf, size_t max_len)
|
||||
{
|
||||
size_t n = ui_text_edit_copy(edit, buf, max_len);
|
||||
|
||||
if (edit) {
|
||||
stb_textedit_cut(edit, &edit->state);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* src/widgets/textedit.h: -- text editing state used by textinput.
|
||||
*
|
||||
* Copyright (c) 2026, Liu Chao <hello@lcui.dev> All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* This file is part of LCUI, distributed under the MIT License found
|
||||
* in the LICENSE.TXT file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#ifndef LCUI_WIDGETS_TEXTEDIT_H
|
||||
#define LCUI_WIDGETS_TEXTEDIT_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <wchar.h>
|
||||
#include <pandagl/text.h>
|
||||
|
||||
/* Keyboard input is encoded as a single integer. The shift state must be a
|
||||
* power of two. Character input is submitted through
|
||||
* ui_text_edit_text_input() instead of these key values. */
|
||||
typedef enum ui_text_edit_key {
|
||||
UI_TEXT_EDIT_KEY_LEFT = 0x00000001,
|
||||
UI_TEXT_EDIT_KEY_RIGHT = 0x00000002,
|
||||
UI_TEXT_EDIT_KEY_UP = 0x00000003,
|
||||
UI_TEXT_EDIT_KEY_DOWN = 0x00000004,
|
||||
UI_TEXT_EDIT_KEY_PGUP = 0x00000005,
|
||||
UI_TEXT_EDIT_KEY_PGDOWN = 0x00000006,
|
||||
UI_TEXT_EDIT_KEY_LINESTART = 0x00000007,
|
||||
UI_TEXT_EDIT_KEY_LINEEND = 0x00000008,
|
||||
UI_TEXT_EDIT_KEY_TEXTSTART = 0x00000009,
|
||||
UI_TEXT_EDIT_KEY_TEXTEND = 0x0000000a,
|
||||
UI_TEXT_EDIT_KEY_DELETE = 0x0000000b,
|
||||
UI_TEXT_EDIT_KEY_BACKSPACE = 0x0000000c,
|
||||
UI_TEXT_EDIT_KEY_UNDO = 0x0000000d,
|
||||
UI_TEXT_EDIT_KEY_REDO = 0x0000000e,
|
||||
UI_TEXT_EDIT_KEY_WORDLEFT = 0x0000000f,
|
||||
UI_TEXT_EDIT_KEY_WORDRIGHT = 0x00000010,
|
||||
UI_TEXT_EDIT_KEY_SHIFT = 0x20000000
|
||||
} ui_text_edit_key_t;
|
||||
|
||||
typedef struct ui_text_edit ui_text_edit_t;
|
||||
|
||||
ui_text_edit_t *ui_text_edit_create(void);
|
||||
void ui_text_edit_destroy(ui_text_edit_t *edit);
|
||||
|
||||
/** Replace the whole text. CRLF and CR are normalized to LF. */
|
||||
void ui_text_edit_set_text(ui_text_edit_t *edit, const wchar_t *text,
|
||||
size_t len);
|
||||
|
||||
/** Copy up to max_len characters starting at start. Returns copied count. */
|
||||
size_t ui_text_edit_get_text(ui_text_edit_t *edit, size_t start, size_t max_len,
|
||||
wchar_t *buf);
|
||||
|
||||
size_t ui_text_edit_get_length(ui_text_edit_t *edit);
|
||||
|
||||
/** Insert committed text at the cursor (IME / paste / typing). */
|
||||
void ui_text_edit_text_input(ui_text_edit_t *edit, const wchar_t *text,
|
||||
size_t len);
|
||||
|
||||
/** Send a navigation or editing key, e.g. UI_TEXT_EDIT_KEY_BACKSPACE. */
|
||||
void ui_text_edit_key(ui_text_edit_t *edit, int key);
|
||||
|
||||
/** Move the caret to a visual row/column. */
|
||||
void ui_text_edit_move_caret(ui_text_edit_t *edit, int row, int col);
|
||||
|
||||
/** Move the caret to a visual row/column, optionally extending the selection.
|
||||
*/
|
||||
void ui_text_edit_move_caret_extend(ui_text_edit_t *edit, int row, int col,
|
||||
bool extend);
|
||||
|
||||
/** Move the caret up/down by visual rows, keeping the preferred x. */
|
||||
void ui_text_edit_move_vertical(ui_text_edit_t *edit, int delta, bool extend);
|
||||
|
||||
/** Append text at the end regardless of the current caret. */
|
||||
void ui_text_edit_append_text(ui_text_edit_t *edit, const wchar_t *text,
|
||||
size_t len);
|
||||
|
||||
/** Mouse click/drag, in text-layer pixel coordinates (origin = text top-left).
|
||||
*/
|
||||
void ui_text_edit_click(ui_text_edit_t *edit, float x, float y);
|
||||
void ui_text_edit_drag(ui_text_edit_t *edit, float x, float y);
|
||||
|
||||
bool ui_text_edit_has_selection(ui_text_edit_t *edit);
|
||||
void ui_text_edit_selection(ui_text_edit_t *edit, size_t *start, size_t *end);
|
||||
void ui_text_edit_select_all(ui_text_edit_t *edit);
|
||||
void ui_text_edit_clear_selection(ui_text_edit_t *edit);
|
||||
size_t ui_text_edit_copy(ui_text_edit_t *edit, wchar_t *buf, size_t max_len);
|
||||
size_t ui_text_edit_cut(ui_text_edit_t *edit, wchar_t *buf, size_t max_len);
|
||||
|
||||
/* Layout projection: the pd_text layer is rebuilt from the canonical text
|
||||
* after every edit, and the stb caret index is mapped to its visual row/col. */
|
||||
void ui_text_edit_set_layer(ui_text_edit_t *edit, pd_text_t *layer);
|
||||
void ui_text_edit_set_page_rows(ui_text_edit_t *edit, int rows);
|
||||
void ui_text_edit_sync_layer(ui_text_edit_t *edit);
|
||||
void ui_text_edit_sync_caret(ui_text_edit_t *edit);
|
||||
int ui_text_edit_get_caret_row(ui_text_edit_t *edit);
|
||||
int ui_text_edit_get_caret_col(ui_text_edit_t *edit);
|
||||
|
||||
#endif
|
||||
+757
-451
File diff suppressed because it is too large
Load Diff
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
# stb_textedit
|
||||
|
||||
- Upstream: <https://github.com/nothings/stb>
|
||||
- Vendored file: `stb_textedit.h`
|
||||
- Version: v1.16 (2026-11-12)
|
||||
- License: MIT OR public domain (see the end of `stb_textedit.h`)
|
||||
|
||||
The file is vendored unchanged. To update it, replace the file, record the new
|
||||
version here, and re-run the textinput edit tests.
|
||||
+1662
File diff suppressed because it is too large
Load Diff
@@ -606,6 +606,35 @@ static void check_link_button_has_no_background_in_dark(void)
|
||||
ui_clear_trash();
|
||||
}
|
||||
|
||||
static void check_textcaret_follows_theme_foreground(void)
|
||||
{
|
||||
ui_widget_t *input = ui_create_widget("textinput");
|
||||
ui_widget_t *caret;
|
||||
|
||||
ui_widget_append(ui_root(), input);
|
||||
ui_update();
|
||||
caret = ui_widget_get_child(input, 0);
|
||||
ctest_equal_bool("light caret should match the text foreground",
|
||||
caret->computed_style.background_color ==
|
||||
input->computed_style.color,
|
||||
true);
|
||||
ctest_equal_bool(
|
||||
"light caret should not use the old black color",
|
||||
caret->computed_style.background_color != css_color(255, 0, 0, 0),
|
||||
true);
|
||||
|
||||
ui_widget_add_class(ui_root(), "dark");
|
||||
ui_update();
|
||||
ctest_equal_bool("dark caret should match the text foreground",
|
||||
caret->computed_style.background_color ==
|
||||
input->computed_style.color,
|
||||
true);
|
||||
|
||||
ui_widget_remove_class(ui_root(), "dark");
|
||||
ui_widget_destroy(input);
|
||||
ui_clear_trash();
|
||||
}
|
||||
|
||||
void test_style_nova(void)
|
||||
{
|
||||
lcui_init();
|
||||
@@ -636,6 +665,7 @@ void test_style_nova(void)
|
||||
ctest_describe("style-nova: toast", check_toast_theme);
|
||||
ctest_describe("style-nova: card", check_card_theme);
|
||||
ctest_describe("style-nova: attachment", check_attachment_theme);
|
||||
|
||||
ctest_describe("style-nova: textcaret",
|
||||
check_textcaret_follows_theme_foreground);
|
||||
lcui_destroy();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* tests/integration/test_textinput_edit.c
|
||||
*
|
||||
* Copyright (c) 2026, Liu Chao <hello@lcui.dev> All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* This file is part of LCUI, distributed under the MIT License found
|
||||
* in the LICENSE.TXT file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <LCUI.h>
|
||||
#include <ctest-custom.h>
|
||||
#include "../../src/widgets/textedit.h"
|
||||
|
||||
static void check_text_edit_core(void)
|
||||
{
|
||||
ui_text_edit_t *edit = ui_text_edit_create();
|
||||
wchar_t buf[16];
|
||||
|
||||
ui_text_edit_set_text(edit, L"hello", 5);
|
||||
ctest_equal_int("should store text length",
|
||||
(int)ui_text_edit_get_length(edit), 5);
|
||||
ctest_equal_int("should read text back",
|
||||
(int)ui_text_edit_get_text(edit, 0, 16, buf), 5);
|
||||
ctest_equal_wcs("should return the identical text", buf, L"hello");
|
||||
|
||||
ui_text_edit_text_input(edit, L"!", 1);
|
||||
ctest_equal_int("text input should insert at the cursor",
|
||||
(int)ui_text_edit_get_length(edit), 6);
|
||||
ctest_equal_int("should read the inserted text",
|
||||
(int)ui_text_edit_get_text(edit, 0, 16, buf), 6);
|
||||
ctest_equal_wcs("should append the input text", buf, L"hello!");
|
||||
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_BACKSPACE);
|
||||
ctest_equal_int("backspace should delete one character",
|
||||
(int)ui_text_edit_get_length(edit), 5);
|
||||
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_UNDO);
|
||||
ctest_equal_int("undo should restore the deleted character",
|
||||
(int)ui_text_edit_get_length(edit), 6);
|
||||
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_REDO);
|
||||
ctest_equal_int("redo should delete it again",
|
||||
(int)ui_text_edit_get_length(edit), 5);
|
||||
|
||||
ui_text_edit_destroy(edit);
|
||||
}
|
||||
|
||||
static void check_layer_mapping(void)
|
||||
{
|
||||
pd_text_t *layer = pd_text_create();
|
||||
ui_text_edit_t *edit = ui_text_edit_create();
|
||||
wchar_t buf[16];
|
||||
|
||||
pd_text_set_multiline(layer, true);
|
||||
pd_text_set_fixed_size(layer, 200, 100);
|
||||
pd_text_set_max_size(layer, 200, 100);
|
||||
ui_text_edit_set_layer(edit, layer);
|
||||
ui_text_edit_set_text(edit, L"abc\ndef", 7);
|
||||
ui_text_edit_sync_layer(edit);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
/* set_text leaves the caret at the end of the text */
|
||||
ctest_equal_int("caret should start at the last line",
|
||||
ui_text_edit_get_caret_row(edit), 1);
|
||||
ctest_equal_int("caret should start at the line end",
|
||||
ui_text_edit_get_caret_col(edit), 3);
|
||||
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_LEFT);
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_LEFT);
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_LEFT);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
ctest_equal_int("left should stay on the same line",
|
||||
ui_text_edit_get_caret_row(edit), 1);
|
||||
ctest_equal_int("left should reach the line start",
|
||||
ui_text_edit_get_caret_col(edit), 0);
|
||||
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_LEFT);
|
||||
ui_text_edit_sync_caret(edit);
|
||||
ctest_equal_int("crossing the newline should land on the previous line",
|
||||
ui_text_edit_get_caret_row(edit), 0);
|
||||
ctest_equal_int("crossing the newline should land at the line end",
|
||||
ui_text_edit_get_caret_col(edit), 3);
|
||||
|
||||
ui_text_edit_move_caret(edit, 1, 0);
|
||||
ui_text_edit_text_input(edit, L"X", 1);
|
||||
ui_text_edit_get_text(edit, 0, 16, buf);
|
||||
ctest_equal_wcs("move_caret should place typing at the visual line",
|
||||
buf, L"abc\nXdef");
|
||||
ui_text_edit_append_text(edit, L"!", 1);
|
||||
ui_text_edit_get_text(edit, 0, 16, buf);
|
||||
ctest_equal_wcs("append_text should always append at the end", buf,
|
||||
L"abc\nXdef!");
|
||||
|
||||
ui_text_edit_destroy(edit);
|
||||
pd_text_destroy(layer);
|
||||
}
|
||||
|
||||
static void check_layout_queries(void)
|
||||
{
|
||||
pd_text_t *layer = pd_text_create();
|
||||
ui_text_edit_t *edit = ui_text_edit_create();
|
||||
pd_text_style_t style;
|
||||
int line_h;
|
||||
size_t start, end;
|
||||
|
||||
pd_text_style_init(&style);
|
||||
pd_text_style_set_default_font(&style);
|
||||
pd_text_style_set_size(&style, 14);
|
||||
pd_text_set_style(layer, &style);
|
||||
pd_text_style_destroy(&style);
|
||||
pd_text_set_multiline(layer, true);
|
||||
pd_text_set_fixed_size(layer, 200, 100);
|
||||
pd_text_set_max_size(layer, 200, 100);
|
||||
ui_text_edit_set_layer(edit, layer);
|
||||
ui_text_edit_set_text(edit, L"abc\ndef", 7);
|
||||
|
||||
ui_text_edit_click(edit, 0, 0);
|
||||
ctest_equal_int("click should land on the first row",
|
||||
ui_text_edit_get_caret_row(edit), 0);
|
||||
ctest_equal_int("click should land at the row start",
|
||||
ui_text_edit_get_caret_col(edit), 0);
|
||||
|
||||
line_h = pd_text_get_line_height(layer, 0);
|
||||
ui_text_edit_click(edit, 0, (float)line_h + 1);
|
||||
ctest_equal_int("click should land on the second row",
|
||||
ui_text_edit_get_caret_row(edit), 1);
|
||||
ctest_equal_int("click should land at the second row start",
|
||||
ui_text_edit_get_caret_col(edit), 0);
|
||||
|
||||
ui_text_edit_move_caret(edit, 0, 0);
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_RIGHT | UI_TEXT_EDIT_KEY_SHIFT);
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_RIGHT | UI_TEXT_EDIT_KEY_SHIFT);
|
||||
ctest_equal_bool("shift-right should create a selection",
|
||||
ui_text_edit_has_selection(edit), true);
|
||||
ui_text_edit_selection(edit, &start, &end);
|
||||
ctest_equal_int("selection should start at the caret origin",
|
||||
(int)start, 0);
|
||||
ctest_equal_int("selection should cover two characters", (int)end, 2);
|
||||
|
||||
ui_text_edit_destroy(edit);
|
||||
pd_text_destroy(layer);
|
||||
}
|
||||
|
||||
static void check_selection_operations(void)
|
||||
{
|
||||
ui_text_edit_t *edit = ui_text_edit_create();
|
||||
wchar_t buf[16];
|
||||
size_t start, end;
|
||||
|
||||
ui_text_edit_set_text(edit, L"hello", 5);
|
||||
ui_text_edit_select_all(edit);
|
||||
ctest_equal_bool("select-all should select the whole text",
|
||||
ui_text_edit_has_selection(edit), true);
|
||||
ui_text_edit_selection(edit, &start, &end);
|
||||
ctest_equal_int("select-all start", (int)start, 0);
|
||||
ctest_equal_int("select-all end", (int)end, 5);
|
||||
ctest_equal_int("copy should return the selected length",
|
||||
(int)ui_text_edit_copy(edit, buf, 16), 5);
|
||||
ctest_equal_wcs("copy should return the selected text", buf, L"hello");
|
||||
|
||||
ctest_equal_int("cut should return the selected length",
|
||||
(int)ui_text_edit_cut(edit, buf, 16), 5);
|
||||
ctest_equal_int("cut should remove the selection",
|
||||
(int)ui_text_edit_get_length(edit), 0);
|
||||
ctest_equal_bool("cut should clear the selection",
|
||||
ui_text_edit_has_selection(edit), false);
|
||||
|
||||
ui_text_edit_destroy(edit);
|
||||
}
|
||||
|
||||
static void check_crlf_and_surrogates(void)
|
||||
{
|
||||
pd_text_t *layer = pd_text_create();
|
||||
ui_text_edit_t *edit = ui_text_edit_create();
|
||||
pd_text_style_t style;
|
||||
wchar_t buf[32];
|
||||
|
||||
pd_text_style_init(&style);
|
||||
pd_text_style_set_default_font(&style);
|
||||
pd_text_style_set_size(&style, 14);
|
||||
pd_text_set_style(layer, &style);
|
||||
pd_text_style_destroy(&style);
|
||||
pd_text_set_multiline(layer, true);
|
||||
pd_text_set_fixed_size(layer, 200, 100);
|
||||
pd_text_set_max_size(layer, 200, 100);
|
||||
ui_text_edit_set_layer(edit, layer);
|
||||
|
||||
ui_text_edit_set_text(edit, L"a\r\nb", 4);
|
||||
ctest_equal_int("set_text should normalize CRLF",
|
||||
(int)ui_text_edit_get_length(edit), 3);
|
||||
ui_text_edit_get_text(edit, 0, 32, buf);
|
||||
ctest_equal_wcs("set_text should keep LF only", buf, L"a\nb");
|
||||
|
||||
ui_text_edit_set_text(edit, L"", 0);
|
||||
ui_text_edit_text_input(edit, L"a\r\nb", 4);
|
||||
ctest_equal_int("text input should normalize CRLF",
|
||||
(int)ui_text_edit_get_length(edit), 3);
|
||||
ui_text_edit_get_text(edit, 0, 32, buf);
|
||||
ctest_equal_wcs("text input should keep LF only", buf, L"a\nb");
|
||||
|
||||
#if defined(_WIN32)
|
||||
{
|
||||
wchar_t emoji[4] = { 0xD83D, 0xDE00, L'a', 0 };
|
||||
|
||||
ui_text_edit_set_text(edit, emoji, 3);
|
||||
ctest_equal_int("emoji text should keep three code units",
|
||||
(int)ui_text_edit_get_length(edit), 3);
|
||||
ui_text_edit_move_caret(edit, 0, 3);
|
||||
ctest_equal_int("move_caret should reach the text end",
|
||||
ui_text_edit_get_caret_col(edit), 3);
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_LEFT);
|
||||
ctest_equal_int("left should stop before the trailing letter",
|
||||
ui_text_edit_get_caret_col(edit), 2);
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_LEFT);
|
||||
ctest_equal_int("left should skip the surrogate pair",
|
||||
ui_text_edit_get_caret_col(edit), 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
ui_text_edit_destroy(edit);
|
||||
pd_text_destroy(layer);
|
||||
}
|
||||
|
||||
static void check_soft_wrap_queries(void)
|
||||
{
|
||||
pd_text_t *layer = pd_text_create();
|
||||
ui_text_edit_t *edit = ui_text_edit_create();
|
||||
pd_text_style_t style;
|
||||
int line_len;
|
||||
|
||||
pd_text_style_init(&style);
|
||||
pd_text_style_set_default_font(&style);
|
||||
pd_text_style_set_size(&style, 14);
|
||||
pd_text_set_style(layer, &style);
|
||||
pd_text_style_destroy(&style);
|
||||
pd_text_set_multiline(layer, true);
|
||||
pd_text_set_autowrap(layer, true);
|
||||
pd_text_set_word_break(layer, PD_WORD_BREAK_BREAK_ALL);
|
||||
pd_text_set_fixed_size(layer, 40, 100);
|
||||
pd_text_set_max_size(layer, 40, 100);
|
||||
ui_text_edit_set_layer(edit, layer);
|
||||
ui_text_edit_set_text(edit, L"aaaaaaaaaaaaaaaa", 16);
|
||||
|
||||
ctest_equal_bool("narrow layer should wrap into several lines",
|
||||
pd_text_get_lines_length(layer) >= 2, true);
|
||||
line_len = pd_text_get_line_length(layer, 0);
|
||||
ctest_equal_int("soft wrap should not consume characters",
|
||||
pd_text_get_line_char_start(layer, 1), line_len);
|
||||
|
||||
ui_text_edit_move_caret(edit, 0, line_len);
|
||||
ctest_equal_int("soft boundary should map to the next visual row",
|
||||
ui_text_edit_get_caret_row(edit), 1);
|
||||
ctest_equal_int("soft boundary should map to the next row start",
|
||||
ui_text_edit_get_caret_col(edit), 0);
|
||||
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_DOWN);
|
||||
ctest_equal_int("down from a soft boundary should move one row",
|
||||
ui_text_edit_get_caret_row(edit), 2);
|
||||
|
||||
ui_text_edit_move_caret(edit, 1, line_len);
|
||||
ctest_equal_int("second boundary should map to row 2",
|
||||
ui_text_edit_get_caret_row(edit), 2);
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_UP);
|
||||
ctest_equal_int("up from a boundary should move one row up",
|
||||
ui_text_edit_get_caret_row(edit), 1);
|
||||
|
||||
ui_text_edit_move_caret(edit, 0, 0);
|
||||
ui_text_edit_key(edit, UI_TEXT_EDIT_KEY_DOWN);
|
||||
ctest_equal_int("down should cross a soft wrap",
|
||||
ui_text_edit_get_caret_row(edit), 1);
|
||||
|
||||
ui_text_edit_destroy(edit);
|
||||
pd_text_destroy(layer);
|
||||
}
|
||||
|
||||
static void check_vertical_movement(void)
|
||||
{
|
||||
pd_text_t *layer = pd_text_create();
|
||||
ui_text_edit_t *edit = ui_text_edit_create();
|
||||
pd_text_style_t style;
|
||||
size_t start, end;
|
||||
|
||||
pd_text_style_init(&style);
|
||||
pd_text_style_set_default_font(&style);
|
||||
pd_text_style_set_size(&style, 14);
|
||||
pd_text_set_style(layer, &style);
|
||||
pd_text_style_destroy(&style);
|
||||
pd_text_set_multiline(layer, true);
|
||||
pd_text_set_fixed_size(layer, 200, 100);
|
||||
pd_text_set_max_size(layer, 200, 100);
|
||||
ui_text_edit_set_layer(edit, layer);
|
||||
ui_text_edit_set_text(edit, L"abcdef\nxy\nabcdef", 15);
|
||||
|
||||
ui_text_edit_move_caret(edit, 0, 4);
|
||||
ui_text_edit_move_vertical(edit, 1, false);
|
||||
ctest_equal_int("vertical should land on the short line",
|
||||
ui_text_edit_get_caret_row(edit), 1);
|
||||
ctest_equal_int("vertical should clamp to the short line end",
|
||||
ui_text_edit_get_caret_col(edit), 2);
|
||||
|
||||
ui_text_edit_move_vertical(edit, 1, false);
|
||||
ctest_equal_int("vertical should reach the third line",
|
||||
ui_text_edit_get_caret_row(edit), 2);
|
||||
ctest_equal_int("vertical should restore the preferred column",
|
||||
ui_text_edit_get_caret_col(edit), 4);
|
||||
|
||||
ui_text_edit_move_vertical(edit, -1, true);
|
||||
ctest_equal_bool("shift+vertical should create a selection",
|
||||
ui_text_edit_has_selection(edit), true);
|
||||
ui_text_edit_selection(edit, &start, &end);
|
||||
ctest_equal_bool("selection should span the vertical range",
|
||||
start != end, true);
|
||||
|
||||
#if defined(_WIN32)
|
||||
{
|
||||
wchar_t emoji[4] = { 0xD83D, 0xDE00, L'a', 0 };
|
||||
|
||||
ui_text_edit_set_text(edit, emoji, 3);
|
||||
ui_text_edit_move_caret(edit, 0, 1);
|
||||
ctest_equal_int("move_caret should not split a surrogate pair",
|
||||
ui_text_edit_get_caret_col(edit), 0);
|
||||
ui_text_edit_move_caret(edit, 0, 2);
|
||||
ctest_equal_int("move_caret should keep the pair boundary",
|
||||
ui_text_edit_get_caret_col(edit), 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
ui_text_edit_destroy(edit);
|
||||
pd_text_destroy(layer);
|
||||
}
|
||||
|
||||
void test_textinput_edit(void)
|
||||
{
|
||||
lcui_init();
|
||||
ctest_describe("text edit core", check_text_edit_core);
|
||||
ctest_describe("text edit layer mapping", check_layer_mapping);
|
||||
ctest_describe("text edit layout queries", check_layout_queries);
|
||||
ctest_describe("text edit selection operations",
|
||||
check_selection_operations);
|
||||
ctest_describe("text edit crlf and surrogates",
|
||||
check_crlf_and_surrogates);
|
||||
ctest_describe("text edit soft wrap", check_soft_wrap_queries);
|
||||
ctest_describe("text edit vertical movement", check_vertical_movement);
|
||||
lcui_destroy();
|
||||
}
|
||||
@@ -24,6 +24,7 @@ extern void test_css_unload(void);
|
||||
extern void test_text_resize(void);
|
||||
extern void test_text_decoration(void);
|
||||
extern void test_textinput(void);
|
||||
extern void test_textinput_edit(void);
|
||||
extern void test_font_face(void);
|
||||
extern void test_widget_opacity(void);
|
||||
extern void test_widget_status(void);
|
||||
@@ -93,6 +94,7 @@ static const ctest_suite_t suites[] = {
|
||||
{ "text resize", test_text_resize },
|
||||
{ "text decoration", test_text_decoration },
|
||||
{ "textinput", test_textinput },
|
||||
{ "textinput edit", test_textinput_edit },
|
||||
{ "font face", test_font_face },
|
||||
{ "widget opacity", test_widget_opacity },
|
||||
{ "widget status", test_widget_status },
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* tests/previews/preview_textinput_edit.c
|
||||
*
|
||||
* Copyright (c) 2026, Liu Chao <hello@lcui.dev> All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* This file is part of LCUI, distributed under the MIT License found in the
|
||||
* LICENSE.TXT file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <LCUI.h>
|
||||
#include "preview_window.h"
|
||||
|
||||
static ui_widget_t *add_input(const char *left, const char *top,
|
||||
const char *width, const char *height)
|
||||
{
|
||||
ui_widget_t *input = ui_create_widget("textinput");
|
||||
|
||||
ui_widget_set_style_string(input, "position", "absolute");
|
||||
ui_widget_set_style_string(input, "left", left);
|
||||
ui_widget_set_style_string(input, "top", top);
|
||||
ui_widget_set_style_string(input, "width", width);
|
||||
ui_widget_set_style_string(input, "height", height);
|
||||
ui_root_append(input);
|
||||
return input;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ui_widget_t *input;
|
||||
|
||||
lcui_init();
|
||||
ui_widget_set_title(ui_root(), L"textinput edit preview");
|
||||
|
||||
input = add_input("20px", "20px", "330px", "32px");
|
||||
ui_textinput_set_placeholder(input, "Single line, try Shift+Arrows");
|
||||
ui_textinput_set_text(input, "Hello world");
|
||||
|
||||
input = add_input("20px", "70px", "330px", "32px");
|
||||
ui_textinput_set_password_char(input, L'*');
|
||||
ui_textinput_set_text(input, "secret");
|
||||
|
||||
input = add_input("20px", "120px", "330px", "32px");
|
||||
ui_textinput_set_read_only(input, true);
|
||||
ui_textinput_set_text(input, "Read-only, still selectable");
|
||||
|
||||
input = add_input("20px", "170px", "330px", "110px");
|
||||
ui_textinput_enable_multiline(input, true);
|
||||
ui_textinput_set_text_w(
|
||||
input,
|
||||
L"Line one\n"
|
||||
L"Line two with a longer sentence that should wrap inside the "
|
||||
L"box when it exceeds the available width.\n"
|
||||
L"Line three");
|
||||
|
||||
ui_widget_resize(ui_root(), 380, 310);
|
||||
preview_show_default_window();
|
||||
return lcui_main();
|
||||
}
|
||||
@@ -22,8 +22,16 @@ for _, topic in ipairs(previews) do
|
||||
add_deps("lcui")
|
||||
end
|
||||
|
||||
target("preview-flex-layout-percentage-wrap")
|
||||
target("preview-textinput-edit")
|
||||
set_default(false)
|
||||
set_kind("binary")
|
||||
set_group("previews")
|
||||
set_rundir("../fixtures")
|
||||
add_includedirs("../helpers")
|
||||
add_files("preview_textinput_edit.c")
|
||||
add_deps("lcui")
|
||||
|
||||
target("preview-flex-layout-percentage-wrap") set_default(false)
|
||||
set_kind("binary")
|
||||
set_group("previews")
|
||||
set_rundir("../fixtures")
|
||||
|
||||
Reference in New Issue
Block a user