Borderless buttons



Hi!

I'm trying to turn some image-based togglebuttons in Dia into cleaner
code.  Previously, they've just been GtkDrawingAreas with event
handling, but I'd like them to be proper ToggleButtons that change the
image according to state.  While I have the image handling in there, I
can't seem to get the six-pixel (or so) border away, making the buttons
look much clunkier than before.  Is there a way to get rid of all
borders?  Googling shows me some patches back in '99, but they don't
seem to have made it into Gtk.

Here's the code I use to create a togglebutton with images
(dia_get_image_from_file is just a utility function to make a GtkImage
from an installed image file):

dia_toggle_button_new_with_images(gchar *on_image, gchar *off_image)
{
  GtkWidget *button = gtk_toggle_button_new();
  struct image_pair *images = g_new0(struct image_pair, 1);

  images->on = dia_get_image_from_file(on_image);
  g_object_ref(images->on);
  gtk_misc_set_padding(GTK_MISC(images->on), 0, 0);
  gtk_widget_show(images->on);

  images->off = dia_get_image_from_file(off_image);
  g_object_ref(images->off);
  gtk_misc_set_padding(GTK_MISC(images->off), 0, 0);
  gtk_widget_show(images->off);

  gtk_container_add(GTK_CONTAINER(button), images->off);
  gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
  /* Don't want to force everybody into 2.4 just for this */
  /*  gtk_button_set_focus_on_click(GTK_BUTTON(button), FALSE);*/
  gtk_container_set_border_width(GTK_CONTAINER(button), 0);

  g_signal_connect(G_OBJECT(button), "toggled", 
                   dia_toggle_button_swap_images, images);
  g_signal_connect(G_OBJECT(button), "destroy",
                   dia_toggle_button_destroy, images);

  return button;
}

Thanks,
-Lars




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]