Author: jtn
Date: Mon May  4 13:49:34 2015
New Revision: 28984

URL: http://svn.gna.org/viewcvs/freeciv?rev=28984&view=rev
Log:
In Gtk client, make the more-units arrow button fixed-size, so that the
layout doesn't jump around when switching focus between unit stacks of
different sizes.

See gna bug #23562.

Modified:
    branches/S2_6/client/gui-gtk-2.0/gui_main.c
    branches/S2_6/client/gui-gtk-3.0/gui_main.c

Modified: branches/S2_6/client/gui-gtk-2.0/gui_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/gui_main.c?rev=28984&r1=28983&r2=28984&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/gui_main.c (original)
+++ branches/S2_6/client/gui-gtk-2.0/gui_main.c Mon May  4 13:49:34 2015
@@ -178,6 +178,7 @@
 static GtkWidget *unit_below_pixmap_button[MAX_NUM_UNITS_BELOW];
 static GtkWidget *more_arrow_pixmap;
 static GtkWidget *more_arrow_pixmap_button;
+static GtkWidget *more_arrow_pixmap_container;
 
 static int unit_id_top;
 static int unit_ids[MAX_NUM_UNITS_BELOW];  /* ids of the units icons in 
@@ -865,24 +866,36 @@
   }
 
   /* create arrow (popup for all units on the selected tile) */
-  more_arrow_pixmap = gtk_image_new_from_pixbuf(
-          sprite_get_pixbuf(get_arrow_sprite(tileset, ARROW_RIGHT)));
-  g_object_ref(more_arrow_pixmap);
-  more_arrow_pixmap_button = gtk_event_box_new();
-  g_object_ref(more_arrow_pixmap_button);
-  gtk_container_add(GTK_CONTAINER(more_arrow_pixmap_button),
-                    more_arrow_pixmap);
-  g_signal_connect(more_arrow_pixmap_button,
-                   "button_press_event",
-                   G_CALLBACK(select_more_arrow_pixmap_callback), NULL);
+  {
+    GdkPixbuf *more_arrow = 
+      sprite_get_pixbuf(get_arrow_sprite(tileset, ARROW_RIGHT));
+
+    more_arrow_pixmap = gtk_image_new_from_pixbuf(more_arrow);
+    g_object_ref(more_arrow_pixmap);
+    more_arrow_pixmap_button = gtk_event_box_new();
+    g_object_ref(more_arrow_pixmap_button);
+    gtk_container_add(GTK_CONTAINER(more_arrow_pixmap_button),
+                      more_arrow_pixmap);
+    g_signal_connect(more_arrow_pixmap_button,
+                     "button_press_event",
+                     G_CALLBACK(select_more_arrow_pixmap_callback), NULL);
+    /* An extra layer so that we can hide the clickable button but keep
+     * an explicit size request to avoid the layout jumping around */
+    more_arrow_pixmap_container = gtk_alignment_new(0.5, 0.5, 0, 0);
+    g_object_ref(more_arrow_pixmap_container);
+    gtk_container_add(GTK_CONTAINER(more_arrow_pixmap_container),
+                      more_arrow_pixmap_button);
+    gtk_widget_set_size_request(more_arrow_pixmap_container,
+                                gdk_pixbuf_get_width(more_arrow), -1);
+  }
 
   if (!options.gui_gtk2_small_display_layout) {
     /* Display on bottom row. */
-    gtk_table_attach_defaults(GTK_TABLE(table), more_arrow_pixmap_button,
+    gtk_table_attach_defaults(GTK_TABLE(table), more_arrow_pixmap_container,
                               MAX_NUM_UNITS_BELOW, MAX_NUM_UNITS_BELOW+1, 1, 
2);
   } else {
     /* Display on top row (there is no bottom row). */
-    gtk_table_attach_defaults(GTK_TABLE(table), more_arrow_pixmap_button,
+    gtk_table_attach_defaults(GTK_TABLE(table), more_arrow_pixmap_container,
                               MAX_NUM_UNITS_BELOW, MAX_NUM_UNITS_BELOW+1, 0, 
1);
   }
 
@@ -914,9 +927,10 @@
       }
     }
     gtk_container_remove(GTK_CONTAINER(unit_pixmap_table),
-                         more_arrow_pixmap_button);
+                         more_arrow_pixmap_container);
     g_object_unref(more_arrow_pixmap);
     g_object_unref(more_arrow_pixmap_button);
+    g_object_unref(more_arrow_pixmap_container);
   }
 
   populate_unit_pixmap_table();

Modified: branches/S2_6/client/gui-gtk-3.0/gui_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/gui_main.c?rev=28984&r1=28983&r2=28984&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/gui_main.c (original)
+++ branches/S2_6/client/gui-gtk-3.0/gui_main.c Mon May  4 13:49:34 2015
@@ -163,6 +163,7 @@
 static GtkWidget *unit_below_pixmap_button[MAX_NUM_UNITS_BELOW];
 static GtkWidget *more_arrow_pixmap;
 static GtkWidget *more_arrow_pixmap_button;
+static GtkWidget *more_arrow_pixmap_container;
 
 static int unit_id_top;
 static int unit_ids[MAX_NUM_UNITS_BELOW];  /* ids of the units icons in 
@@ -874,24 +875,33 @@
   /* create arrow (popup for all units on the selected tile) */
   pix = sprite_get_pixbuf(get_arrow_sprite(tileset, ARROW_RIGHT));
   more_arrow_pixmap = gtk_image_new_from_pixbuf(pix);
-  g_object_unref(G_OBJECT(pix));
   g_object_ref(more_arrow_pixmap);
   more_arrow_pixmap_button = gtk_event_box_new();
   g_object_ref(more_arrow_pixmap_button);
-  gtk_event_box_set_visible_window(GTK_EVENT_BOX(more_arrow_pixmap_button), 
FALSE);
+  gtk_event_box_set_visible_window(GTK_EVENT_BOX(more_arrow_pixmap_button),
+                                   FALSE);
   gtk_container_add(GTK_CONTAINER(more_arrow_pixmap_button),
                     more_arrow_pixmap);
   g_signal_connect(more_arrow_pixmap_button,
                    "button_press_event",
                    G_CALLBACK(select_more_arrow_pixmap_callback), NULL);
+  /* An extra layer so that we can hide the clickable button but keep
+   * an explicit size request to avoid the layout jumping around */
+  more_arrow_pixmap_container = gtk_alignment_new(0.5, 0.5, 0, 0);
+  g_object_ref(more_arrow_pixmap_container);
+  gtk_container_add(GTK_CONTAINER(more_arrow_pixmap_container),
+                    more_arrow_pixmap_button);
+  gtk_widget_set_size_request(more_arrow_pixmap_container,
+                              gdk_pixbuf_get_width(pix), -1);
+  g_object_unref(G_OBJECT(pix));
 
   if (!options.gui_gtk3_small_display_layout) {
     /* Display on bottom row. */
-    gtk_grid_attach(GTK_GRID(table), more_arrow_pixmap_button,
+    gtk_grid_attach(GTK_GRID(table), more_arrow_pixmap_container,
                     MAX_NUM_UNITS_BELOW, 1, 1, 1);
   } else {
     /* Display on top row (there is no bottom row). */
-    gtk_grid_attach(GTK_GRID(table), more_arrow_pixmap_button,
+    gtk_grid_attach(GTK_GRID(table), more_arrow_pixmap_container,
                     MAX_NUM_UNITS_BELOW, 0, 1, 1);
   }
 
@@ -923,9 +933,10 @@
       }
     }
     gtk_container_remove(GTK_CONTAINER(unit_pixmap_table),
-                         more_arrow_pixmap_button);
+                         more_arrow_pixmap_container);
     g_object_unref(more_arrow_pixmap);
     g_object_unref(more_arrow_pixmap_button);
+    g_object_unref(more_arrow_pixmap_container);
   }
 
   populate_unit_pixmap_table();


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to