tags:

views:

19

answers:

1

I am adding one GtkVBox to GtkViewPort.
And I am doing scrolling for GtkViewPort based on two Up/Down Buttons.

I need to display last item in VBox as we do in Message Chat Screens (Message Chat list displays/adds newest chat message at bottom of the list) i doing exact thing.

so for scrolling at the bottom of the GtkViewPort i am doing in the map event call back.

GtkAdjustment* adjustment;
adjustment = gtk_viewport_get_vadjustment(GTK_VIEWPORT(viewport_list));
gtk_adjustment_set_value(adjustment, gtk_adjustment_get_upper(adjustment));

So this works perfectly fine. it displays newest added widget in Vbox at the end.

on some external events I add new Widgets to my VBox and call above code again to display these newly added widgets. on first add it does not scroll at all but on 2nd add to VBOX it scroll upto 2nd last Widget in the list.

Why this might be happening.
It there another way of scrolling GtkViewPort to the end?

Thanks for reading :)

+1  A: 

This is very probably happening because when you run your code, the GtkVBox hasn't had time to grow, and/or the containing viewport hasn't had time to re-compute the new upper bound of the adjustment.

As I suggested in another version of this question, you should probably listen to the size-allocate signal from the GtkVBox to know when to re-try the jump to the bottom.

If that doesn't work (I haven't tried this exact scenario), you could try hooking up to the changed signal of the GtkAdjustment itself. That will, along with some simple buffering, let you determine when the "upper" bound of the GtkAdjustment has increased, which is exactly when you want to change the adjustment's value to the new upper bound.

unwind