Archived
1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
cli-old/lib/widgets/menu.rb
2017-07-25 16:22:38 +00:00

42 lines
956 B
Ruby

# frozen_string_literal: true
module Widgets
class Menu < Base
def trigger(event)
case event
when Events::Text::Up
props[:on_up].call
when Events::Text::Down
props[:on_down].call
end
end
private
def draw
props[:items][props[:top]...(props[:top] + props[:height])].each_with_index.each do |item, offset|
index = props[:top] + offset
setpos 0, offset
if item[:online]
Style.default.online_mark window do
addstr '*'
end
else
addstr 'o'
end
addstr ' '
Style.default.public_send(index == props[:active] && props[:focused] ? :selection : :text, window) do
if item[:name].length <= props[:width] - 2
addstr item[:name].ljust props[:width] - 2
else
addstr "#{item[:name][0...props[:width] - 5]}..."
end
end
end
end
end
end