Re: locating a widget in a scrolled window
- From: Stephen Bach <9sjb qlink queensu ca>
- To: Irtza Sharif <irtzas gmail com>
- Cc: gtk-list gnome org
- Subject: Re: locating a widget in a scrolled window
- Date: Sun, 10 Apr 2005 22:27:20 -0400
Hi Irtza, 
On Sun, Apr 10, 2005 at 09:48:24PM -0400, Irtza Sharif wrote:
> Thank you for your response.  Let me clarify my situation.
> 
> I have a Scrolled Window within which I add a vbox
> 
> The widgets inside the vbox are held in a linked list that I have
> setup.  New widgets can be created and added to this vbox within the
> scrolled window while the program is running.  When these new widgets
> are created and added, I would like to shift the scrolled window to
> show this widget.
If the new widgets are direct children of the vbox (which is a direct
child of the scrolled window's viewport), you should be able to do
something like this:
void scroll_to(GtkWidget* scrolled_window, GtkWidget* widget) {
	gdouble page_inc, step_inc, upper, lower, pos;
	GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(
			GTK_SCROLLED_WINDOW(scrolled_window));
	page_inc = vadj->page_increment;
	step_inc = vadj->step_increment;
	lower = vadj->lower;
	/* Otherwise we sometimes scroll down into a page of black. */
	upper = vadj->upper - page_inc - step_inc;
	/* Center on the widget. */
	pos = (gdouble)widget->allocation.y - page_inc/2;
	gtk_adjustment_set_value(vadj, CLAMP(pos, lower, upper));
}
This only takes into account the vertical, but I think the horizontal
could be done similarly.
If the new widgets aren't direct children of the vbox, you could still
probably do this by recursing up through widget->parent until you get to
the vbox, remapping the coordinates along the way.
Hope this helps,
Stephen
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]