Class: Scryglass::TreePanel
- Defined in:
- lib/scryglass/tree_panel.rb
Instance Attribute Summary
Attributes inherited from ViewPanel
#current_view_coords, #scry_session, #x_boundaries, #y_boundaries
Instance Method Summary collapse
Methods inherited from ViewPanel
#ensure_correct_view_coords, #initialize, #move_view_down, #move_view_left, #move_view_right, #move_view_up, #recalculate_boundaries, #screen_string, #visible_body_string, #visible_header_string
Constructor Details
This class inherits a constructor from Scryglass::ViewPanel
Instance Method Details
#slide_view_to_cursor ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/scryglass/tree_panel.rb', line 9 def cursor_tracking = Scryglass.config.cursor_tracking current_ro = scry_session.current_ro ## Here we calculate the ro_in_center_of_view: visible_ros_from_center = (body_screen_height / 2) scanning_ro = top_visible_ro_of_tree_view visible_ros_from_center.times do next_visible_ro = scanning_ro.next_visible_ro_down scanning_ro = next_visible_ro if next_visible_ro end ro_in_center_of_view = scanning_ro ## We don't need to do anything if current_ro is already in the center: relative_index = current_ro.index - ro_in_center_of_view.index return if relative_index.zero? ## Establish the number of visible ros between current_ro and center point index_span = [ro_in_center_of_view.index, current_ro.index] ros_between_them = scry_session.all_ros[index_span.min...index_span.max] visible_count_between_them = ros_between_them.count(&:visible?) direction = :up if relative_index.negative? direction = :down if relative_index.positive? ## If view movement is needed, and how far, depends on the tracking config case cursor_tracking when :flexible_range flex_range = body_screen_height / 3 if visible_count_between_them >= flex_range distance_to_flex_range = visible_count_between_them - flex_range move_view_up(distance_to_flex_range) if direction == :up move_view_down(distance_to_flex_range) if direction == :down end when :dead_center move_view_up(visible_count_between_them) if direction == :up move_view_down(visible_count_between_them) if direction == :down end end |