Archived
1
0
Fork 0

Add widget VPanel

This commit is contained in:
Braiden Vasco 2017-07-22 08:30:26 +00:00
parent e59b925ac3
commit 8ca28eab0e
4 changed files with 34 additions and 15 deletions

View file

@ -9,6 +9,7 @@ require 'events'
# Basic # Basic
require 'widgets/text' require 'widgets/text'
require 'widgets/v_panel'
require 'widgets/messenger' require 'widgets/messenger'

View file

@ -1,11 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
module Widgets module Widgets
class Chat class Chat < VPanel
attr_reader :focused
def initialize(x, y, width, height) def initialize(x, y, width, height)
@focused = false super
info_height = 4 info_height = 4
message_height = 1 message_height = 1
@ -20,10 +18,8 @@ module Widgets
@message = NewMessage.new x, y + message_top, width, message_height @message = NewMessage.new x, y + message_top, width, message_height
end end
def render def children
@info.render [@info, @history, @message]
@history.render
@message.render
end end
def trigger(event) def trigger(event)

View file

@ -1,19 +1,16 @@
# frozen_string_literal: true # frozen_string_literal: true
module Widgets module Widgets
class Peers class Peers < VPanel
attr_reader :focused
def initialize(x, y, width, height) def initialize(x, y, width, height)
@focused = false super
@list = List.new x, y + 1, width, height - 1 @list = List.new x, y + 1, width, height - 1
@search = Search.new x, y, width, 1 @search = Search.new x, y, width, 1
end end
def render def children
@list.render [@list, @search]
@search.render
end end
def trigger(event) def trigger(event)

25
lib/widgets/v_panel.rb Normal file
View file

@ -0,0 +1,25 @@
# frozen_string_literal: true
module Widgets
class VPanel
attr_reader :x, :y, :width, :height, :focused
def initialize(x, y, width, height)
@x = x
@y = y
@width = width
@height = height
@focused = false
end
def render
children.each(&:render)
end
def children
raise NotImplementedError, "#{self.class}#children"
end
end
end