GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Apr 21, 2014 9:41 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Reduce button padding
PostPosted: Tue Feb 12, 2008 3:04 pm 
Offline

Joined: Tue Feb 12, 2008 2:50 pm
Posts: 4
I'm sure I'm missing something simple, but how do you remove most(or all) of the space around the text in a button?

I played with GtkAlignment widgets a little. I put the button inside the alignment widget and then changed the padding when I changed the label. That kinda worked. But it seemed to make the button smaller and the GtkAlignment actually bigger. (I can post screen shots if that doesn't make sense)

So, how is one supposed to remove/reduce the padding?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 12, 2008 5:41 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
You may want to take a look at resource files.

As an example, I have a text editor that has tabs which have little close buttons on the tab. I make that button nice and small using this code which is largely taken from the gedit source code:

Code:
static void
on_close_button_style_set (GtkWidget *button,
                           GtkStyle *previous_style,
                           gpointer user_data)
{
        gint h, w;

        gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
                                           GTK_ICON_SIZE_MENU, &w, &h);

        gtk_widget_set_size_request (button, w + 2, h + 2);
}

static GtkWidget *
create_close_button ()
{
        GtkWidget *button;
        GtkWidget *image;
        GtkRcStyle *rcstyle;
       
        button = gtk_button_new ();
        gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);

        /* don't allow focus on the close button */
        gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);

        /* make it as small as possible */
        rcstyle = gtk_rc_style_new ();
        rcstyle->xthickness = rcstyle->ythickness = 0;
        gtk_widget_modify_style (button, rcstyle);
        gtk_rc_style_unref (rcstyle);

        image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
        gtk_widget_show (image);
        gtk_container_add (GTK_CONTAINER (button), image);

        /* Set minimal size */
        g_signal_connect (button, "style-set",
                          G_CALLBACK (on_close_button_style_set), NULL);

        return button;
}

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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