lib/cyberarm_engine/ui/elements/container.rb in cyberarm_engine-0.20.0 vs lib/cyberarm_engine/ui/elements/container.rb in cyberarm_engine-0.21.0
- old
+ new
@@ -4,10 +4,20 @@
include Common
attr_accessor :stroke_color, :fill_color
attr_reader :children, :gui_state, :scroll_position
+ def self.current_container
+ @@current_container
+ end
+
+ def self.current_container=(container)
+ raise ArgumentError, "Expected container to an an instance of CyberarmEngine::Element::Container, got #{container.class}" unless container.is_a?(CyberarmEngine::Element::Container)
+
+ @@current_container = container
+ end
+
def initialize(options = {}, block = nil)
@gui_state = options.delete(:gui_state)
super
@scroll_position = Vector.new(0, 0)
@@ -33,27 +43,27 @@
end
def clear(&block)
@children.clear
- old_container = $__current_container__
+ old_container = CyberarmEngine::Element::Container.current_container
- $__current_container__ = self
+ CyberarmEngine::Element::Container.current_container = self
block.call(self) if block
- $__current_container__ = old_container
+ CyberarmEngine::Element::Container.current_container = old_container
root.gui_state.request_recalculate
end
def append(&block)
- old_container = $__current_container__
+ old_container = CyberarmEngine::Element::Container.current_container
- $__current_container__ = self
+ CyberarmEngine::Element::Container.current_container = self
block.call(self) if block
- $__current_container__ = old_container
+ CyberarmEngine::Element::Container.current_container = old_container
root.gui_state.request_recalculate
end
def render
@@ -120,12 +130,12 @@
@height = 0
_width = dimensional_size(@style.width, :width)
_height = dimensional_size(@style.height, :height)
- @width = _width || (@children.map { |c| c.x + c.outer_width }.max || 0).round
- @height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).round
+ @width = _width || (@children.map { |c| c.x + c.outer_width }.max || 0).floor
+ @height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).floor
end
# Move child to parent after positioning
@children.each do |child|
child.x += (@x + @style.border_thickness_left) - style.margin_left
@@ -149,15 +159,17 @@
def layout
raise "Not overridden"
end
def max_width
- _width = dimensional_size(@style.width, :width)
- if _width
- outer_width
- else
- window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
- end
+ # _width = dimensional_size(@style.width, :width)
+ # if _width
+ # outer_width
+ # else
+ # window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
+ # end
+
+ outer_width
end
def fits_on_line?(element) # Flow
p [@options[:id], @width] if @options[:id]
@current_position.x + element.outer_width <= max_width &&