lib/cyberarm_engine/ui/element.rb in cyberarm_engine-0.8.1 vs lib/cyberarm_engine/ui/element.rb in cyberarm_engine-0.9.0

- old
+ new

@@ -21,15 +21,18 @@ @x = @style.x @y = @style.y @z = @style.z + @width = 0 + @height = 0 + @fixed_x = @x if @x != 0 @fixed_y = @y if @y != 0 - @style.width = default(:width) || $window.width - @style.height = default(:height) || $window.height + @style.width = default(:width) || nil + @style.height = default(:height) || nil stylize default_events end @@ -117,21 +120,21 @@ @visible end def toggle @visible = !@visible - root.recalculate + root.gui_state.request_recalculate end def show @visible = true - root.recalculate + root.gui_state.request_recalculate end def hide @visible = false - root.recalculate + root.gui_state.request_recalculate end def draw return unless @visible @@ -157,11 +160,11 @@ y.between?(@y, @y + height) end def width if visible? - (@style.border_thickness_left + @style.padding_left) + @style.width + (@style.padding_right + @style.border_thickness_right) + (@style.border_thickness_left + @style.padding_left) + @width + (@style.padding_right + @style.border_thickness_right) else 0 end end @@ -169,20 +172,33 @@ @style.margin_left + width + @style.margin_right end def height if visible? - (@style.border_thickness_top + @style.padding_top) + @style.height + (@style.padding_bottom + @style.border_thickness_bottom) + (@style.border_thickness_top + @style.padding_top) + @height + (@style.padding_bottom + @style.border_thickness_bottom) else 0 end end def outer_height @style.margin_top + height + @style.margin_bottom end + private def dimensional_size(size, dimension) + raise "dimension must be either :width or :height" unless dimension == :width || dimension == :height + if size && size.is_a?(Numeric) + if size.between?(0.0, 1.0) + @parent.send(:"#{dimension}") * size + else + size + end + else + nil + end + end + def background=(_background) @style.background_canvas.background=(_background) update_background end @@ -210,9 +226,13 @@ end end end @root + end + + def is_root? + @gui_state != nil end def recalculate raise "#{self.class}#recalculate was not overridden!" end \ No newline at end of file