lib/cyberarm_engine/ui/elements/container.rb in cyberarm_engine-0.19.1 vs lib/cyberarm_engine/ui/elements/container.rb in cyberarm_engine-0.20.0

- old
+ new

@@ -43,11 +43,11 @@ $__current_container__ = old_container root.gui_state.request_recalculate end - def apend(&block) + def append(&block) old_container = $__current_container__ $__current_container__ = self block.call(self) if block @@ -55,11 +55,16 @@ root.gui_state.request_recalculate end def render - Gosu.clip_to(@x, @y, width, height) do + Gosu.clip_to( + @x + @style.border_thickness_left + @style.padding_left, + @y + @style.border_thickness_top + @style.padding_top, + content_width + 1, + content_height + 1 + ) do @children.each(&:draw) end end def debug_draw @@ -101,10 +106,12 @@ Stats.increment(:gui_recalculations_last_frame, 1) stylize + # s = Gosu.milliseconds + layout if is_root? @width = @style.width = window.width @height = @style.height = window.height @@ -127,12 +134,17 @@ child.stylize child.recalculate child.reposition # TODO: Implement top,bottom,left,center, and right positioning Stats.increment(:gui_recalculations_last_frame, 1) + + child.element_visible = child.x >= @x - child.width && child.x <= @x + width && + child.y >= @y - child.height && child.y <= @y + height end + # puts "TOOK: #{Gosu.milliseconds - s}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}" + update_background end def layout raise "Not overridden" @@ -192,12 +204,13 @@ return unless @style.scroll if @scroll_position.y < 0 @scroll_position.y += @scroll_speed @scroll_position.y = 0 if @scroll_position.y > 0 - recalculate + root.gui_state.request_recalculate_for(self) + return :handled end end def mouse_wheel_down(sender, x, y) @@ -206,10 +219,11 @@ return unless height < scroll_height if @scroll_position.y.abs < max_scroll_height @scroll_position.y -= @scroll_speed @scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height - recalculate + + root.gui_state.request_recalculate_for(self) return :handled end end