GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 24, 2014 9:29 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: GtkNotebook tab close button padding
PostPosted: Wed Aug 19, 2009 1:12 pm 
Offline
Familiar Face

Joined: Tue Aug 18, 2009 4:51 pm
Posts: 7
Location: Romania
Code:
#define GTK_DISABLE_DEPRECATED
#define GTK_DISABLE_SINGLE_INCLUDES

#include <gtk/gtk.h>

int main(int argc, char **argv) {
        GtkWidget *notebook, *tabContainer, *tabCloseButton, *window, *tabLabel;
   
        gtk_init(&argc, &argv);
   
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        notebook = gtk_notebook_new();
        tabLabel = gtk_label_new("notebook tab");
        tabContainer = gtk_hbox_new(FALSE, 3);
        tabCloseButton = gtk_button_new();
           
        g_signal_connect(G_OBJECT(window), "destroy",
              G_CALLBACK(gtk_main_quit), NULL);
   
        gtk_button_set_relief(GTK_BUTTON(tabCloseButton), GTK_RELIEF_NONE);

        gtk_container_add(GTK_CONTAINER(window), notebook);
        gtk_box_pack_start(GTK_BOX(tabContainer), tabLabel, TRUE, TRUE, 0);
        gtk_box_pack_start(GTK_BOX(tabContainer),
        tabCloseButton, FALSE, FALSE, 0);
        gtk_container_add(GTK_CONTAINER(tabCloseButton),
        gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
        gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook), gtk_label_new("example"), tabContainer);
       
        gtk_widget_show_all(window);
        gtk_widget_show_all(tabContainer);
 
        gtk_main();
        return 0;
}


If you compile the code you see that tabCloseButton's image is padded too much inside the button.These are two screenshots with this close button and gedit's close button.

GEdit: http://picasaweb.google.com/lh/photo/oraQlNUi9gsyb2gBxy6-cA?feat=directlink
My application: http://picasaweb.google.com/lh/photo/yGq9NEkTHGXmVbA8BHRHRg?feat=directlink

How do I remove this internal padding?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 22, 2009 8:37 am 
Offline
Never Seen the Sunlight

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

You'll have to play with GTK+ rc styles a bit (like GEdit developers did;).

The main idea is to remove empty space around the button image that your GTK+ theme defines. And this is how you can do it (I modified your code a bit):

Code:
#define GTK_DISABLE_DEPRECATED
#define GTK_DISABLE_SINGLE_INCLUDES

#include <gtk/gtk.h>

int main(int argc, char **argv) {
        GtkWidget *notebook, *tabContainer, *tabCloseButton, *window, *tabLabel;
   
        gtk_init(&argc, &argv);

      /* Update style for notebook tab button */
      gtk_rc_parse_string (
         "style \"my-button-style\"\n"
         "{\n"
         "  GtkWidget::focus-padding = 0\n"
         "  GtkWidget::focus-line-width = 0\n"
         "  xthickness = 0\n"
         "  ythickness = 0\n"
         "}\n"
         "widget \"*.my-close-button\" style \"my-button-style\"");
   
   
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        notebook = gtk_notebook_new();
        tabLabel = gtk_label_new("notebook tab");
        tabContainer = gtk_hbox_new(FALSE, 3);
        tabCloseButton = gtk_button_new();

      /* Set buttons name so the style will affect it */
      gtk_widget_set_name( tabCloseButton, "my-close-button" );
           
        g_signal_connect(G_OBJECT(window), "destroy",
              G_CALLBACK(gtk_main_quit), NULL);
   
        gtk_button_set_relief(GTK_BUTTON(tabCloseButton), GTK_RELIEF_NONE);

        gtk_container_add(GTK_CONTAINER(window), notebook);
        gtk_box_pack_start(GTK_BOX(tabContainer), tabLabel, TRUE, TRUE, 0);
        gtk_box_pack_start(GTK_BOX(tabContainer),
        tabCloseButton, FALSE, FALSE, 0);
        gtk_container_add(GTK_CONTAINER(tabCloseButton),
        gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
        gtk_notebook_prepend_page(GTK_NOTEBOOK(notebook), gtk_label_new("example"), tabContainer);
       
        gtk_widget_show_all(window);
        gtk_widget_show_all(tabContainer);

        gtk_main();
        return 0;
}


Tadej


Top
 Profile  
 
 Post subject: It works!
PostPosted: Sat Aug 22, 2009 8:52 am 
Offline
Familiar Face

Joined: Tue Aug 18, 2009 4:51 pm
Posts: 7
Location: Romania
It works!

I already tried with gtk_rc_parse_string, but the syntax I used was invalid and I didn't know that I have to use gtk_widget_set_name.

Thanks again Tadej!

_________________
--Silviu Bogan


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

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] 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