GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Jul 29, 2014 12:35 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Keeping a tab on buttons
PostPosted: Tue Feb 07, 2012 10:13 pm 
Offline

Joined: Tue Feb 07, 2012 10:01 pm
Posts: 3
Hi, I'm new to GTK and new to this forum, so I'm sorry if I'm a bit slow on the uptake.

I'm a complete GTK beginner, and I'm currently learning basic layout. I've set myself a challenge involving a window with ten buttons - clicking each button changes the text on one of the other buttons. Naturally, this means I need to be able to refer to a button after I've run the gtk_widget_show function, but tutorials so far have generated multiple buttons by reassigning as single GtkWidget* pointer to a new button after gtk_widget_show-ing each one, so I lose the reference to the previous button each time I create a new one.

I've created a simple application which uses an array of GtkWidget* pointers as opposed to just one, but would this fill up more memory than necessary? Perhaps there is another way to get around this (for example, I notice that gtk_widget_show returns void, but if there is a function similar to g_signal_connect which returns a gulong ID for that button which I can use to retrieve it)?


Top
 Profile  
 
 Post subject: Re: Keeping a tab on buttons
PostPosted: Wed Feb 08, 2012 1:33 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
There's a number of ways you can do this. If you have a fixed definite number of buttons there's the crude method of calling them butt1, butt2, etc. and referring to them explicitly; or you could use a data type like an array (there's also singly and doubly linked lists etc. available -- have a browse in glibs functionality to see) as you mention.
You don't have to worry about the space; you're programming a GUI and the memory required for storing an array is negligible compared to the amount involved in the graphical interface.


Top
 Profile  
 
 Post subject: Re: Keeping a tab on buttons
PostPosted: Wed Feb 08, 2012 4:52 pm 
Offline

Joined: Tue Feb 07, 2012 10:01 pm
Posts: 3
OK, thanks for your reply.
On a separate point, how can I set up a window so that the number of buttons in a toolbar changes according to the size of the window? Would this require completely redrawing the window every time it is resized?


Top
 Profile  
 
 Post subject: Re: Keeping a tab on buttons
PostPosted: Thu Feb 09, 2012 10:45 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
To the latter question, I believe so, but I think you'll find that this happens anyway. You can get the window width with gtk_window_get_size. I imagine then you'll want fixed size buttons and could do with room for a little arrow button to access the unseen toolbar button functionality. Subtract off space for this (if that is there will be more button than there is space for without it) as well as other needed padding and then divide by the button width and then only gtk_widget_show up to this button number (in which case it is better to have them in an array or list than the crude approach mentioned before). The situation can be more complicated if you want the button size to initially be set larger than needed and then shrink to a limit as room gets more cramped, before knocking out buttons


Top
 Profile  
 
 Post subject: Re: Keeping a tab on buttons
PostPosted: Sat Feb 11, 2012 11:38 pm 
Offline

Joined: Tue Feb 07, 2012 10:01 pm
Posts: 3
Thanks very much!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group