mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 13:12:34 +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
|
||||
|
||||
private def element_parent
|
||||
self.is_a?(CyberarmEngine::Element::Container) ? self : @containers.last
|
||||
$__current_container__
|
||||
end
|
||||
|
||||
private def container(klass, options = {}, &block)
|
||||
@@ -85,10 +85,13 @@ module CyberarmEngine
|
||||
|
||||
_container = klass.new(options, block)
|
||||
|
||||
@containers << _container
|
||||
old_parent = element_parent
|
||||
$__current_container__ = _container
|
||||
|
||||
_container.build
|
||||
_container.parent.add(_container)
|
||||
@containers.pop
|
||||
|
||||
$__current_container__ = old_parent
|
||||
|
||||
return _container
|
||||
end
|
||||
|
||||
@@ -2,7 +2,6 @@ module CyberarmEngine
|
||||
class Element
|
||||
class Container < Element
|
||||
include Common
|
||||
include CyberarmEngine::DSL
|
||||
|
||||
attr_accessor :stroke_color, :fill_color
|
||||
attr_reader :children, :gui_state
|
||||
@@ -35,8 +34,13 @@ module CyberarmEngine
|
||||
def clear(&block)
|
||||
@children.clear
|
||||
|
||||
old_container = $__current_container__
|
||||
|
||||
$__current_container__ = self
|
||||
block.call(self) if block
|
||||
|
||||
$__current_container__ = old_container
|
||||
|
||||
recalculate
|
||||
root.gui_state.request_recalculate
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@ module CyberarmEngine
|
||||
|
||||
@root_container = Element::Stack.new(gui_state: self)
|
||||
@game_objects << @root_container
|
||||
@containers = [@root_container]
|
||||
$__current_container__ = @root_container
|
||||
|
||||
@active_width = window.width
|
||||
@active_height = window.height
|
||||
|
||||
Reference in New Issue
Block a user