[gnome-builder] tree: improve menu placement at bottom of screen
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tree: improve menu placement at bottom of screen
- Date: Fri, 10 Apr 2015 22:00:21 +0000 (UTC)
commit 8242f89e753361b0a3a9c926115607e27b434c0c
Author: Christian Hergert <christian hergert me>
Date: Fri Apr 10 15:00:03 2015 -0700
tree: improve menu placement at bottom of screen
src/tree/gb-tree.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/src/tree/gb-tree.c b/src/tree/gb-tree.c
index a648ef2..06b40fb 100644
--- a/src/tree/gb-tree.c
+++ b/src/tree/gb-tree.c
@@ -31,6 +31,7 @@ struct _GbTreePrivate
GbTreeNode *selection;
GtkTreeViewColumn *column;
GtkCellRenderer *cell_pixbuf;
+ GtkCellRenderer *cell_text;
GtkTreeStore *store;
guint building : 1;
guint show_icons : 1;
@@ -150,6 +151,36 @@ gb_tree_select (GbTree *tree,
IDE_EXIT;
}
+static guint
+gb_tree_get_row_height (GbTree *tree)
+{
+ const guint extra_padding = 2;
+ gint pix_min_height;
+ gint pix_nat_height;
+ gint text_min_height;
+ gint text_nat_height;
+
+ /*
+ * TODO:
+ *
+ * Determine where extra_padding comes from.
+ * Current thought is somewhere in styling.
+ */
+
+ g_assert (GB_IS_TREE (tree));
+
+ gtk_cell_renderer_get_preferred_height (tree->priv->cell_pixbuf,
+ GTK_WIDGET (tree),
+ &pix_min_height,
+ &pix_nat_height);
+ gtk_cell_renderer_get_preferred_height (tree->priv->cell_text,
+ GTK_WIDGET (tree),
+ &text_min_height,
+ &text_nat_height);
+
+ return MAX (pix_nat_height, text_nat_height) + extra_padding;
+}
+
static void
gb_tree_menu_position_func (GtkMenu *menu,
gint *x,
@@ -158,13 +189,36 @@ gb_tree_menu_position_func (GtkMenu *menu,
gpointer user_data)
{
GdkPoint *loc = user_data;
+ GtkRequisition req;
+ GdkRectangle rect;
+ GdkScreen *screen;
+ gint monitor;
g_return_if_fail (loc != NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &req);
+ screen = gtk_widget_get_screen (GTK_WIDGET (menu));
+ monitor = gdk_screen_get_monitor_at_point (screen, *x, *y);
+ gdk_screen_get_monitor_geometry (screen, monitor, &rect);
+
if ((loc->x != -1) && (loc->y != -1))
{
- *x = loc->x;
- *y = loc->y;
+ if ((loc->y + req.height) <= (rect.y + rect.height))
+ {
+ *x = loc->x;
+ *y = loc->y;
+ }
+ else
+ {
+ GtkWidget *attached;
+ guint row_height;
+
+ attached = gtk_menu_get_attach_widget (menu);
+ row_height = gb_tree_get_row_height (GB_TREE (attached));
+
+ *x = loc->x;
+ *y = loc->y + row_height - req.height;
+ }
}
}
@@ -1048,6 +1102,7 @@ gb_tree_init (GbTree *tree)
cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
"ellipsize", PANGO_ELLIPSIZE_NONE,
NULL);
+ tree->priv->cell_text = cell;
gtk_cell_layout_pack_start (column, cell, TRUE);
gtk_cell_layout_set_cell_data_func (column, cell, text_func, NULL, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]