From 8ca28eab0e84ed6a086bb0b73c47f41bb0570dde Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Sat, 22 Jul 2017 08:30:26 +0000 Subject: [PATCH] Add widget VPanel --- lib/main.rb | 1 + lib/widgets/chat.rb | 12 ++++-------- lib/widgets/peers.rb | 11 ++++------- lib/widgets/v_panel.rb | 25 +++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 lib/widgets/v_panel.rb diff --git a/lib/main.rb b/lib/main.rb index 798824e..75f2c24 100644 --- a/lib/main.rb +++ b/lib/main.rb @@ -9,6 +9,7 @@ require 'events' # Basic require 'widgets/text' +require 'widgets/v_panel' require 'widgets/messenger' diff --git a/lib/widgets/chat.rb b/lib/widgets/chat.rb index 2ccde1c..fbe8d20 100644 --- a/lib/widgets/chat.rb +++ b/lib/widgets/chat.rb @@ -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) diff --git a/lib/widgets/peers.rb b/lib/widgets/peers.rb index 1c774d3..4330aba 100644 --- a/lib/widgets/peers.rb +++ b/lib/widgets/peers.rb @@ -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) diff --git a/lib/widgets/v_panel.rb b/lib/widgets/v_panel.rb new file mode 100644 index 0000000..1e6d972 --- /dev/null +++ b/lib/widgets/v_panel.rb @@ -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