Make focus_size depend on allocation size
authorEnrico Zini <enrico@enricozini.org>
Fri, 18 Dec 2009 01:13:16 +0000 (01:13 +0000)
committerEnrico Zini <enrico@enricozini.org>
Fri, 18 Dec 2009 01:13:16 +0000 (01:13 +0000)
gtkfisheyelist/gtkfisheyelistview.vala

index 0e9073591974fdc426c1e602f0af419054f29f31..0029b330c6f2fbf7c1b43414ac962513421e1309 100644 (file)
@@ -102,16 +102,7 @@ public class FisheyeListView : Gtk.DrawingArea
     protected int focus_area_start;
 
     // Number of elements in full focus
-    protected int _focus_size;
-    public int focus_size {
-        get { return _focus_size; }
-        set {
-            _focus_size = value;
-            focus_info = new FocusInfo[_focus_size+2*steps+1];
-            focus_layout_needed = true;
-            queue_draw();
-        }
-    }
+    protected int focus_size;
 
     protected int _label_column;
     public int label_column {
@@ -161,6 +152,10 @@ public class FisheyeListView : Gtk.DrawingArea
         add_events(Gdk.EventMask.POINTER_MOTION_MASK
                  | Gdk.EventMask.BUTTON_PRESS_MASK
              | Gdk.EventMask.BUTTON_RELEASE_MASK);
+
+        base_layout_needed = true;
+        focus_layout_needed = true;
+        queue_draw();
     }
 
     public unowned Gtk.TreeModel get_model() { return model; }
@@ -379,6 +374,11 @@ public class FisheyeListView : Gtk.DrawingArea
         renderers[renderers.length-1].get_size(this, null, null, null, null, out max_renderer_size);
         renderer_sizes[renderers.length-1] = max_renderer_size;
 
+        focus_size = allocation.height / (2*max_renderer_size);
+        if (focus_size % 2 == 1)
+            focus_size += 1;
+        focus_info = new FocusInfo[focus_size+2*steps+1];
+
         is_fisheye = label_count * max_renderer_size > allocation.height;
 
         if (is_fisheye)
@@ -412,7 +412,7 @@ public class FisheyeListView : Gtk.DrawingArea
 
     protected int el_renderer(int idx)
     {
-        int fs2 = _focus_size/2;
+        int fs2 = focus_size/2;
         int renderer_idx;
         if (idx < cur_el)
             renderer_idx = idx - (cur_el-fs2-steps);
@@ -435,7 +435,7 @@ public class FisheyeListView : Gtk.DrawingArea
             return;
         }
 
-        focus_first = cur_el - _focus_size/2 - steps;
+        focus_first = cur_el - focus_size/2 - steps;
         if (focus_first < 0) focus_first = 0;
         if (focus_first + focus_info.length > label_count)
             focus_first = label_count - focus_info.length;