Add class Widgets::Chat::History
This commit is contained in:
parent
61fa1d89ec
commit
34b8218d98
3 changed files with 32 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
24
lib/widgets/chat/history.rb
Normal file
24
lib/widgets/chat/history.rb
Normal file
|
@ -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
|
Reference in a new issue