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