Module: RubyCoded::Chat::State::Scrollable

Included in:
RubyCoded::Chat::State
Defined in:
lib/ruby_coded/chat/state/scrollable.rb

Overview

This module contains the logic for the scrollable management. scroll_offset represents “lines from the bottom”: 0 = latest content visible.

Instance Method Summary collapse

Instance Method Details

#scroll_down(amount = 1) ⇒ Object



14
15
16
17
# File 'lib/ruby_coded/chat/state/scrollable.rb', line 14

def scroll_down(amount = 1)
  @scroll_offset = [@scroll_offset - amount, 0].max
  mark_dirty!
end

#scroll_to_bottomObject



24
25
26
27
# File 'lib/ruby_coded/chat/state/scrollable.rb', line 24

def scroll_to_bottom
  @scroll_offset = 0
  mark_dirty!
end

#scroll_to_topObject



19
20
21
22
# File 'lib/ruby_coded/chat/state/scrollable.rb', line 19

def scroll_to_top
  @scroll_offset = max_scroll
  mark_dirty!
end

#scroll_up(amount = 1) ⇒ Object



9
10
11
12
# File 'lib/ruby_coded/chat/state/scrollable.rb', line 9

def scroll_up(amount = 1)
  @scroll_offset = [@scroll_offset + amount, max_scroll].min
  mark_dirty!
end

#update_scroll_metrics(total_lines:, visible_height:) ⇒ Object



29
30
31
32
# File 'lib/ruby_coded/chat/state/scrollable.rb', line 29

def update_scroll_metrics(total_lines:, visible_height:)
  @total_lines = total_lines
  @visible_height = visible_height
end