From bebadd354548e886ea4437365ddc0f76e7a5f3fd Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Mon, 24 Jul 2017 11:00:51 +0000 Subject: [PATCH] Move Widgets::Window to Widgets::Main --- lib/main.rb | 4 ++-- lib/widgets/main.rb | 35 +++++++++++++++++++++++++++++++++++ lib/widgets/window.rb | 30 ------------------------------ 3 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 lib/widgets/main.rb delete mode 100644 lib/widgets/window.rb diff --git a/lib/main.rb b/lib/main.rb index fdb20c5..c530eab 100644 --- a/lib/main.rb +++ b/lib/main.rb @@ -16,7 +16,7 @@ require 'widgets/text' require 'widgets/container' require 'widgets/v_panel' -require 'widgets/window' +require 'widgets/main' require 'widgets/messenger' @@ -91,7 +91,7 @@ private end def window - @window ||= Widgets::Window.new( + @window ||= Widgets::Main.new( 0, 0, Curses.stdscr.maxx, diff --git a/lib/widgets/main.rb b/lib/widgets/main.rb new file mode 100644 index 0000000..97c9422 --- /dev/null +++ b/lib/widgets/main.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Widgets + class Main < Container + def initialize(x, y, width, height) + super + + menu_width = width / 4 + chat_width = width - menu_width + + menu_left = 0 + chat_left = menu_width + + @menu = Widgets::Menu.new x + menu_left, y, menu_width, height + @chat = Widgets::Chat.new x + chat_left, y, chat_width, height + + self.focus = @menu + end + + def children + [@menu, @chat] + end + + def trigger(event) + case event + when Events::Window::Left + self.focus = @menu + when Events::Window::Right + self.focus = @chat + else + focus.trigger event + end + end + end +end diff --git a/lib/widgets/window.rb b/lib/widgets/window.rb deleted file mode 100644 index 3159274..0000000 --- a/lib/widgets/window.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -module Widgets - class Window < Container - def initialize(x, y, width, height) - super - - @menu = Widgets::Menu.new 0, 0, nil, height - - @messenger = Widgets::Messenger.new 0, 0, width - @menu.width, height - - self.focus = @messenger - - @menu_visible = false - end - - def children - focus == @menu ? [@messenger, @menu] : [@messenger] - end - - def trigger(event) - case event - when Events::Tab - self.focus = focus == @menu ? @messenger : @menu - else - focus.trigger event - end - end - end -end