summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColomban Wendling <[email protected]>2022-11-23 18:32:05 +0100
committerGitHub <[email protected]>2022-11-23 18:32:05 +0100
commitaf235d070905b146878bfbf11a88b37f94a07da7 (patch)
tree0c051f191f884f1e6ca44082f552033d44097acd
parent14dd4822ddbcafecd3bfb283920b6a60507134bd (diff)
downloadcaja-af235d070905b146878bfbf11a88b37f94a07da7.tar.bz2
caja-af235d070905b146878bfbf11a88b37f94a07da7.tar.xz
icon view: Refresh icon positions for manual layout on zoom change (#1676)
When zoom changes on a manual layout icon view, the available area changes and can lead to some icons to either overflow or be able to go back to their actually saved position. This is done correctly when the view is reloaded entirely, but not in response to zoom change, leading to disappearing icons (when zoom increases) or unexpected empty space (when zoom decreases). Fix this by re-computing actual positions based on saved positions when zoom changes, to match what would actually happen when the view gets loaded.
-rw-r--r--libcaja-private/caja-icon-container.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c
index 2180d218..0d839597 100644
--- a/libcaja-private/caja-icon-container.c
+++ b/libcaja-private/caja-icon-container.c
@@ -296,14 +296,15 @@ icon_is_positioned (const CajaIcon *icon)
/* x, y are the top-left coordinates of the icon. */
static void
-icon_set_position (CajaIcon *icon,
- double x, double y)
+icon_set_position_full (CajaIcon *icon,
+ double x, double y,
+ gboolean force)
{
CajaIconContainer *container;
int x1, x2, y1, y2;
EelDRect icon_bounds;
- if (icon->x == x && icon->y == y)
+ if (!force && icon->x == x && icon->y == y)
{
return;
}
@@ -392,6 +393,13 @@ icon_set_position (CajaIcon *icon,
}
static void
+icon_set_position (CajaIcon *icon,
+ double x, double y)
+{
+ icon_set_position_full (icon, x, y, FALSE);
+}
+
+static void
icon_get_size (CajaIconContainer *container,
CajaIcon *icon,
guint *size)
@@ -2387,7 +2395,8 @@ redo_layout (CajaIconContainer *container)
}
static void
-reload_icon_positions (CajaIconContainer *container)
+reload_icon_positions (CajaIconContainer *container,
+ gboolean layout_changed)
{
GList *p, *no_position_icons;
gboolean have_stored_position;
@@ -2417,7 +2426,12 @@ reload_icon_positions (CajaIconContainer *container)
&have_stored_position);
if (have_stored_position)
{
- icon_set_position (icon, position.x, position.y);
+ icon_set_position_full (icon, position.x, position.y,
+ /* if only layout changed, don't bother
+ * updating already valid info. If however
+ * e.g. zoom changed, x and y might now be
+ * overflowing and need recomputing */
+ !layout_changed);
item = EEL_CANVAS_ITEM (icon->item);
caja_icon_canvas_item_get_bounds_for_layout (icon->item,
&bounds.x0,
@@ -2435,15 +2449,20 @@ reload_icon_positions (CajaIconContainer *container)
bottom = bounds.y1;
}
}
- else
+ else if (layout_changed)
{
no_position_icons = g_list_prepend (no_position_icons, icon);
}
}
- no_position_icons = g_list_reverse (no_position_icons);
- /* Place all the other icons. */
- lay_down_icons (container, no_position_icons, bottom + ICON_PAD_BOTTOM);
+ if (layout_changed)
+ {
+ /* If layout changed, place all the other icons that don't have stored
+ * positions yet */
+ no_position_icons = g_list_reverse (no_position_icons);
+ lay_down_icons (container, no_position_icons, bottom + ICON_PAD_BOTTOM);
+ }
+
g_list_free (no_position_icons);
}
@@ -8021,6 +8040,11 @@ caja_icon_container_request_update_all (CajaIconContainer *container)
caja_icon_container_update_icon (container, icon);
}
+ /* on manual layout we need to reload icon positions, as that might be
+ * affected by the view size, zoom, etc. */
+ if (!container->details->auto_layout)
+ reload_icon_positions (container, FALSE);
+
redo_layout (container);
container->details->is_loading = FALSE;
}
@@ -8622,7 +8646,7 @@ caja_icon_container_set_auto_layout (CajaIconContainer *container,
if (!auto_layout)
{
- reload_icon_positions (container);
+ reload_icon_positions (container, TRUE);
caja_icon_container_freeze_icon_positions (container);
}