2017-07-24 07:00:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Widgets
|
|
|
|
class Main < Container
|
2017-07-25 10:29:01 -04:00
|
|
|
def initialize(_parent)
|
2017-07-24 07:00:51 -04:00
|
|
|
super
|
|
|
|
|
2017-07-25 10:29:01 -04:00
|
|
|
@sidebar = Widgets::Sidebar.new self
|
|
|
|
@chat = Widgets::Chat.new self
|
2017-07-24 18:34:50 -04:00
|
|
|
end
|
2017-07-24 07:00:51 -04:00
|
|
|
|
2017-07-25 10:48:37 -04:00
|
|
|
def props=(_value)
|
|
|
|
super
|
2017-07-25 12:22:38 -04:00
|
|
|
|
|
|
|
@sidebar.props = props[:sidebar].merge(
|
|
|
|
on_menu_up: props[:on_menu_up],
|
|
|
|
on_menu_down: props[:on_menu_down],
|
2017-07-25 21:40:19 -04:00
|
|
|
|
|
|
|
friends: props[:friends],
|
2017-07-25 12:22:38 -04:00
|
|
|
).freeze
|
|
|
|
|
2017-07-25 12:36:19 -04:00
|
|
|
@chat.props = props[:chat].merge(
|
|
|
|
on_new_message_putc: props[:on_new_message_putc],
|
2017-07-25 13:36:05 -04:00
|
|
|
|
|
|
|
on_new_message_left: props[:on_new_message_left],
|
|
|
|
on_new_message_right: props[:on_new_message_right],
|
|
|
|
on_new_message_home: props[:on_new_message_home],
|
|
|
|
on_new_message_end: props[:on_new_message_end],
|
2017-07-25 13:41:55 -04:00
|
|
|
|
|
|
|
on_new_message_backspace: props[:on_new_message_backspace],
|
|
|
|
on_new_message_delete: props[:on_new_message_delete],
|
2017-07-25 22:09:36 -04:00
|
|
|
|
|
|
|
friend: props[:friends][props[:active_friend_number]],
|
2017-07-25 12:36:19 -04:00
|
|
|
).freeze
|
2017-07-25 10:48:37 -04:00
|
|
|
end
|
|
|
|
|
2017-07-25 12:03:32 -04:00
|
|
|
def trigger(event)
|
|
|
|
case event
|
|
|
|
when Events::Window::Left
|
|
|
|
props[:on_window_left].call
|
|
|
|
when Events::Window::Right
|
|
|
|
props[:on_window_right].call
|
|
|
|
else
|
2017-07-25 12:36:19 -04:00
|
|
|
focus&.trigger event
|
2017-07-25 12:03:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-25 10:48:37 -04:00
|
|
|
private
|
|
|
|
|
2017-07-24 18:34:50 -04:00
|
|
|
def focus
|
|
|
|
case props[:focus]
|
|
|
|
when :sidebar then @sidebar
|
|
|
|
when :chat then @chat
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-24 07:00:51 -04:00
|
|
|
def children
|
2017-07-24 16:31:23 -04:00
|
|
|
[@sidebar, @chat]
|
2017-07-24 07:00:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|