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