Hello! I am using GTK-3 with Vala. In my app when button is clicked then new child is added to Box which is inside ScrolledWindow. I want ScrolledWindow to be scrolled to the bottom when such a thing happens. I tried to use ResizeMode.IMMEDIATE and it worked well (else it just scrolled to the bottom minus added element size) but it is deprecated. What is correct way of doing that?
You can get the scrolled window vadjustment and set its value. Look into gtk_scrolled_window_get_vadjustment and gtk_adjustment_set_value. According to the docs you should set the adjustment value to upper - page-size
:
static void
scroll_to_bottom (GtkWidget *scrolled_window)
{
GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window));
double upper = gtk_adjustment_get_upper (adjustment);
double page_size = gtk_adjustment_get_page_size (adjustment);
gtk_adjustment_set_value (adjustment, upper - page_size);
}
Also, to the āscrolled to bottom minus element sizeā, you can do.
create a callback to āchangedā signal of the GtkAdjustment. This signal is emmited when some attribute different from āvalueā is changed. Eg. It is emmited when āpage_sizeā changes.
So, all we need to do is to get the āupperā attribute from the GtkAdjustment and set the āvalueā attribute to this value (or to āupperā - āpage_sizeā, if you prefer).
Doing this, the scroll will be on the bottom of the Scrolled Window.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.