Add class Widgets::Menu::Items
This commit is contained in:
parent
cab2881d02
commit
92bc971b5f
3 changed files with 33 additions and 23 deletions
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
28
lib/widgets/menu/items.rb
Normal file
28
lib/widgets/menu/items.rb
Normal file
|
@ -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
|
Reference in a new issue