mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 21:22:33 +00:00
Improved shoes-iness; no longer need to pass clear blocks an element to parent to, todo: replace global var with something else.
This commit is contained in:
@@ -76,7 +76,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
private def element_parent
|
private def element_parent
|
||||||
self.is_a?(CyberarmEngine::Element::Container) ? self : @containers.last
|
$__current_container__
|
||||||
end
|
end
|
||||||
|
|
||||||
private def container(klass, options = {}, &block)
|
private def container(klass, options = {}, &block)
|
||||||
@@ -85,10 +85,13 @@ module CyberarmEngine
|
|||||||
|
|
||||||
_container = klass.new(options, block)
|
_container = klass.new(options, block)
|
||||||
|
|
||||||
@containers << _container
|
old_parent = element_parent
|
||||||
|
$__current_container__ = _container
|
||||||
|
|
||||||
_container.build
|
_container.build
|
||||||
_container.parent.add(_container)
|
_container.parent.add(_container)
|
||||||
@containers.pop
|
|
||||||
|
$__current_container__ = old_parent
|
||||||
|
|
||||||
return _container
|
return _container
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ module CyberarmEngine
|
|||||||
class Element
|
class Element
|
||||||
class Container < Element
|
class Container < Element
|
||||||
include Common
|
include Common
|
||||||
include CyberarmEngine::DSL
|
|
||||||
|
|
||||||
attr_accessor :stroke_color, :fill_color
|
attr_accessor :stroke_color, :fill_color
|
||||||
attr_reader :children, :gui_state
|
attr_reader :children, :gui_state
|
||||||
@@ -35,8 +34,13 @@ module CyberarmEngine
|
|||||||
def clear(&block)
|
def clear(&block)
|
||||||
@children.clear
|
@children.clear
|
||||||
|
|
||||||
|
old_container = $__current_container__
|
||||||
|
|
||||||
|
$__current_container__ = self
|
||||||
block.call(self) if block
|
block.call(self) if block
|
||||||
|
|
||||||
|
$__current_container__ = old_container
|
||||||
|
|
||||||
recalculate
|
recalculate
|
||||||
root.gui_state.request_recalculate
|
root.gui_state.request_recalculate
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
@root_container = Element::Stack.new(gui_state: self)
|
@root_container = Element::Stack.new(gui_state: self)
|
||||||
@game_objects << @root_container
|
@game_objects << @root_container
|
||||||
@containers = [@root_container]
|
$__current_container__ = @root_container
|
||||||
|
|
||||||
@active_width = window.width
|
@active_width = window.width
|
||||||
@active_height = window.height
|
@active_height = window.height
|
||||||
|
|||||||
Reference in New Issue
Block a user