diff --git a/lib/widgets/menu.rb b/lib/widgets/menu.rb index eb6752d..7b27de3 100644 --- a/lib/widgets/menu.rb +++ b/lib/widgets/menu.rb @@ -7,6 +7,8 @@ module Widgets @logo = Logo.new x, y, nil, nil @items = Items.new x, @logo.height, @logo.width, nil + + self.focus = @items end def children diff --git a/lib/widgets/menu/items.rb b/lib/widgets/menu/items.rb index af0abad..a34e225 100644 --- a/lib/widgets/menu/items.rb +++ b/lib/widgets/menu/items.rb @@ -19,6 +19,15 @@ module Widgets @active = 0 end + def trigger(event) + case event + when Events::Panel::Up + up + when Events::Panel::Down + down + end + end + def draw ITEMS.each_with_index do |item, index| draw_item index, item @@ -37,6 +46,14 @@ module Widgets Curses.addstr ' ' * (width - 2 * SIDE_PADDING) end end + + def up + @active -= 1 if active.positive? + end + + def down + @active += 1 if active < ITEMS.count - 1 + end end end end diff --git a/lib/widgets/window.rb b/lib/widgets/window.rb index 65f0573..db16ebf 100644 --- a/lib/widgets/window.rb +++ b/lib/widgets/window.rb @@ -8,7 +8,7 @@ module Widgets @menu = Widgets::Menu.new 0, 0, nil, Curses.stdscr.maxy @messenger = Widgets::Messenger.new @menu.width, 0, Curses.stdscr.maxx - @menu.width, Curses.stdscr.maxy - self.focus = @messenger + self.focus = @menu end def children