Commit 4f3665fb authored by Christian Neumair's avatar Christian Neumair Committed by Christian Neumair

Fix icon container size calculation (consider margins), use unified

2008-08-25  Christian Neumair  <cneumair@gnome.org>

	* libnautilus-private/nautilus-icon-container.c
	(icon_set_position):
	Fix icon container size calculation (consider margins),
	use unified container clamping code for RTL and LTR, that considers
	the entire item dimensions, instead of measuring just the icon
	rectangle.

svn path=/trunk/; revision=14522
parent 3d0617ed
2008-08-25 Christian Neumair <cneumair@gnome.org>
* libnautilus-private/nautilus-icon-container.c
(icon_set_position):
Fix icon container size calculation (consider margins),
use unified container clamping code for RTL and LTR, that considers
the entire item dimensions, instead of measuring just the icon
rectangle.
2008-08-24 Christian Neumair <cneumair@gnome.org>
* libnautilus-private/nautilus-directory.c
......
......@@ -110,9 +110,6 @@
#define SNAP_SIZE_X 78
#define SNAP_SIZE_Y 20
/* Value used to protect against icons being dragged outside of the desktop bounds */
#define DESKTOP_ICON_SAFETY_PAD 10
#define DEFAULT_SELECTION_BOX_ALPHA 0x40
#define DEFAULT_HIGHLIGHT_ALPHA 0xff
#define DEFAULT_NORMAL_ALPHA 0xff
......@@ -188,7 +185,7 @@ static NautilusIcon *get_icon_being_renamed (NautilusIco
static void finish_adding_new_icons (NautilusIconContainer *container);
static void update_label_color (EelBackground *background,
NautilusIconContainer *icon_container);
static void icon_get_bounding_box (NautilusIcon *icon,
static inline void icon_get_bounding_box (NautilusIcon *icon,
int *x1_return,
int *y1_return,
int *x2_return,
......@@ -302,16 +299,20 @@ icon_is_positioned (const NautilusIcon *icon)
return icon->x != ICON_UNPOSITIONED_VALUE && icon->y != ICON_UNPOSITIONED_VALUE;
}
/* x, y are the top-left coordinates of the icon. */
static void
icon_set_position (NautilusIcon *icon,
double x, double y)
{
NautilusIconContainer *container;
double pixels_per_unit;
int left, top, right, bottom;
int width;
int container_left, container_top, container_right, container_bottom;
int x1, x2, y1, y2;
int container_x, container_y, container_width, container_height;
EelDRect icon_bounds;
int item_width, item_height;
int height_above, height_below, width_left, width_right;
int min_x, max_x, min_y, max_y;
if (icon->x == x && icon->y == y) {
return;
......@@ -339,39 +340,39 @@ icon_set_position (NautilusIcon *icon,
*/
container_x = 0;
container_y = 0;
container_width = gdk_screen_width ();
container_height = gdk_screen_height ();
container_width = gdk_screen_width () - container_x
- container->details->left_margin
- container->details->right_margin;
container_height = gdk_screen_height () - container_y
- container->details->top_margin
- container->details->bottom_margin;
pixels_per_unit = EEL_CANVAS (container)->pixels_per_unit;
/* Clip the position of the icon within our desktop bounds */
left = container_x / pixels_per_unit;
top = container_y / pixels_per_unit;
right = left + container_width / pixels_per_unit;
bottom = top + container_height / pixels_per_unit;
container_left = container_x / pixels_per_unit;
container_top = container_y / pixels_per_unit;
container_right = container_left + container_width / pixels_per_unit;
container_bottom = container_top + container_height / pixels_per_unit;
icon_get_bounding_box (icon, &x1, &y1, &x2, &y2,
BOUNDS_USAGE_FOR_ENTIRE_ITEM);
item_width = x2 - x1;
item_height = y2 - y1;
icon_bounds = nautilus_icon_canvas_item_get_icon_rectangle (icon->item);
width = icon_bounds.x1 - icon_bounds.x0;
if (nautilus_icon_container_is_layout_rtl(container)) {
if (x + width < left + DESKTOP_ICON_SAFETY_PAD) {
x = left + DESKTOP_ICON_SAFETY_PAD - width;
}
if (x + width > right) {
x = right - width;
}
} else {
if (x > right - DESKTOP_ICON_SAFETY_PAD) {
x = right - DESKTOP_ICON_SAFETY_PAD;
}
if (x < left) {
x = left;
}
}
if (y > bottom - DESKTOP_ICON_SAFETY_PAD) {
y = bottom - DESKTOP_ICON_SAFETY_PAD;
}
if (y < top) {
y = top;
}
/* determine icon rectangle relative to item rectangle */
height_above = icon_bounds.y0 - y1;
height_below = y2 - icon_bounds.y1;
width_left = icon_bounds.x0 - x1;
width_right = x2 - icon_bounds.x1;
min_x = container_left + DESKTOP_PAD_HORIZONTAL + width_left;
max_x = container_right - DESKTOP_PAD_HORIZONTAL - item_width + width_left;
x = CLAMP (x, min_x, max_x);
min_y = container_top + height_above + DESKTOP_PAD_VERTICAL;
max_y = container_bottom - DESKTOP_PAD_VERTICAL - item_height + height_above;
y = CLAMP (y, min_y, max_y);
}
if (icon->x == ICON_UNPOSITIONED_VALUE) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment