center on C-space if possible
authorgc <gc>
Sun, 27 Apr 2008 20:10:33 +0000 (20:10 +0000)
committergc <gc>
Sun, 27 Apr 2008 20:10:33 +0000 (20:10 +0000)
bin/booh-classifier

index fa5931c..7023416 100644 (file)
@@ -718,25 +718,27 @@ class MainView < Gtk::DrawingArea
     end
 end
 
-def autoscroll_if_needed(button)
+def autoscroll_if_needed(button, center)
     xpos_left = button.allocation.x
     xpos_right = button.allocation.x + button.allocation.width
     hadj = $imagesline_sw.hadjustment
     current_minx_visible = hadj.value
     current_maxx_visible = hadj.value + hadj.page_size
-    if xpos_left < current_minx_visible
-        #- autoscroll left
-        newval = hadj.value - (current_minx_visible - xpos_left)
-        hadj.value = newval
-        button.queue_draw  #- TOREMOVE: the visual focus is displayed incorrectly
-    elsif xpos_right > current_maxx_visible
-        #- autoscroll right
-        newval = hadj.value + (xpos_right - current_maxx_visible)
-        if newval > hadj.upper - hadj.page_size
-            newval = hadj.upper - hadj.page_size
+    if ! center
+        if xpos_left < current_minx_visible
+            #- autoscroll left
+            newval = hadj.value - (current_minx_visible - xpos_left)
+            hadj.value = newval
+        elsif xpos_right > current_maxx_visible
+            #- autoscroll right
+            newval = hadj.value + (xpos_right - current_maxx_visible)
+            if newval > hadj.upper - hadj.page_size
+                newval = hadj.upper - hadj.page_size
+            end
+            hadj.value = newval
         end
-        hadj.value = newval
-        button.queue_draw  #- TOREMOVE: the visual focus is displayed incorrectly
+    else
+        hadj.value = clamp((xpos_left + xpos_right) / 2 - hadj.page_size / 2, 0, hadj.upper - hadj.page_size)
     end
 end
 
@@ -868,7 +870,7 @@ def thumbnail_keypressed(entry, event)
         end
         if event.keyval == Gdk::Keyval::GDK_space
             shown = $mainview.get_shown_entry
-            shown and autoscroll_if_needed(shown.button)
+            shown and autoscroll_if_needed(shown.button, true)
         end
 
     else
@@ -1029,7 +1031,7 @@ def show_entry(entry, i, tips)
         if shown != entry
             shown and shown.alignment.set(0.5, 1, 0, 0)
             entry.alignment.set(0.5, 0, 0, 0)
-            autoscroll_if_needed(entry.button)
+            autoscroll_if_needed(entry.button, false)
             $mainview.set_shown_entry(entry)
         end
     }
@@ -1690,7 +1692,7 @@ the <i>to remove</i> label, and copy or move images with the labels you defined.
 <span foreground='darkblue'>Space</span>: clear any label on current image
 <span foreground='darkblue'>Control-z</span>: undo
 <span foreground='darkblue'>Control-r</span>: redo
-<span foreground='darkblue'>Control-Space</span>: autoscroll thumbnails to view current item
+<span foreground='darkblue'>Control-Space</span>: recenter thumbnails on current item
 
 Any alphabetical key will assign (or popup for) the associated label on current image.
 ")), { :pos_centered => true, :not_transient => true })