GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reduce button padding

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
montgoss



Joined: 12 Feb 2008
Posts: 4

PostPosted: Tue Feb 12, 2008 3:04 pm    Post subject: Reduce button padding Reply with quote

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?
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 480
Location: Portland, OR USA

PostPosted: Tue Feb 12, 2008 5:41 pm    Post subject: Reply with quote

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: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP