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:
2020-01-13 20:13:03 -06:00
parent a267695b1c
commit 4b25d724b5
3 changed files with 12 additions and 5 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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