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-25 10:29:01 -04:00
|
|
|
def initialize(_parent)
|
2017-07-22 04:30:26 -04:00
|
|
|
super
|
2017-07-21 12:16:49 -04:00
|
|
|
|
2017-07-25 10:29:01 -04:00
|
|
|
@info = Info.new self
|
|
|
|
@history = History.new self
|
|
|
|
@message = NewMessage.new self
|
2017-07-21 13:43:39 -04:00
|
|
|
end
|
|
|
|
|
2017-07-24 18:34:50 -04:00
|
|
|
def props=(_value)
|
|
|
|
super
|
2017-07-25 12:36:19 -04:00
|
|
|
|
2017-07-24 18:34:50 -04:00
|
|
|
@info.props = props[:info]
|
|
|
|
@history.props = props[:history]
|
2017-07-25 12:36:19 -04:00
|
|
|
|
|
|
|
@message.props = props[:new_message].merge(
|
|
|
|
on_putc: props[:on_new_message_putc],
|
2017-07-25 13:36:05 -04:00
|
|
|
|
|
|
|
on_left: props[:on_new_message_left],
|
|
|
|
on_right: props[:on_new_message_right],
|
|
|
|
on_home: props[:on_new_message_home],
|
|
|
|
on_end: props[:on_new_message_end],
|
2017-07-25 13:41:55 -04:00
|
|
|
|
|
|
|
on_backspace: props[:on_new_message_backspace],
|
|
|
|
on_delete: props[:on_new_message_delete],
|
2017-07-25 12:36:19 -04:00
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def trigger(event)
|
|
|
|
focus&.trigger event
|
2017-07-24 18:34:50 -04:00
|
|
|
end
|
|
|
|
|
2017-07-25 10:48:37 -04:00
|
|
|
private
|
|
|
|
|
2017-07-24 18:34:50 -04:00
|
|
|
def focus
|
|
|
|
case props[:focus]
|
|
|
|
when :info then @info
|
|
|
|
when :history then @history
|
|
|
|
when :new_message then @message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-22 04:30:26 -04:00
|
|
|
def children
|
|
|
|
[@info, @history, @message]
|
2017-07-21 11:19:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|