[PATCH] Improve icon container size calculation
- From: Christian Neumair <chris gnome-de org>
- To: nautilus-list gnome org
- Subject: [PATCH] Improve icon container size calculation
- Date: Wed, 22 Feb 2006 23:35:21 +0100
The attached patch is meant to fix issues where the offset of the icons
wrt the visible icon container border vary based on the panel width.
This patch isn't tested too well but it is obvious that the old logic
was wrong, i.e. pixel sizes were added to canvas unit sizes.
The original motivation was that I hoped to be able to easily fix the
problems reported by Martin where icons randomly jumped around
(reproducible when pressing ctrl-R).
The issue seems to be that with a non-tight layout and two icons
spanning more than one SNAP_SIZE_X wide column, they're considered to
overlap although they don't seem to overlap to the user.
I'm not sure what the best further steps are, we could
a) rework some of the grid logic to maybe have a more fine-grained grid.
Sounds reasonable. IIRC, Sebastien Bacher also requested that the drop
grid (i.e. the tight one) matches the normal wise grid used in this
case.
b) replace the NAUTILUS_IS_DESKTOP_ICON_FILE check in
fm_icon_view_add_file with has_volume || has_drive. I think that's how I
wrote it originally. Alex, was this modified to not break computer:///?
Maybe we should just pass FALSE for ordinary icon views and override the
_add handler in fm-desktop-icon-view.c, adding extra volume/drive
checks. I still think we'd have issues with network mounts that are
close to other icons.
c) revert the last patch which removed the usage of a tight layout for
semi positioned icons. Worst option IMHO.
Also note that icon_set_position could need some love, it doesn't really
clip the icon into the visible area, because it doesn't subtract the
borders.
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.408
diff -u -p -r1.408 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c 6 Feb 2006 16:48:08 -0000 1.408
+++ libnautilus-private/nautilus-icon-container.c 22 Feb 2006 22:16:06 -0000
@@ -806,12 +806,14 @@ nautilus_icon_container_update_scroll_re
(EEL_CANVAS (container),
(double) - container->details->left_margin,
(double) - container->details->top_margin,
- (double) (allocation->width - 1) / pixels_per_unit
+ ((double) (allocation->width - 1)
- container->details->left_margin
- - container->details->right_margin,
- (double) (allocation->height - 1) / pixels_per_unit
+ - container->details->right_margin)
+ / pixels_per_unit,
+ ((double) (allocation->height - 1)
- container->details->top_margin
- - container->details->bottom_margin);
+ - container->details->bottom_margin)
+ / pixels_per_unit);
return;
}
@@ -999,7 +1001,8 @@ lay_down_icons_horizontal (NautilusIconC
/ EEL_CANVAS (container)->pixels_per_unit;
canvas_height = (GTK_WIDGET (container)->allocation.height
- container->details->top_margin
- - container->details->bottom_margin) / EEL_CANVAS (container)->pixels_per_unit;
+ - container->details->bottom_margin)
+ / EEL_CANVAS (container)->pixels_per_unit;
max_icon_width = max_text_width = 0.0;
@@ -1192,14 +1195,14 @@ placement_grid_new (NautilusIconContaine
int i;
/* Get container dimensions */
- width = GTK_WIDGET (container)->allocation.width /
- EEL_CANVAS (container)->pixels_per_unit
+ width = (GTK_WIDGET (container)->allocation.width
- container->details->left_margin
- - container->details->right_margin;
- height = GTK_WIDGET (container)->allocation.height /
- EEL_CANVAS (container)->pixels_per_unit
+ - container->details->right_margin) /
+ EEL_CANVAS (container)->pixels_per_unit;
+ height = (GTK_WIDGET (container)->allocation.height
- container->details->top_margin
- - container->details->bottom_margin;
+ - container->details->bottom_margin) /
+ EEL_CANVAS (container)->pixels_per_unit;
num_columns = width / SNAP_SIZE_X;
num_rows = height / SNAP_SIZE_Y;
@@ -1270,10 +1273,16 @@ placement_grid_mark (PlacementGrid *grid
}
static void
-canvas_position_to_grid_position (PlacementGrid *grid,
+canvas_position_to_grid_position (NautilusIconContainer *container,
+ PlacementGrid *grid,
ArtIRect canvas_position,
ArtIRect *grid_position)
{
+ canvas_position.x0 -= container->details->left_margin / EEL_CANVAS (container)->pixels_per_unit;
+ canvas_position.x1 -= container->details->left_margin / EEL_CANVAS (container)->pixels_per_unit;
+ canvas_position.y0 -= container->details->top_margin / EEL_CANVAS (container)->pixels_per_unit;
+ canvas_position.y1 -= container->details->top_margin / EEL_CANVAS (container)->pixels_per_unit;
+
/* The first causes minimal moving around during a snap, but
* can end up with partially overlapping icons. The second one won't
* allow any overlapping, but can cause more movement to happen
@@ -1297,7 +1306,9 @@ canvas_position_to_grid_position (Placem
}
static void
-placement_grid_mark_icon (PlacementGrid *grid, NautilusIcon *icon)
+placement_grid_mark_icon (NautilusIconContainer *container,
+ PlacementGrid *grid,
+ NautilusIcon *icon)
{
ArtIRect icon_pos;
ArtIRect grid_pos;
@@ -1305,7 +1316,9 @@ placement_grid_mark_icon (PlacementGrid
icon_get_bounding_box (icon,
&icon_pos.x0, &icon_pos.y0,
&icon_pos.x1, &icon_pos.y1);
- canvas_position_to_grid_position (grid,
+
+ canvas_position_to_grid_position (container,
+ grid,
icon_pos,
&grid_pos);
placement_grid_mark (grid, grid_pos);
@@ -1328,14 +1341,14 @@ find_empty_location (NautilusIconContain
gboolean collision;
/* Get container dimensions */
- canvas_width = GTK_WIDGET (container)->allocation.width /
- EEL_CANVAS (container)->pixels_per_unit
+ canvas_width = (GTK_WIDGET (container)->allocation.width
- container->details->left_margin
- - container->details->right_margin;
- canvas_height = GTK_WIDGET (container)->allocation.height /
- EEL_CANVAS (container)->pixels_per_unit
+ - container->details->right_margin) /
+ EEL_CANVAS (container)->pixels_per_unit;
+ canvas_height = (GTK_WIDGET (container)->allocation.height
- container->details->top_margin
- - container->details->bottom_margin;
+ - container->details->bottom_margin) /
+ EEL_CANVAS (container)->pixels_per_unit;
icon_get_bounding_box (icon,
&icon_position.x0, &icon_position.y0,
@@ -1358,7 +1371,8 @@ find_empty_location (NautilusIconContain
collision = FALSE;
- canvas_position_to_grid_position (grid,
+ canvas_position_to_grid_position (container,
+ grid,
icon_position,
&grid_position);
@@ -1417,7 +1431,7 @@ align_icons (NautilusIconContainer *cont
icon_set_position (icon, x, y);
- placement_grid_mark_icon (grid, icon);
+ placement_grid_mark_icon (container, grid, icon);
}
g_list_free (unplaced_icons);
@@ -1473,7 +1487,7 @@ lay_down_icons_tblr (NautilusIconContain
if (grid) {
for (p = placed_icons; p != NULL; p = p->next) {
placement_grid_mark_icon
- (grid, (NautilusIcon*)p->data);
+ (container, grid, (NautilusIcon*)p->data);
}
/* Place unplaced icons in the best locations */
@@ -1493,7 +1507,7 @@ lay_down_icons_tblr (NautilusIconContain
&x, &y);
icon_set_position (icon, x, y);
- placement_grid_mark_icon (grid, icon);
+ placement_grid_mark_icon (container, grid, icon);
}
placement_grid_free (grid);
@@ -5655,7 +5669,7 @@ finish_adding_new_icons (NautilusIconCon
icon = p->data;
if (icon_is_positioned (icon) && !icon->has_lazy_position) {
- placement_grid_mark_icon (grid, icon);
+ placement_grid_mark_icon (container, grid, icon);
}
}
@@ -5672,7 +5686,7 @@ finish_adding_new_icons (NautilusIconCon
icon_set_position (icon, x, y);
- placement_grid_mark_icon (grid, icon);
+ placement_grid_mark_icon (container, grid, icon);
/* ensure that next time we run this code, the formerly semi-positioned
* icons are treated as being positioned. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]