Container child elements that are not visible are no longer drawn

This commit is contained in:
2021-12-24 17:00:02 -06:00
parent c35d587419
commit c8734ae98b
2 changed files with 10 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ module CyberarmEngine
include Event
include Common
attr_accessor :x, :y, :z, :tip
attr_accessor :x, :y, :z, :tip, :element_visible
attr_reader :parent, :options, :style, :event_handler, :background_canvas, :border_canvas
def initialize(options = {}, block = nil)
@@ -24,6 +24,7 @@ module CyberarmEngine
@root ||= nil
@gui_state ||= nil
@element_visible = true
@x = @style.x
@y = @style.y
@@ -260,6 +261,10 @@ module CyberarmEngine
@visible
end
def element_visible?
@element_visible
end
def toggle
@visible = !@visible
root.gui_state.request_recalculate
@@ -279,6 +284,7 @@ module CyberarmEngine
def draw
return unless visible?
return unless element_visible?
@style.background_canvas.draw
@style.background_nine_slice_canvas.draw

View File

@@ -129,6 +129,9 @@ module CyberarmEngine
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
update_background