[gnome-initial-setup] cc-timezone-map: Respect aspect ratio
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup] cc-timezone-map: Respect aspect ratio
- Date: Thu, 31 Oct 2013 20:49:21 +0000 (UTC)
commit f2d2bf8f18b7c5c9dd2acf9517a3532353c0359c
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Thu Oct 31 15:53:26 2013 -0400
cc-timezone-map: Respect aspect ratio
.../pages/timezone/cc-timezone-map.c | 80 ++++++++++++++------
.../pages/timezone/gis-timezone-page.ui | 27 -------
2 files changed, 56 insertions(+), 51 deletions(-)
---
diff --git a/gnome-initial-setup/pages/timezone/cc-timezone-map.c
b/gnome-initial-setup/pages/timezone/cc-timezone-map.c
index 6eb0912..d128770 100644
--- a/gnome-initial-setup/pages/timezone/cc-timezone-map.c
+++ b/gnome-initial-setup/pages/timezone/cc-timezone-map.c
@@ -58,37 +58,66 @@ cc_timezone_map_dispose (GObject *object)
G_OBJECT_CLASS (cc_timezone_map_parent_class)->dispose (object);
}
-/* GtkWidget functions */
+static double
+get_ratio (CcTimezoneMap *map)
+{
+ CcTimezoneMapPrivate *priv = map->priv;
+ return (double) gdk_pixbuf_get_width (priv->orig_background) / gdk_pixbuf_get_height
(priv->orig_background);
+}
+
static void
-cc_timezone_map_get_preferred_width (GtkWidget *widget,
- gint *minimum,
- gint *natural)
+cc_timezone_map_get_preferred_height_for_width (GtkWidget *widget,
+ int width,
+ int *minimum_height,
+ int *natural_height)
{
- /* choose a minimum size small enough to prevent the window
- * from growing horizontally
- */
- if (minimum != NULL)
- *minimum = 300;
- if (natural != NULL)
- *natural = 300;
+ double pix_ratio = get_ratio (CC_TIMEZONE_MAP (widget));
+
+ if (minimum_height)
+ *minimum_height = width / pix_ratio;
+ if (natural_height)
+ *natural_height = width / pix_ratio;
}
static void
+cc_timezone_map_get_preferred_width_for_height (GtkWidget *widget,
+ int height,
+ int *minimum_width,
+ int *natural_width)
+{
+ double pix_ratio = get_ratio (CC_TIMEZONE_MAP (widget));
+
+ if (minimum_width)
+ *minimum_width = height * pix_ratio;
+ if (natural_width)
+ *natural_width = height * pix_ratio;
+}
+
+#define MIN_WIDTH 300
+
+static void
cc_timezone_map_get_preferred_height (GtkWidget *widget,
- gint *minimum,
- gint *natural)
+ int *minimum_height,
+ int *natural_height)
{
- CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
- gint size;
-
- /* The + 20 here is a slight tweak to make the map fill the
- * panel better without causing horizontal growing
- */
- size = 300 * gdk_pixbuf_get_height (priv->orig_background) / gdk_pixbuf_get_width (priv->orig_background)
+ 20;
- if (minimum != NULL)
- *minimum = size;
- if (natural != NULL)
- *natural = size;
+ cc_timezone_map_get_preferred_height_for_width (widget, MIN_WIDTH, minimum_height, natural_height);
+}
+
+static void
+cc_timezone_map_get_preferred_width (GtkWidget *widget,
+ int *minimum_width,
+ int *natural_width)
+{
+ if (minimum_width)
+ *minimum_width = MIN_WIDTH;
+ if (natural_width)
+ *natural_width = MIN_WIDTH;
+}
+
+static GtkSizeRequestMode
+cc_timezone_map_get_request_mode (GtkWidget *widget)
+{
+ return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
}
static void
@@ -261,6 +290,9 @@ cc_timezone_map_class_init (CcTimezoneMapClass *klass)
widget_class->get_preferred_width = cc_timezone_map_get_preferred_width;
widget_class->get_preferred_height = cc_timezone_map_get_preferred_height;
+ widget_class->get_preferred_width_for_height = cc_timezone_map_get_preferred_width_for_height;
+ widget_class->get_preferred_height_for_width = cc_timezone_map_get_preferred_height_for_width;
+ widget_class->get_request_mode = cc_timezone_map_get_request_mode;
widget_class->size_allocate = cc_timezone_map_size_allocate;
widget_class->draw = cc_timezone_map_draw;
}
diff --git a/gnome-initial-setup/pages/timezone/gis-timezone-page.ui
b/gnome-initial-setup/pages/timezone/gis-timezone-page.ui
index 5bc5dcf..13038bb 100644
--- a/gnome-initial-setup/pages/timezone/gis-timezone-page.ui
+++ b/gnome-initial-setup/pages/timezone/gis-timezone-page.ui
@@ -21,11 +21,6 @@
<attribute name="scale" value="1.6"/>
</attributes>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
</child>
<child>
<object class="GtkBox" id="status_box">
@@ -57,11 +52,6 @@
</packing>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
</child>
<child>
<object class="GtkToggleButton" id="search_button">
@@ -80,18 +70,8 @@
</object>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
</child>
<child>
<object class="GtkFrame" id="map_frame">
@@ -100,7 +80,6 @@
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="hexpand">True</property>
- <property name="vexpand">True</property>
<property name="label_xalign">0</property>
<child>
<object class="GtkOverlay" id="map_overlay">
@@ -109,7 +88,6 @@
<object class="CcTimezoneMap" id="map">
<property name="visible">True</property>
<property name="hexpand">True</property>
- <property name="vexpand">True</property>
</object>
</child>
<child type="overlay">
@@ -124,11 +102,6 @@
</object>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">2</property>
- </packing>
</child>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]