GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed May 22, 2013 10:38 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Button Padding
PostPosted: Wed Mar 25, 2009 3:16 pm 
Offline
Familiar Face

Joined: Thu Mar 19, 2009 5:30 am
Posts: 20
Hi

How to achieve the padding for button or if there is any generic solution for widgets.I am able to pad button at Top and Left but not getting how to achieve Right and Bottom Padding

Any help is appreciating


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 25, 2009 5:14 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

When creating GUI with Gtk+, you must take into consideration that the final look of the widget is usually the result of how it has been packed into it's parent.

For example, when you're adding widget into Gtk[H|V]Box, the last parameter of gtk_box_pack_[start|end] is padding, which adds some space around your widget.

Check containers you're adding widgets in to see if they offer some similar option. If that's not the case, you can still use GtkAlignment as an adapter and set padding on it.

If you need an example, post back and I'll do my best to provide one that will depict the usual usage.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 26, 2009 5:16 am 
Offline
Familiar Face

Joined: Thu Mar 19, 2009 5:30 am
Posts: 20
Hi tadeboro

Thanks for ur reply

I am using Layout containeer and putting widgets inside it.
The padding requirement is run time, so i think GtkAligment option will work for me.

If you can send some sample code then it will be a great help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 26, 2009 5:37 am 
Offline
Familiar Face

Joined: Thu Mar 19, 2009 5:30 am
Posts: 20
Hi

Actually my question is not clear , sorry for that.

I want to pad the button label inside the button.
i.e the label should be able to pad at Top/Left/Right and Bottom position and all padding parameters will be different for eg 10 pixels padding at Top and 2 pixel padding at bottom.

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 26, 2009 10:08 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

As promised, I wrote a simplistic sample application that sports some packing methods.

Code:
#include <gtk/gtk.h>

int
main( int    argc,
     char **argv )
{
   GtkWidget *window;
   GtkWidget *align;
   GtkWidget *button;
   GtkWidget *label;
   GtkWidget *table;

   gtk_init( &argc, &argv );

   window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
   g_signal_connect( G_OBJECT( window ), "destroy",
                 G_CALLBACK( gtk_main_quit ), NULL );

   table = gtk_table_new( 10, 2, FALSE );
   gtk_container_add( GTK_CONTAINER( window ), table );

   /* First button */
   label = gtk_label_new( "This button has 15px margin\n"
                     "on all sides." );
   gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1, GTK_FILL,
                                       GTK_SHRINK, 0, 0 );

   button = gtk_button_new_with_label( "Button 1" );
   gtk_container_set_border_width( GTK_CONTAINER( button ), 15 );
   gtk_table_attach( GTK_TABLE( table ), button, 1, 2, 0, 1, GTK_SHRINK,
                                      GTK_SHRINK, 0, 0 );

   /* Second button */
   label = gtk_label_new( "Label inside this button has 0px top, 5px right,\n"
                     "10px botton and 15px left padding." );
   gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2, GTK_FILL,
                                       GTK_SHRINK, 0, 0 );

   button = gtk_button_new();
   gtk_table_attach( GTK_TABLE( table ), button, 1, 2, 1, 2, GTK_SHRINK,
                                      GTK_SHRINK, 0, 0 );
   align = gtk_alignment_new( 0, 0, 0, 0 );
   gtk_alignment_set_padding( GTK_ALIGNMENT( align ), 0, 10, 15, 5 );
   gtk_container_add( GTK_CONTAINER( button ), align );

   label = gtk_label_new( "Button 2" );
   gtk_container_add( GTK_CONTAINER( align ), label );

   gtk_widget_show_all( window );

   gtk_main();

   return( 0 );
}


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 5 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group