Class: LogBench::App::Renderer::Scrollbar

Inherits:
Object
  • Object
show all
Includes:
Curses
Defined in:
lib/log_bench/app/renderer/scrollbar.rb

Instance Method Summary collapse

Constructor Details

#initialize(screen) ⇒ Scrollbar



9
10
11
# File 'lib/log_bench/app/renderer/scrollbar.rb', line 9

def initialize(screen)
  self.screen = screen
end

Instance Method Details

#draw(win, height, offset, total) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/log_bench/app/renderer/scrollbar.rb', line 13

def draw(win, height, offset, total)
  return if total <= height

  scrollbar_height = [(height * height / total), 1].max
  scrollbar_pos = offset * height / total

  x = win.maxx - 2  # Position scrollbar closer to the border
  height.times do |i|
    win.setpos(i + 1, x)
    if i >= scrollbar_pos && i < scrollbar_pos + scrollbar_height
      win.attron(color_pair(1)) { win.addstr("█") }  # Solid block for scrollbar thumb
    end
  end
end