Re: [PATCH] Neaten up the layout for text beside icons



I had a thought about this last night, and decided that to get the
grid layout to be neat and to use the most possible space is to set
the gridsize to the size of the largest icon.

Attached is the patch to implement this. There's also some other fixes
to my earlier one, that was causing bad layout in tight layout mode.
It also removes an unused line of code.

The only case I can foresee that this will not look so good, is where
the user has one or two really HUGE icons (> 2 times the width of the
rest of the icons), but this is a very rare case, and if we do want to
solve that, then we just need to check if icons could fit into factors
of grid_size. but I don't think its necessary.

This also makes grid layout in text-under-icons mode neater too.

iain

On Thu, 7 Oct 2004 23:10:51 +0100, Iain * <iaingnome gmail com> wrote:
> The reason the second screenshot it messed up is because the icon
> width is just greater than 160 pixels and so it is aligned to the
> second column, at 320 pixels. This was the case I explained as case b
> in my earlier mail
> 
> "b) when the icon's width is actually just over 210 pixels, in which
> case the icon gets allocated 420 pixels (the next multiple of the grid
> size) and so in the case of say an icon being 215 pixels wide, you end
> up with 205 pixels blank space."
> 
> There really isn't any solution for this, as to align the text to the
> first columns baseline[1] would mean that part of the icon isn't going
> to be on screen. I'm not sure if there's a fix for this, its a
> limitation of having icons of variable sizes.
> 
> iain
> [1] I call it baseline, but really its a vertical line that runs from
> the top of the column and has the icon on the left hand side, and the
> text on the right.
> 
> On Thu, 7 Oct 2004 13:13:13 -0400, Vincent Noel <vincent noel gmail com> wrote:
> 
> > HOWEVER, while doing this I think I ran into the reason for the
> 
> 
> > 210-pixels grid : thumbnails. If you set the grid size at 160 pixels,
> > the alignment of thumbnails is screwed. See second screenshot.
> >
>
Index: nautilus-icon-canvas-item.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-canvas-item.c,v
retrieving revision 1.185
diff -u -p -r1.185 nautilus-icon-canvas-item.c
--- nautilus-icon-canvas-item.c	6 Oct 2004 15:21:13 -0000	1.185
+++ nautilus-icon-canvas-item.c	8 Oct 2004 11:04:05 -0000
@@ -640,7 +640,7 @@ compute_text_rectangle (const NautilusIc
 	if (NAUTILUS_ICON_CONTAINER (EEL_CANVAS_ITEM (item)->canvas)->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
                 text_rectangle.x0 = icon_rectangle.x1;
                 text_rectangle.x1 = text_rectangle.x0 + text_width;
-                text_rectangle.y0 = icon_rectangle.y0;
+                text_rectangle.y0 = (icon_rectangle.y0 + icon_rectangle.y1) / 2- (int) text_height / 2;
                 text_rectangle.y1 = text_rectangle.y0 + text_height + LABEL_OFFSET / pixels_per_unit;
 	} else {
                 text_rectangle.x0 = (icon_rectangle.x0 + icon_rectangle.x1) / 2 - (int) text_width / 2;
Index: nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.376
diff -u -p -r1.376 nautilus-icon-container.c
--- nautilus-icon-container.c	6 Oct 2004 14:03:05 -0000	1.376
+++ nautilus-icon-container.c	8 Oct 2004 11:04:06 -0000
@@ -121,6 +121,9 @@
 #define MINIMUM_EMBEDDED_TEXT_RECT_WIDTH       20
 #define MINIMUM_EMBEDDED_TEXT_RECT_HEIGHT      20
 
+/* From nautilus-icon-canvas-item.c */
+#define MAX_TEXT_WIDTH_BESIDE 90
+
 #define SNAP_HORIZONTAL(func,x) ((func ((double)((x) - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X) * SNAP_SIZE_X) + DESKTOP_PAD_HORIZONTAL)
 #define SNAP_VERTICAL(func, y) ((func ((double)((y) - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y) * SNAP_SIZE_Y) + DESKTOP_PAD_VERTICAL)
 
@@ -888,6 +891,7 @@ resort (NautilusIconContainer *container
 	sort_icons (container, &container->details->icons);
 }
 
+#if 0
 static double
 get_grid_width (NautilusIconContainer *container)
 {
@@ -897,9 +901,10 @@ get_grid_width (NautilusIconContainer *c
 		return STANDARD_ICON_GRID_WIDTH;
 	}
 }
-
+#endif
 typedef struct {
 	double width;
+	double height;
 	double x_offset;
 	double y_offset;
 } IconPositions;
@@ -909,28 +914,35 @@ lay_down_one_line (NautilusIconContainer
 		   GList *line_start,
 		   GList *line_end,
 		   double y,
+		   double max_height,
 		   GArray *positions)
 {
 	GList *p;
 	NautilusIcon *icon;
-	double x;
+	double x, y_offset;
 	IconPositions *position;
 	int i;
 
 	/* FIXME: Should layout differently when in RTL base mode */
 
 	/* Lay out the icons along the baseline. */
-	x = 0;
+	x = ICON_PAD_LEFT;
 	i = 0;
 	for (p = line_start; p != line_end; p = p->next) {
 		icon = p->data;
 
 		position = &g_array_index (positions, IconPositions, i++);
+		
+		if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
+			y_offset = (max_height - position->height) / 2;
+		} else {
+			y_offset = position->y_offset;
+		}
 
 		icon_set_position
 			(icon,
 			 x + position->x_offset,
-			 y + position->y_offset);
+			 y + y_offset);
 
 		x += position->width;
 	}
@@ -952,7 +964,6 @@ lay_down_icons_horizontal (NautilusIconC
 	EelCanvasItem *item;
 	double max_height_above, max_height_below;
 	double height_above, height_below;
-	int icons_per_line;
 	double line_width;
 	gboolean gridded_layout;
 	double grid_width;
@@ -961,6 +972,10 @@ lay_down_icons_horizontal (NautilusIconC
 
 	g_assert (NAUTILUS_IS_ICON_CONTAINER (container));
 
+	if (icons == NULL) {
+		return;
+	}
+
 	positions = g_array_new (FALSE, FALSE, sizeof (IconPositions));
 	
 	/* Lay out icons a line at a time. */
@@ -969,12 +984,20 @@ lay_down_icons_horizontal (NautilusIconC
 			- container->details->right_margin)
 		/ EEL_CANVAS (container)->pixels_per_unit;
 
-	grid_width = get_grid_width (container);
-	icons_per_line = floor (canvas_width / grid_width);
+	grid_width = 0.0;
+	/* Would it be worth caching these bounds for the next loop? */
+	for (p = icons; p != NULL; p = p->next) {
+		icon = p->data;
+
+		eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
+					    &bounds.x0, &bounds.y0,
+					    &bounds.x1, &bounds.y1);
+		grid_width = MAX (grid_width, ceil (bounds.x1 - bounds.x0) + ICON_PAD_LEFT + ICON_PAD_RIGHT);
+	}
 
 	gridded_layout = !nautilus_icon_container_is_tighter_layout (container);
 	
-	line_width = 0;
+	line_width = container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE ? ICON_PAD_LEFT : 0;
 	line_start = icons;
 	y = start_y;
 	i = 0;
@@ -989,8 +1012,8 @@ lay_down_icons_horizontal (NautilusIconC
 		
 		/* Assume it's only one level hierarchy to avoid costly affine calculations */
 		eel_canvas_item_get_bounds (item,
-					      &bounds.x0, &bounds.y0,
-					      &bounds.x1, &bounds.y1);
+					    &bounds.x0, &bounds.y0,
+					    &bounds.x1, &bounds.y1);
 
 		icon_bounds = nautilus_icon_canvas_item_get_icon_rectangle (icon->item);
 		text_bounds = nautilus_icon_canvas_item_get_text_rectangle (icon->item);
@@ -1000,9 +1023,9 @@ lay_down_icons_horizontal (NautilusIconC
 
 
 		} else {
-			icon_width = ICON_PAD_LEFT + (bounds.x1 - bounds.x0) + ICON_PAD_RIGHT + 8; /* 8 pixels extra for fancy selection box */
+			icon_width = (bounds.x1 - bounds.x0) + ICON_PAD_RIGHT + 8; /* 8 pixels extra for fancy selection box */
 		}		
-
+		
 		/* Calculate size above/below baseline */
 		height_above = icon_bounds.y1 - bounds.y0;
 		height_below = bounds.y1 - icon_bounds.y1;
@@ -1020,11 +1043,11 @@ lay_down_icons_horizontal (NautilusIconC
 				/* Advance to the baseline. */
 				y += ICON_PAD_TOP + max_height_above;
 			}
-			
-			lay_down_one_line (container, line_start, p, y, positions);
+
+			lay_down_one_line (container, line_start, p, y, max_height_above, positions);
 			
 			if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
-			y += max_height_above + max_height_below + ICON_PAD_BOTTOM;
+				y += max_height_above + max_height_below + ICON_PAD_BOTTOM;
 			} else {
 				/* Advance to next line. */
 				y += max_height_below + ICON_PAD_BOTTOM;
@@ -1048,9 +1071,14 @@ lay_down_icons_horizontal (NautilusIconC
 		g_array_set_size (positions, i + 1);
 		position = &g_array_index (positions, IconPositions, i++);
 		position->width = icon_width;
-		
+		position->height = icon_bounds.y1 - icon_bounds.y0;
+
 		if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
-			position->x_offset = (MAXIMUM_IMAGE_SIZE - (icon_bounds.x1 - icon_bounds.x0));
+			if (gridded_layout) {
+				position->x_offset = icon_width - ((icon_bounds.x1 - icon_bounds.x0) + MAX_TEXT_WIDTH_BESIDE);
+			} else {
+				position->x_offset = icon_width - ((icon_bounds.x1 - icon_bounds.x0) + (text_bounds.x1 - text_bounds.x0));
+			}
 			position->y_offset = 0;
 		} else {
 			position->x_offset = (icon_width - (icon_bounds.x1 - icon_bounds.x0)) / 2;
@@ -1070,7 +1098,7 @@ lay_down_icons_horizontal (NautilusIconC
 				y += ICON_PAD_TOP + max_height_above;
 			}
 		
-		lay_down_one_line (container, line_start, NULL, y, positions);
+		lay_down_one_line (container, line_start, NULL, y, max_height_above, positions);
 		
 		/* Advance to next line. */
 		y += max_height_below + ICON_PAD_BOTTOM;


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