Move methods to base class
This commit is contained in:
parent
c7ea787f34
commit
8c6ffb22cb
7 changed files with 28 additions and 37 deletions
|
@ -2,5 +2,20 @@
|
|||
|
||||
module Widgets
|
||||
class Container < Base
|
||||
attr_reader :focus
|
||||
|
||||
def draw
|
||||
children.each(&:render)
|
||||
end
|
||||
|
||||
def children
|
||||
raise NotImplementedError, "#{self.class}#children"
|
||||
end
|
||||
|
||||
def focus=(value)
|
||||
focus&.focused = false
|
||||
@focus = value
|
||||
focus.focused = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Widgets
|
||||
class Menu < Base
|
||||
class Menu < Container
|
||||
def initialize(x, y, _width, height)
|
||||
super x, y, Logo::WIDTH, height
|
||||
|
||||
|
@ -9,9 +9,8 @@ module Widgets
|
|||
@items = Items.new x, @logo.height, @logo.width, nil
|
||||
end
|
||||
|
||||
def draw
|
||||
@logo.render
|
||||
@items.render
|
||||
def children
|
||||
[@logo, @items]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Widgets
|
||||
class Menu < Base
|
||||
class Menu < Container
|
||||
class Items < Base
|
||||
ITEMS = [
|
||||
'Foo menu item',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Widgets
|
||||
class Menu < Base
|
||||
class Menu < Container
|
||||
class Logo < Base
|
||||
LOGO = [
|
||||
' _____ ___ _ _ ___ _ _ ',
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
module Widgets
|
||||
class Messenger < Container
|
||||
attr_reader :focus
|
||||
|
||||
def initialize(x, y, width, height)
|
||||
super
|
||||
|
||||
|
@ -16,12 +14,11 @@ module Widgets
|
|||
@peers = Widgets::Peers.new x + peers_left, y, peers_width, height
|
||||
@chat = Widgets::Chat.new x + chat_left, y, chat_width, height
|
||||
|
||||
@focus = @peers
|
||||
self.focus = @peers
|
||||
end
|
||||
|
||||
def draw
|
||||
@peers.render
|
||||
@chat.render
|
||||
def children
|
||||
[@peers, @chat]
|
||||
end
|
||||
|
||||
def trigger(event)
|
||||
|
@ -31,7 +28,7 @@ module Widgets
|
|||
when Events::Window::Right
|
||||
right
|
||||
else
|
||||
@focus.trigger event
|
||||
focus.trigger event
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,11 +44,5 @@ module Widgets
|
|||
@focused = !!value
|
||||
focus.focused = focused
|
||||
end
|
||||
|
||||
def focus=(child)
|
||||
focus.focused = false
|
||||
@focus = child
|
||||
focus.focused = true if focused
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,12 +2,5 @@
|
|||
|
||||
module Widgets
|
||||
class VPanel < Container
|
||||
def draw
|
||||
children.each(&:render)
|
||||
end
|
||||
|
||||
def children
|
||||
raise NotImplementedError, "#{self.class}#children"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,19 +13,12 @@ module Widgets
|
|||
self.focus = @messenger
|
||||
end
|
||||
|
||||
def children
|
||||
[@menu, @messenger]
|
||||
end
|
||||
|
||||
def trigger(event)
|
||||
focus.trigger event
|
||||
end
|
||||
|
||||
def draw
|
||||
@menu.render
|
||||
@messenger.render
|
||||
end
|
||||
|
||||
def focus=(value)
|
||||
focus.focused = false if focus
|
||||
@focus = value
|
||||
focus.focused = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue