Fixed CheckBox#value not returning a boolean, added support for toggling Element visiblity

This commit is contained in:
2019-06-16 12:03:20 -05:00
parent b6730204e8
commit 4f4770db0e
7 changed files with 59 additions and 0 deletions

View File

@@ -21,6 +21,14 @@ module CyberarmEngine
recalculate recalculate
end end
def value
@toggle_button.value
end
def value=(bool)
@toggle_button.vlaue = bool
end
def define_label_singletons def define_label_singletons
@label.define_singleton_method(:_toggle_button) do |button| @label.define_singleton_method(:_toggle_button) do |button|
@_toggle_button = button @_toggle_button = button

View File

@@ -65,6 +65,11 @@ module CyberarmEngine
def recalculate def recalculate
@current_position = Vector.new(@margin_left, @margin_top) @current_position = Vector.new(@margin_left, @margin_top)
unless @visible
@width = 0
@height= 0
return
end
layout layout

View File

@@ -77,6 +77,12 @@ module CyberarmEngine
def recalculate def recalculate
super super
unless @visible
@width = 0
@height= 0
return
end
@width = default(:width) @width = default(:width)
update_background update_background
end end

View File

@@ -53,6 +53,7 @@ module CyberarmEngine
# raise "#{self.class} 'padding' must be a number" unless @padding.is_a?(Numeric) # raise "#{self.class} 'padding' must be a number" unless @padding.is_a?(Numeric)
@enabled = true @enabled = true
@visible = true
default_events default_events
end end
@@ -122,7 +123,28 @@ module CyberarmEngine
@enabled @enabled
end end
def visible?
@visible
end
def toggle
@visible = !@visible
root.recalculate
end
def show
@visible = true
root.recalculate
end
def hide
@visible = false
root.recalculate
end
def draw def draw
return unless @visible
@background_canvas.draw @background_canvas.draw
@border_canvas.draw @border_canvas.draw
render render

View File

@@ -31,6 +31,12 @@ module CyberarmEngine
end end
def recalculate def recalculate
unless @visible
@width = 0
@height= 0
return
end
@width = @image.width * @scale_x @width = @image.width * @scale_x
@height = @image.height * @scale_y @height = @image.height * @scale_y
end end

View File

@@ -17,6 +17,12 @@ module CyberarmEngine
end end
def recalculate def recalculate
unless @visible
@width = 0
@height= 0
return
end
@width = @text.width.round @width = @text.width.round
@height= @text.height.round @height= @text.height.round

View File

@@ -38,6 +38,12 @@ module CyberarmEngine
def recalculate def recalculate
super super
unless @visible
@width = 0
@height= 0
return
end
@width = @text.textobject.text_width(@options[:checkmark]) @width = @text.textobject.text_width(@options[:checkmark])
update_background update_background
end end