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/main.rb

75 lines
2 KiB
Ruby
Raw Permalink Normal View History

2017-07-24 07:00:51 -04:00
# frozen_string_literal: true
module Widgets
class Main < Container
2017-07-30 22:32:25 -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
focus&.trigger event
end
end
def node
elem = render
React::Curses::Nodes.klass_for(elem).new nil, elem
2017-07-24 18:34:50 -04:00
end
2017-07-24 07:00:51 -04:00
2017-07-30 22:32:25 -04:00
def render
create_element :window, x: props[:x], y: props[:y], width: props[:width], height: props[:height] do
create_element :wrapper do
render_sidebar
render_chat
end
end
2017-07-25 12:22:38 -04:00
2017-07-30 22:32:25 -04:00
# (0...props[:height]).each do |y|
# setpos props[:sidebar][:width], y
# addstr "\u2502"
# end
end
def render_sidebar
create_element Sidebar, props[:sidebar].merge(
2017-07-25 12:22:38 -04:00
on_menu_up: props[:on_menu_up],
on_menu_down: props[:on_menu_down],
2017-07-27 23:13:05 -04:00
active_friend_index: props[:data][:active_friend_index],
2017-07-27 23:13:05 -04:00
friends: props[:data][:friends],
2017-07-25 12:22:38 -04:00
).freeze
2017-07-30 22:32:25 -04:00
end
2017-07-25 12:22:38 -04:00
2017-07-30 22:32:25 -04:00
def render_chat
create_element Chat, props[:chat].merge(
2017-07-26 04:07:36 -04:00
on_new_message_enter: props[:on_new_message_enter],
2017-07-25 12:36:19 -04:00
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-27 23:13:05 -04:00
active_friend_index: props[:data][:active_friend_index],
2017-07-27 23:13:05 -04:00
friend: props[:data][:active_friend_index] &&
props[:data][:friends][props[:data][:friends].keys[props[:data][:active_friend_index]]],
2017-07-25 12:36:19 -04:00
).freeze
2017-07-25 10:48:37 -04:00
end
2017-07-24 18:34:50 -04:00
def focus
case props[:focus]
2017-07-30 22:32:25 -04:00
when :sidebar then node.children[0].children[0].instance
when :chat then node.children[0].children[1].instance
2017-07-24 18:34:50 -04:00
end
end
2017-07-24 07:00:51 -04:00
end
end