Add widget VPanel
This commit is contained in:
parent
e59b925ac3
commit
8ca28eab0e
4 changed files with 34 additions and 15 deletions
|
@ -9,6 +9,7 @@ require 'events'
|
|||
|
||||
# Basic
|
||||
require 'widgets/text'
|
||||
require 'widgets/v_panel'
|
||||
|
||||
require 'widgets/messenger'
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Widgets
|
||||
class Chat
|
||||
attr_reader :focused
|
||||
|
||||
class Chat < VPanel
|
||||
def initialize(x, y, width, height)
|
||||
@focused = false
|
||||
super
|
||||
|
||||
info_height = 4
|
||||
message_height = 1
|
||||
|
@ -20,10 +18,8 @@ module Widgets
|
|||
@message = NewMessage.new x, y + message_top, width, message_height
|
||||
end
|
||||
|
||||
def render
|
||||
@info.render
|
||||
@history.render
|
||||
@message.render
|
||||
def children
|
||||
[@info, @history, @message]
|
||||
end
|
||||
|
||||
def trigger(event)
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Widgets
|
||||
class Peers
|
||||
attr_reader :focused
|
||||
|
||||
class Peers < VPanel
|
||||
def initialize(x, y, width, height)
|
||||
@focused = false
|
||||
super
|
||||
|
||||
@list = List.new x, y + 1, width, height - 1
|
||||
@search = Search.new x, y, width, 1
|
||||
end
|
||||
|
||||
def render
|
||||
@list.render
|
||||
@search.render
|
||||
def children
|
||||
[@list, @search]
|
||||
end
|
||||
|
||||
def trigger(event)
|
||||
|
|
25
lib/widgets/v_panel.rb
Normal file
25
lib/widgets/v_panel.rb
Normal 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
|
Reference in a new issue