Wed, 21 Jan 2026 20:12:59 +0100
extend textfield API (QT)
| ucx/cx/string.h | file | annotate | diff | comparison | revisions | |
| ui/qt/text.cpp | file | annotate | diff | comparison | revisions |
--- a/ucx/cx/string.h Fri Jan 16 11:56:17 2026 +0100 +++ b/ucx/cx/string.h Wed Jan 21 20:12:59 2026 +0100 @@ -1335,10 +1335,10 @@ bool cx_strtok_next_(CxStrtokCtx *ctx, cxstring *token); #ifdef __cplusplus -CX_CPPDECL cx_strtok_next(CxStrtokCtx *ctx, cxstring *token) { +CX_CPPDECL bool cx_strtok_next(CxStrtokCtx *ctx, cxstring *token) { return cx_strtok_next_(ctx, token); } -CX_CPPDECL cx_strtok_next(CxStrtokCtx *ctx, cxmutstr *token) { +CX_CPPDECL bool cx_strtok_next(CxStrtokCtx *ctx, cxmutstr *token) { // Note: this is actually UB - fixed with start_lifetime_as() in C++23 // but it works on all supported platforms return cx_strtok_next_(ctx, reinterpret_cast<cxstring*>(token));
--- a/ui/qt/text.cpp Fri Jan 16 11:56:17 2026 +0100 +++ b/ui/qt/text.cpp Wed Jan 21 20:12:59 2026 +0100 @@ -278,3 +278,50 @@ } str->value.ptr = NULL; } + +void ui_textfield_focus(UIWIDGET textfield) { + QLineEdit *edit = static_cast<QLineEdit*>(textfield); + edit->setFocus(); + edit->selectAll(); +} + +void ui_textfield_focus_without_selecting(UIWIDGET textfield) { + QLineEdit *edit = static_cast<QLineEdit*>(textfield); + edit->setFocus(); +} + +void ui_textfield_set_selection(UIWIDGET textfield, int begin, int end) { + QLineEdit *edit = static_cast<QLineEdit*>(textfield); + if (begin < 0) { + begin = 0; + } + if (end < begin) { + end = begin; + } + edit->setSelection(begin, end - begin); +} + +void ui_textfield_select_all(UIWIDGET textfield) { + QLineEdit *edit = static_cast<QLineEdit*>(textfield); + edit->selectAll(); +} + +void ui_textfield_set_editable(UIWIDGET textfield, UiBool editable) { + QLineEdit *edit = static_cast<QLineEdit*>(textfield); + edit->setReadOnly(!editable); +} + +UiBool ui_textfield_is_editable(UIWIDGET textfield) { + QLineEdit *edit = static_cast<QLineEdit*>(textfield); + return !edit->isReadOnly(); +} + +void ui_textfield_set_position(UIWIDGET textfield, int pos) { + QLineEdit *edit = static_cast<QLineEdit*>(textfield); + edit->setCursorPosition(pos); +} + +int ui_textfield_get_position(UIWIDGET textfield) { + QLineEdit *edit = static_cast<QLineEdit*>(textfield); + return edit->cursorPosition(); +}