summaryrefslogtreecommitdiff
path: root/tikzit/src/gtk/tztoolpalette.m
diff options
context:
space:
mode:
authorAlex Merry <alex.merry@cs.ox.ac.uk>2012-12-17 15:56:29 +0000
committerAlex Merry <alex.merry@cs.ox.ac.uk>2012-12-17 15:56:29 +0000
commit352d217c8805ba3f7de6d4e710a0b4bb3e2a307b (patch)
treedfda05afc811c1f8894cac05467e3edf935252aa /tikzit/src/gtk/tztoolpalette.m
parent477b865da18f6004a5180d924997d9283c20250f (diff)
Snap toolbox width to tool button width
The toolbox width is forced to always be a multiple of the width of one of the tool buttons.
Diffstat (limited to 'tikzit/src/gtk/tztoolpalette.m')
-rw-r--r--tikzit/src/gtk/tztoolpalette.m51
1 files changed, 44 insertions, 7 deletions
diff --git a/tikzit/src/gtk/tztoolpalette.m b/tikzit/src/gtk/tztoolpalette.m
index 1a6ab9a..a948127 100644
--- a/tikzit/src/gtk/tztoolpalette.m
+++ b/tikzit/src/gtk/tztoolpalette.m
@@ -68,20 +68,57 @@ tz_tool_palette_init (TzToolPalette *palette)
{
}
+static GtkToolItemGroup *
+tz_tool_palette_tool_group (TzToolPalette *palette)
+{
+ GList *children;
+ GtkToolItemGroup *group;
+
+ children = gtk_container_get_children (GTK_CONTAINER (palette));
+ g_return_val_if_fail (children, NULL);
+ group = GTK_TOOL_ITEM_GROUP (children->data);
+ g_list_free (children);
+
+ return group;
+}
+
+gboolean
+tz_tool_palette_get_button_size (TzToolPalette *palette,
+ gint *width,
+ gint *height)
+{
+ g_return_val_if_fail (width || height, FALSE);
+
+ GtkToolItemGroup *group = tz_tool_palette_tool_group (palette);
+ g_return_val_if_fail (group, FALSE);
+
+ guint tool_count = gtk_tool_item_group_get_n_items (group);
+ if (tool_count > 0)
+ {
+ GtkWidget *tool_button;
+ GtkRequisition button_requisition;
+
+ tool_button = GTK_WIDGET (gtk_tool_item_group_get_nth_item (group, 0));
+ gtk_widget_size_request (tool_button, &button_requisition);
+ if (width)
+ *width = button_requisition.width;
+ if (height)
+ *height = button_requisition.height;
+ return TRUE;
+ }
+ return FALSE;
+}
+
static void
tz_tool_palette_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
TzToolPalettePrivate *private = GET_PRIVATE (widget);
- GList *children;
- GtkToolItemGroup *group;
+ GtkToolItemGroup *group = tz_tool_palette_tool_group (TZ_TOOL_PALETTE (widget));
- GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
+ g_return_if_fail (group);
- children = gtk_container_get_children (GTK_CONTAINER (widget));
- g_return_if_fail (children);
- group = GTK_TOOL_ITEM_GROUP (children->data);
- g_list_free (children);
+ GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
guint tool_count = gtk_tool_item_group_get_n_items (group);
if (tool_count > 0)