lock
lock

Reputation: 421

How to detect if GtkScrolledWindow is scrolled to bottom?

I would like to know if there is a way to know if the user scrolled GtkScrolledWindow (containing a GtkTextView) to the bottom or not.

Indeed, I automatically scrolled to the end with:

gtk_text_buffer_get_end_iter(tbuf, &iter);
GtkTextMark *insert_mark = gtk_text_buffer_get_insert(tbuf);
gtk_text_buffer_place_cursor(tbuf, &iter);
gtk_text_view_scroll_to_mark(text, insert_mark, 0.0, TRUE, 0.0, 1.0);

But I don't want to run this code if user has scrolled by himself.

Upvotes: 0

Views: 99

Answers (2)

lock
lock

Reputation: 421

I think I have the answer to my own question:

This code should detects if the edge is reached.

value = gtk_adjustment_get_value(adjustment);
lower = gtk_adjustment_get_lower(adjustment);
upper = gtk_adjustment_get_upper(adjustment);
page_size = gtk_adjustment_get_page_size(adjustment);

if (value == upper - page_size)
    edge_reached = TRUE;

Upvotes: 1

DigitalDruid
DigitalDruid

Reputation: 11

It looks like you could check for "the edge-reached" signal before excecuting those lines. "edge-reached" a signal in GtkScrooledWindow, which could be GTK_POS_TOP and GTK_POS_BOTTOM.

take a look at: https://developer.gnome.org/gtk3/stable/GtkScrolledWindow.html#GtkScrolledWindow-edge-reached

Upvotes: 1

Related Questions