Archived
1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
cli-old/lib/widgets/chat.rb

42 lines
973 B
Ruby
Raw Normal View History

2017-07-21 11:19:59 -04:00
# frozen_string_literal: true
module Widgets
2017-07-22 04:30:26 -04:00
class Chat < VPanel
2017-07-21 11:19:59 -04:00
def initialize(x, y, width, height)
2017-07-22 04:30:26 -04:00
super
2017-07-21 12:16:49 -04:00
2017-07-22 04:16:58 -04:00
info_height = 4
message_height = 1
history_height = height - info_height - message_height
info_top = 0
history_top = info_height
message_top = info_height + history_height
@info = Info.new x, y + info_top, width, info_height
@history = History.new x, y + history_top, width, history_height
@message = NewMessage.new x, y + message_top, width, message_height
2017-07-21 13:43:39 -04:00
end
2017-07-22 04:30:26 -04:00
def children
[@info, @history, @message]
2017-07-21 11:19:59 -04:00
end
2017-07-21 13:36:20 -04:00
2017-07-21 13:51:46 -04:00
def trigger(event)
case event
2017-07-21 14:04:59 -04:00
when Events::Panel::Base
@history.trigger event
2017-07-21 13:51:46 -04:00
when Events::Text::Base
@message.trigger event
end
end
def focused=(value)
@focused = !!value
2017-07-22 04:16:58 -04:00
@info.focused = focused
2017-07-21 14:04:59 -04:00
@history.focused = focused
2017-07-21 13:51:46 -04:00
@message.focused = focused
end
2017-07-21 11:19:59 -04:00
end
end