add textarea

Fri, 28 Nov 2025 17:41:51 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 28 Nov 2025 17:41:51 +0100
changeset 940
105bccb3dc66
parent 939
fdc6a46100a3
child 941
e7459e9fbed2

add textarea

application/main.c file | annotate | diff | comparison | revisions
ui/win32/text.c file | annotate | diff | comparison | revisions
ui/win32/text.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Thu Nov 27 19:48:30 2025 +0100
+++ b/application/main.c	Fri Nov 28 17:41:51 2025 +0100
@@ -1243,6 +1243,9 @@
         ui_button(obj, .label = "Button 1", .hfill = TRUE);
         ui_button(obj, .label = "Button 2");
         ui_button(obj, .label = "Button 2");
+        ui_newline(obj);
+
+        ui_textarea(obj, .colspan = 3, .fill = TRUE);
     }
 
 
--- a/ui/win32/text.c	Thu Nov 27 19:48:30 2025 +0100
+++ b/ui/win32/text.c	Fri Nov 28 17:41:51 2025 +0100
@@ -28,6 +28,135 @@
 
 #include "text.h"
 
+static W32WidgetClass textarea_widget_class = {
+    .eventproc = ui_textarea_eventproc,
+    .enable = w32_widget_default_enable,
+    .show = w32_widget_default_show,
+    .get_preferred_size = ui_textarea_get_preferred_size,
+    .destroy  = w32_widget_default_destroy
+};
+
+UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs *args) {
+    HINSTANCE hInstance = GetModuleHandle(NULL);
+    UiContainerPrivate *container = ui_obj_container(obj);
+    HWND parent = ui_container_get_parent(container);
+    UiLayout layout = UI_ARGS2LAYOUT(args);
+
+    int width = args->width >= 0 ? args->width : 100;
+    int height = args->height >= 0 ? args->height : 100;
+
+    HWND hwnd = CreateWindowEx(
+            0,
+            "EDIT",
+            "",
+            WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL,
+            0, 0, width, height,
+            parent,
+            (HMENU)0,
+            hInstance,
+            NULL);
+    ui_win32_set_ui_font(hwnd);
+
+    W32Widget *widget = w32_widget_create(&textarea_widget_class, hwnd, sizeof(UiTextArea));
+    ui_container_add(container, widget, &layout);
+
+    UiTextArea *textarea = (UiTextArea*)widget;
+    textarea->width = width;
+    textarea->widget.var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_TEXT);
+    textarea->widget.callback = args->onchange;
+    textarea->widget.callbackdata = args->onchangedata;
+
+    if (textarea->widget.var) {
+        UiText *t = textarea->widget.var->value;
+
+        if (t->value.ptr) {
+            // TODO: set textarea string
+        }
+        t->obj = widget;
+        t->save = ui_textarea_save;
+        t->destroy = ui_textarea_destroy;
+        t->restore = ui_textarea_restore;
+        t->get = ui_textarea_get;
+        t->set = ui_textarea_set;
+        t->getsubstr = ui_textarea_getsubstr;
+        t->insert = ui_textarea_insert;
+        t->setposition = ui_textarea_setposition;
+        t->position = ui_textarea_position;
+        t->setselection = ui_textarea_setselection;
+        t->selection = ui_textarea_selection;
+        t->length = ui_textarea_length;
+        t->remove = ui_textarea_remove;
+    }
+
+    return widget;
+}
+
+W32Size ui_textarea_get_preferred_size(W32Widget *widget) {
+    W32Size size;
+    UiTextArea *textarea = (UiTextArea*)widget;
+    size.width = textarea->width;
+    size.height = textarea->height;
+    return size;
+}
+
+int ui_textarea_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+    return 0;
+}
+
+void  ui_textarea_save(UiText *text) {
+
+}
+
+void  ui_textarea_destroy(UiText *text) {
+
+}
+
+void  ui_textarea_restore(UiText *text) {
+
+}
+
+void  ui_textarea_set(UiText *text, const char *str) {
+
+}
+
+char* ui_textarea_get(UiText *text) {
+    return NULL;
+}
+
+char* ui_textarea_getsubstr(UiText *text, int begin, int end) {
+    return NULL;
+}
+
+void  ui_textarea_insert(UiText *text, int pos, char *str) {
+
+}
+
+void  ui_textarea_setposition(UiText *text, int pos) {
+
+}
+
+int   ui_textarea_position(UiText *text) {
+    return 0;
+}
+
+void  ui_textarea_setselection(UiText *text, int begin, int end) {
+
+}
+
+void  ui_textarea_selection(UiText *text, int *begin, int *end) {
+
+}
+
+int   ui_textarea_length(UiText *text) {
+    return 0;
+}
+
+void  ui_textarea_remove(UiText *text, int begin, int end) {
+
+}
+
+/* ----------------------------- TextField ----------------------------- */
+
 static W32WidgetClass textfield_widget_class = {
     .eventproc = ui_textfield_eventproc,
     .enable = w32_widget_default_enable,
--- a/ui/win32/text.h	Thu Nov 27 19:48:30 2025 +0100
+++ b/ui/win32/text.h	Fri Nov 28 17:41:51 2025 +0100
@@ -33,11 +33,34 @@
 #include "container.h"
 #include "toolkit.h"
 
+typedef struct UiTextArea {
+    UiWidget widget;
+    int width;
+    int height;
+} UiTextArea;
+
 typedef struct UiTextField {
     UiWidget widget;
     int width;
 } UiTextField;
 
+W32Size ui_textarea_get_preferred_size(W32Widget *widget);
+int ui_textarea_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+
+void  ui_textarea_save(UiText *text);
+void  ui_textarea_destroy(UiText *text);
+void  ui_textarea_restore(UiText *text);
+void  ui_textarea_set(UiText *text, const char *str);
+char* ui_textarea_get(UiText *text);
+char* ui_textarea_getsubstr(UiText *text, int begin, int end);
+void  ui_textarea_insert(UiText *text, int pos, char *str);
+void  ui_textarea_setposition(UiText *text, int pos);
+int   ui_textarea_position(UiText *text);
+void  ui_textarea_setselection(UiText *text, int begin, int end);
+void  ui_textarea_selection(UiText *text, int *begin, int *end);
+int   ui_textarea_length(UiText *text);
+void  ui_textarea_remove(UiText *text, int begin, int end);
+
 W32Size ui_textfield_get_preferred_size(W32Widget *widget);
 int ui_textfield_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 

mercurial