# HG changeset patch # User Olaf Wintermann # Date 1769967486 -3600 # Node ID 4243fcc0aa5c38532acfa6a499515b02183b0faf # Parent afe02792303dd632a65805c5bf5af61206976dcb add functions for scrolling a textarea to a specific position (GTK) diff -r afe02792303d -r 4243fcc0aa5c ui/common/objs.mk --- a/ui/common/objs.mk Sun Feb 01 11:42:27 2026 +0100 +++ b/ui/common/objs.mk Sun Feb 01 18:38:06 2026 +0100 @@ -32,7 +32,7 @@ COMMON_OBJ = context$(OBJ_EXT) COMMON_OBJ += document$(OBJ_EXT) COMMON_OBJ += object$(OBJ_EXT) -COMMON_OBJ = action$(OBJ_EXT) +COMMON_OBJ += action$(OBJ_EXT) COMMON_OBJ += container$(OBJ_EXT) COMMON_OBJ += types$(OBJ_EXT) COMMON_OBJ += app$(OBJ_EXT) diff -r afe02792303d -r 4243fcc0aa5c ui/common/types.c --- a/ui/common/types.c Sun Feb 01 11:42:27 2026 +0100 +++ b/ui/common/types.c Sun Feb 01 18:38:06 2026 +0100 @@ -678,6 +678,7 @@ to->insert = from->insert; to->setposition = from->setposition; to->position = from->position; + to->showposition = from->showposition; to->setselection = from->setselection; to->selection = from->selection; to->length = from->length; diff -r afe02792303d -r 4243fcc0aa5c ui/gtk/text.c --- a/ui/gtk/text.c Sun Feb 01 11:42:27 2026 +0100 +++ b/ui/gtk/text.c Sun Feb 01 18:38:06 2026 +0100 @@ -131,6 +131,7 @@ uitext->onchangedata = args->onchangedata; g_object_set_data(G_OBJECT(text_area), "ui_textarea", uitext); + g_object_set_data(G_OBJECT(text_area), "ui_textarea_widget", text_area); g_signal_connect( text_area, @@ -144,6 +145,7 @@ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS SCROLLEDWINDOW_SET_CHILD(scroll_area, text_area); + g_object_set_data(G_OBJECT(scroll_area), "ui_textarea_widget", text_area); ui_widget_size_request(scroll_area, args->width, args->height); @@ -186,6 +188,7 @@ value->insert = ui_textarea_insert; value->setposition = ui_textarea_setposition; value->position = ui_textarea_position; + value->showposition = ui_textarea_showposition; value->setselection = ui_textarea_setselection; value->selection = ui_textarea_selection; value->length = ui_textarea_length; @@ -211,8 +214,21 @@ free(textarea); } +void ui_textarea_scroll_to(UIWIDGET textarea, int pos) { + GtkWidget *widget = ui_textarea_gettextwidget(textarea); + if(!widget) { + fprintf(stderr, "Error: ui_textarea_scroll_to: widget is not a textarea\n"); + } + GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)); + + GtkTextIter offset; + gtk_text_buffer_get_iter_at_offset(buf, &offset, pos); + + gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(widget), &offset, 0.2, FALSE, 0, 0); +} + UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) { - return SCROLLEDWINDOW_GET_CHILD(textarea); + return g_object_get_data(G_OBJECT(textarea), "ui_textarea_widget"); } void ui_textarea_save(UiText *text) { @@ -296,6 +312,10 @@ return text->pos; } +void ui_textarea_showposition(UiText *text, int pos) { + ui_textarea_scroll_to(text->obj, pos); +} + void ui_textarea_setselection(UiText *text, int begin, int end) { GtkTextBuffer *buf = text->data1; GtkTextIter ib; diff -r afe02792303d -r 4243fcc0aa5c ui/gtk/text.h --- a/ui/gtk/text.h Sun Feb 01 11:42:27 2026 +0100 +++ b/ui/gtk/text.h Sun Feb 01 18:38:06 2026 +0100 @@ -120,6 +120,7 @@ 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_showposition(UiText *text, int pos); 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); diff -r afe02792303d -r 4243fcc0aa5c ui/ui/text.h --- a/ui/ui/text.h Sun Feb 01 11:42:27 2026 +0100 +++ b/ui/ui/text.h Sun Feb 01 18:38:06 2026 +0100 @@ -149,6 +149,8 @@ UIEXPORT void ui_text_undo(UiText *value); UIEXPORT void ui_text_redo(UiText *value); +UIEXPORT void ui_textarea_scroll_to(UIWIDGET textarea, int pos); + #define ui_textfield(obj, ...) ui_textfield_create(obj, &(UiTextFieldArgs) { __VA_ARGS__ }) #define ui_frameless_textfield(obj, ...) ui_frameless_field_create(obj, &(UiTextFieldArgs) { __VA_ARGS__ }) #define ui_passwordfield(obj, ...) ui_passwordfield_create(obj, &(UiTextFieldArgs) { __VA_ARGS__ }) diff -r afe02792303d -r 4243fcc0aa5c ui/ui/toolkit.h --- a/ui/ui/toolkit.h Sun Feb 01 11:42:27 2026 +0100 +++ b/ui/ui/toolkit.h Sun Feb 01 18:38:06 2026 +0100 @@ -395,6 +395,7 @@ void (*insert)(UiText*, int, char*); void (*setposition)(UiText*,int); int (*position)(UiText*); + void (*showposition)(UiText*, int); void (*setselection)(UiText*, int, int); /* text, begin, end */ void (*selection)(UiText*, int*, int*); /* text, begin, end */ int (*length)(UiText*);