From 92bc971b5fa2cb802b99d15759b54ba07b2daee6 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Sat, 22 Jul 2017 14:51:07 +0000 Subject: [PATCH] Add class Widgets::Menu::Items --- lib/main.rb | 1 + lib/widgets/menu.rb | 27 ++++----------------------- lib/widgets/menu/items.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 lib/widgets/menu/items.rb diff --git a/lib/main.rb b/lib/main.rb index 5a84f3c..006e235 100644 --- a/lib/main.rb +++ b/lib/main.rb @@ -17,6 +17,7 @@ require 'widgets/messenger' require 'widgets/menu' require 'widgets/menu/logo' +require 'widgets/menu/items' require 'widgets/peers' require 'widgets/peers/list' diff --git a/lib/widgets/menu.rb b/lib/widgets/menu.rb index 7703804..3f8a68d 100644 --- a/lib/widgets/menu.rb +++ b/lib/widgets/menu.rb @@ -2,35 +2,16 @@ module Widgets class Menu < Base - ITEMS = [ - 'Foo menu item', - 'Bar Car menu item', - 'Hello, World!', - ].freeze - def initialize(x, y, _width, height) super x, y, Logo::WIDTH, height - @logo = Logo.new x, y, nil, nil + @logo = Logo.new x, y, nil, nil + @items = Items.new x, @logo.height, @logo.width, nil end def draw - @logo.draw - - ITEMS.each_with_index do |item, index| - item_y = @logo.height + index * 4 - - Style.default.menu_item do - setpos 2, item_y + 0 - Curses.addstr ' ' * (width - 4) - - setpos 2, item_y + 1 - Curses.addstr " #{item}".ljust width - 4 - - setpos 2, item_y + 2 - Curses.addstr ' ' * (width - 4) - end - end + @logo.render + @items.render end end end diff --git a/lib/widgets/menu/items.rb b/lib/widgets/menu/items.rb new file mode 100644 index 0000000..39fd2b5 --- /dev/null +++ b/lib/widgets/menu/items.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Widgets + class Menu < Base + class Items < Base + ITEMS = [ + 'Foo menu item', + 'Bar Car menu item', + 'Hello, World!', + ].freeze + + def draw + ITEMS.each_with_index do |item, index| + Style.default.menu_item do + setpos 2, 4 * index + 0 + Curses.addstr ' ' * (width - 4) + + setpos 2, 4 * index + 1 + Curses.addstr " #{item}".ljust width - 4 + + setpos 2, 4 * index + 2 + Curses.addstr ' ' * (width - 4) + end + end + end + end + end +end