Fixed layout bugs
authorEnrico Zini <enrico@enricozini.org>
Thu, 10 Dec 2009 13:43:04 +0000 (13:43 +0000)
committerEnrico Zini <enrico@enricozini.org>
Thu, 10 Dec 2009 13:43:04 +0000 (13:43 +0000)
src/fisheye.vala

index 4efcadac44834b9cd17576b5edec1db98c04263c..15550ec3c4517396d5d76c06eea2a64d24f24e59 100644 (file)
@@ -53,6 +53,7 @@ public class FisheyeList : Gtk.DrawingArea
        protected bool focus_layout_needed;
        protected bool is_fisheye;
        protected int focus_step_size;
+       protected int focus_area_start;
 
        // Number of elements in full focus
        protected int _focus_size;
@@ -164,15 +165,15 @@ public class FisheyeList : Gtk.DrawingArea
 
                if (is_fisheye)
                {
-                       focus_locked = !focus_layout_needed && x < allocation.width/2 && y >= focus_info[0].y && y < focus_info[focus_end - focus_first].y;
+                       focus_locked = !focus_layout_needed && x < allocation.width/2 && y >= focus_area_start+focus_info[0].y && y < focus_area_start+focus_info[focus_end - focus_first].y;
 
-                       if (y < focus_info[0].y || y >= focus_info[focus_end - focus_first].y)
+                       if (y < focus_area_start+focus_info[0].y || y >= focus_area_start+focus_info[focus_end - focus_first].y)
                                cur_el = y * (label_cache.length+1) / allocation.height;
                        else
-                               for (int idx = focus_first; idx < focus_end; ++idx)
-                                       if (y < focus_info[idx-focus_first+1].y)
+                               for (int idx = 0; idx < focus_info.length; ++idx)
+                                       if (y - focus_area_start < focus_info[idx].y + renderer_sizes[focus_info[idx].renderer])
                                        {
-                                               cur_el = idx;
+                                               cur_el = idx + focus_first;
                                                break;
                                        }
 
@@ -332,13 +333,10 @@ public class FisheyeList : Gtk.DrawingArea
                        return;
                }
 
-               int focus_area_size = 2 * focus_step_size + _focus_size * max_renderer_size;
-               int anchor_y = cur_el * allocation.height / (label_cache.length+1);
-               int focus_area_start = anchor_y - (focus_area_size - max_renderer_size) / 2;
-               if (focus_area_start < 0) focus_area_start = 0;
-
                focus_first = cur_el - _focus_size/2 - steps;
                if (focus_first < 0) focus_first = 0;
+               if (focus_first + focus_info.length > label_cache.length)
+                       focus_first = label_cache.length - focus_info.length;
 
                /*
                int full_focus_start = anchor_y - (_focus_size/2) * max_renderer_size;
@@ -346,21 +344,35 @@ public class FisheyeList : Gtk.DrawingArea
                int steps_start = full_focus_start - focus_step_size;
                */
 
-               int cur_pos = focus_area_start;
-               int cur_idx = focus_first;
-               while (cur_pos < allocation.height && cur_idx < label_cache.length && cur_idx - focus_first < focus_info.length)
+               int cur_pos = 0;
+               int cur_idx = 0;
+               int focus_area_pre = 0;
+               while (cur_pos < allocation.height && cur_idx < focus_info.length)
                {
-                       focus_info[cur_idx - focus_first].y = cur_pos;
-                       focus_info[cur_idx - focus_first].renderer = el_renderer(cur_idx);
-//                     stderr.printf("LAYOUT [%d-%d-?] at %d/%d: pos %d rend %d rsz %d\n",
-//                             focus_first, cur_idx, cur_idx - focus_first, focus_info.length, cur_pos, focus_info[cur_idx - focus_first].renderer, renderer_sizes[focus_info[cur_idx - focus_first].renderer]);
-                       cur_pos += renderer_sizes[focus_info[cur_idx - focus_first].renderer];
+                       if (focus_first + cur_idx == cur_el)
+                               focus_area_pre = cur_pos;
+                       focus_info[cur_idx].y = cur_pos;
+                       focus_info[cur_idx].renderer = el_renderer(focus_first + cur_idx);
+//                     stderr.printf("LAYOUT %d+[0-%d-%d] item %d/%d: pos %d rend %d rsz %d\n",
+//                             focus_first, cur_idx, focus_info.length, focus_first + cur_idx, label_cache.length,
+//                             cur_pos, focus_info[cur_idx].renderer, renderer_sizes[focus_info[cur_idx].renderer]);
+                       cur_pos += renderer_sizes[focus_info[cur_idx].renderer];
                        ++cur_idx;
                }
 
-               focus_end = cur_idx;
-               focus_info[focus_end - focus_first].y = cur_pos;
-               focus_info[focus_end - focus_first].renderer = 0;
+               focus_info[cur_idx].y = cur_pos;
+               focus_info[cur_idx].renderer = 0;
+               focus_end = focus_first + cur_idx;
+
+               int anchor_y = cur_el * allocation.height / (label_cache.length+1);
+               int focus_area_size = cur_pos;
+
+               focus_area_start = anchor_y - focus_area_pre;
+               if (focus_area_start < 0) focus_area_start = 0;
+               if (focus_area_start + focus_area_size > allocation.height)
+                       focus_area_start = allocation.height - focus_area_size;
+
+//             stderr.printf("FA [0 [%d+%d=%d] %d]\n", focus_area_start, focus_area_size, focus_area_start+focus_area_size, allocation.height);
 
                focus_layout_needed = false;
        }
@@ -459,16 +471,16 @@ public class FisheyeList : Gtk.DrawingArea
                {
                        // Focus lock area
                        drawable.draw_rectangle(style.bg_gc[Gtk.StateType.ACTIVE], true,
-                               0, focus_info[0].y, allocation.width/2, focus_info[focus_end - focus_first].y-focus_info[0].y);
+                               0, focus_area_start + focus_info[0].y, allocation.width/2, focus_info[focus_end - focus_first].y);
 
                        // Paint items around focus
                        Gdk.Rectangle cell_area = Gdk.Rectangle();
                        cell_area.x = 0;
                        cell_area.width = allocation.width;
-                       for (int idx = 0; idx < focus_end-focus_first; ++idx)
+                       for (int idx = 0; idx < focus_info.length; ++idx)
                        {
                                var renderer = renderers[focus_info[idx].renderer];
-                               cell_area.y = focus_info[idx].y;
+                               cell_area.y = focus_area_start + focus_info[idx].y;
                                cell_area.height = renderer_sizes[focus_info[idx].renderer];
 
                                Gtk.CellRendererState rflags = 0;