diff --git a/lib/main.rb b/lib/main.rb index f28d458..e1b977e 100644 --- a/lib/main.rb +++ b/lib/main.rb @@ -20,6 +20,7 @@ require 'widgets/list' require 'widgets/chat' require 'widgets/chat/new_message' +require 'widgets/chat/history' class Main def self.inherited(_base) diff --git a/lib/widgets/chat.rb b/lib/widgets/chat.rb index 516969b..7e9c22f 100644 --- a/lib/widgets/chat.rb +++ b/lib/widgets/chat.rb @@ -14,6 +14,7 @@ module Widgets @height = height @message = NewMessage.new x, y + height - 1, width, 1 + @history = History.new x, y, width, history_height @focused = false @@ -26,11 +27,12 @@ module Widgets end end - def log_height + def history_height height - 1 end def render + @history.render @message.render offset = 0 @@ -42,7 +44,7 @@ module Widgets offset = render_message offset, time, name, text - break if offset >= log_height + break if offset >= history_height end end @@ -78,6 +80,8 @@ module Widgets def trigger(event) case event + when Events::Panel::Base + @history.trigger event when Events::Text::Base @message.trigger event end @@ -85,6 +89,7 @@ module Widgets def focused=(value) @focused = !!value + @history.focused = focused @message.focused = focused end end diff --git a/lib/widgets/chat/history.rb b/lib/widgets/chat/history.rb new file mode 100644 index 0000000..ab3ec2f --- /dev/null +++ b/lib/widgets/chat/history.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Widgets + class Chat + class History + attr_reader :x, :y, :width, :height + attr_accessor :focused + + def initialize(x, y, width, height) + @x = x + @y = y + + @width = width + @height = height + + @focused = false + end + + def render; end + + def trigger(event); end + end + end +end