[nautilus/wip/csoriano/zoomsv3: 1/9] canvas-item: add dynamic label sizing for zoom levels



commit b2bf9525eebe219a8827f4c9e1a3123810391bef
Author: Carlos Soriano <csoriano gnome org>
Date:   Mon Feb 22 00:38:41 2016 +0100

    canvas-item: add dynamic label sizing for zoom levels
    
    Last commit added dynamic grid size for canvas items.
    That gave me the idea to do the same for the label, allowing a mostly
    complete dynamic padding and label sizing for zoom levels.
    
    The calculations could be done by multiplying pixel_per_unit fore each
    padding level and then adjust, but in this way we have different padding
    per each level, giving more to smaller zooms than biggers ones.

 libnautilus-private/nautilus-canvas-container.c |    9 +++---
 libnautilus-private/nautilus-canvas-item.c      |   32 ++++++++++++++++++++---
 2 files changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/libnautilus-private/nautilus-canvas-container.c b/libnautilus-private/nautilus-canvas-container.c
index b164522..8a4270d 100644
--- a/libnautilus-private/nautilus-canvas-container.c
+++ b/libnautilus-private/nautilus-canvas-container.c
@@ -97,11 +97,12 @@
  * So with an 80px grid unit, a 100px canvas item would take two grid units,
  * where a 76px canvas item would only take one.
  * Canvas items are then centered in the extra available space.
+ * Keep in sync with MAX_TEXT_WIDTH at nautilus-canvas-item.
  */
-#define SMALL_ICON_GRID_WIDTH 58
-#define STANDARD_ICON_GRID_WIDTH 56
-#define LARGE_ICON_GRID_WIDTH 56
-#define LARGER_ICON_GRID_WIDTH 64
+#define SMALL_ICON_GRID_WIDTH 130
+#define STANDARD_ICON_GRID_WIDTH 130
+#define LARGE_ICON_GRID_WIDTH 96
+#define LARGER_ICON_GRID_WIDTH 128
 
 /* Desktop layout mode defines */
 #define DESKTOP_PAD_HORIZONTAL         10
diff --git a/libnautilus-private/nautilus-canvas-item.c b/libnautilus-private/nautilus-canvas-item.c
index dbd6fe9..c558ba2 100644
--- a/libnautilus-private/nautilus-canvas-item.c
+++ b/libnautilus-private/nautilus-canvas-item.c
@@ -53,9 +53,11 @@
 #define TEXT_BACK_PADDING_X 4
 #define TEXT_BACK_PADDING_Y 1
 
-/* Width of the label with the standard icon size NAUTILUS_CANVAS_ICON_SIZE_STANDARD.
- * It will adapt to other sizes keeping the same space.*/
-#define MAX_TEXT_WIDTH_STANDARD 110
+/* Width of the label, keep in sync with ICON_GRID_WIDTH at nautilus-canvas-container.c */
+#define MAX_TEXT_WIDTH_SMALL 126
+#define MAX_TEXT_WIDTH_STANDARD 126
+#define MAX_TEXT_WIDTH_LARGE 92
+#define MAX_TEXT_WIDTH_LARGER 120
 
 /* special text height handling
  * each item has three text height variables:
@@ -676,10 +678,32 @@ static double
 nautilus_canvas_item_get_max_text_width (NautilusCanvasItem *item)
 {
        EelCanvasItem *canvas_item;
+       NautilusCanvasContainer *container;
+       guint max_text_width;
+
 
        canvas_item = EEL_CANVAS_ITEM (item);
+       container = canvas_item->canvas;
+
+       switch (nautilus_canvas_container_get_zoom_level (container)) {
+       case NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL:
+         max_text_width = MAX_TEXT_WIDTH_SMALL;
+         break;
+       case NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD:
+         max_text_width = MAX_TEXT_WIDTH_STANDARD;
+         break;
+       case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE:
+         max_text_width = MAX_TEXT_WIDTH_LARGE;
+         break;
+       case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER:
+         max_text_width = MAX_TEXT_WIDTH_LARGER;
+         break;
+       default:
+         g_warning ("Zoom level not valid. This may incur in missaligned grid");
+         max_text_width = MAX_TEXT_WIDTH_STANDARD;
+       }
 
-       return MAX_TEXT_WIDTH_STANDARD * canvas_item->canvas->pixels_per_unit - 2 * TEXT_BACK_PADDING_X;
+       return max_text_width * canvas_item->canvas->pixels_per_unit - 2 * TEXT_BACK_PADDING_X;
 }
 
 static void


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