add text functions default tip

Mon, 27 Apr 2026 21:43:34 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 27 Apr 2026 21:43:34 +0200
changeset 1113
2df0be42b5e0
parent 1112
9250601f9d9a

add text functions

ui/common/types.c file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
--- a/ui/common/types.c	Sat Apr 25 21:29:37 2026 +0200
+++ b/ui/common/types.c	Mon Apr 27 21:43:34 2026 +0200
@@ -973,3 +973,77 @@
 void ui_list_class_set_iter(UiList *list, void *iter) {
     list->iter = iter;
 }
+
+/* ---------------- Text functions ---------------- */
+
+char* ui_text_getsubstr(UiText *text, int begin, int end) {
+    if(text->getsubstr) {
+        text->getsubstr(text, begin, end);
+    } else {
+        return NULL;
+    }
+}
+
+void  ui_text_insert(UiText *text, int pos, const char *str) {
+    if(text->insert) {
+        text->insert(text, pos, str);
+    }
+}
+
+void  ui_text_replace(UiText *text, int begin, int end, const char *str) {
+    if(text->replace) {
+        text->replace(text, begin, end, str);
+    }
+}
+
+void  ui_text_setposition(UiText *text, int pos) {
+    if(text->setposition) {
+        text->setposition(text, pos);
+    }
+}
+
+int   ui_text_position(UiText *text) {
+    if(text->position) {
+        return text->position(text);
+    } else {
+        return 0;
+    }
+}
+
+void  ui_text_showposition(UiText *text, int pos) {
+    if(text->showposition) {
+        text->showposition(text, pos);
+    }
+}
+
+void  ui_text_setselection(UiText *text, int begin, int end) {
+    if(text->setselection) {
+        text->setselection(text, begin, end);
+    }
+}
+
+void  ui_text_selection(UiText *text, int *begin, int *end) {
+    if(text->selection) {
+        text->selection(text, begin, end);
+    } else {
+        if(begin) {
+            *begin = 0;
+        }
+        if(end) {
+            *end = 0;
+        }
+    }
+}
+
+int   ui_text_length(UiText *text) {
+    if(text->length) {
+        return text->length(text);
+    } else {
+        return 0;
+    }
+}
+void  ui_text_remove(UiText *text, int begin, int end) {
+    if(text->remove) {
+        text->remove(text, begin, end);
+    }
+}
--- a/ui/ui/toolkit.h	Sat Apr 25 21:29:37 2026 +0200
+++ b/ui/ui/toolkit.h	Mon Apr 27 21:43:34 2026 +0200
@@ -718,7 +718,16 @@
 
 UIEXPORT void ui_add_image(char *imgname, char *filename); // TODO: remove?
 
-
+UIEXPORT char* ui_text_getsubstr(UiText *text, int begin, int end);
+UIEXPORT void  ui_text_insert(UiText *text, int pos, const char *str);
+UIEXPORT void  ui_text_replace(UiText *text, int begin, int end, const char *str);
+UIEXPORT void  ui_text_setposition(UiText *text, int pos);
+UIEXPORT int   ui_text_position(UiText *text);
+UIEXPORT void  ui_text_showposition(UiText *text, int pos);
+UIEXPORT void  ui_text_setselection(UiText *text, int begin, int end);
+UIEXPORT void  ui_text_selection(UiText *text, int *begin, int *end);
+UIEXPORT int   ui_text_length(UiText *text);
+UIEXPORT void  ui_text_remove(UiText *text, int begin, int end);
 
 UIEXPORT UiStr ui_str(char *cstr);
 UIEXPORT UiStr ui_str_free(char *str, void (*free)(void *v));

mercurial