Move Widgets::Window to Widgets::Main
This commit is contained in:
parent
cafb124475
commit
bebadd3545
3 changed files with 37 additions and 32 deletions
|
@ -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,
|
||||
|
|
35
lib/widgets/main.rb
Normal file
35
lib/widgets/main.rb
Normal file
|
@ -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
|
|
@ -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
|
Reference in a new issue