diff --git a/lib/cyberarm_engine/ui/check_box.rb b/lib/cyberarm_engine/ui/check_box.rb index 326bc54..47c93f7 100644 --- a/lib/cyberarm_engine/ui/check_box.rb +++ b/lib/cyberarm_engine/ui/check_box.rb @@ -12,8 +12,8 @@ module CyberarmEngine add(@toggle_button) add(@label) - @width = @toggle_button.width + @label.width - @height = @toggle_button.height + @label.height + @style.width = @toggle_button.width + @label.width + @style.height = @toggle_button.height + @label.height end def text=(text) diff --git a/lib/cyberarm_engine/ui/container.rb b/lib/cyberarm_engine/ui/container.rb index e7ca2ff..c2467d5 100644 --- a/lib/cyberarm_engine/ui/container.rb +++ b/lib/cyberarm_engine/ui/container.rb @@ -65,16 +65,12 @@ module CyberarmEngine def recalculate @current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top) - unless @visible - @width = 0 - @height= 0 - return - end + return unless visible? layout - @width = @max_width ? @max_width : (@children.map {|c| c.x + c.outer_width }.max || 0).round - @height = @max_height ? @max_height : (@children.map {|c| c.y + c.outer_height}.max || 0).round + @style.width = @max_width ? @max_width : (@children.map {|c| c.x + c.outer_width }.max || 0).round + @style.height = @max_height ? @max_height : (@children.map {|c| c.y + c.outer_height}.max || 0).round # Move child to parent after positioning @children.each do |child| diff --git a/lib/cyberarm_engine/ui/edit_line.rb b/lib/cyberarm_engine/ui/edit_line.rb index 48720f3..f6f08f9 100644 --- a/lib/cyberarm_engine/ui/edit_line.rb +++ b/lib/cyberarm_engine/ui/edit_line.rb @@ -20,7 +20,7 @@ module CyberarmEngine end def render - Gosu.clip_to(@text.x, @text.y, @width, @text.height) do + Gosu.clip_to(@text.x, @text.y, @style.width, @text.height) do draw_text Gosu.draw_rect(caret_position, @text.y, @caret_width, @caret_height, @caret_color, @z + 40) if @focus && @show_caret end @@ -80,13 +80,7 @@ module CyberarmEngine def recalculate super - unless @visible - @width = 0 - @height= 0 - return - end - - @width = default(:width) + @style.width = default(:width) update_background end diff --git a/lib/cyberarm_engine/ui/element.rb b/lib/cyberarm_engine/ui/element.rb index 15fcc28..9903dae 100644 --- a/lib/cyberarm_engine/ui/element.rb +++ b/lib/cyberarm_engine/ui/element.rb @@ -5,7 +5,7 @@ module CyberarmEngine include Common attr_accessor :x, :y, :z, :enabled - attr_reader :width, :height, :parent, :options, :style, :event_handler, :background_canvas, :border_canvas + attr_reader :parent, :options, :style, :event_handler, :background_canvas, :border_canvas def initialize(options = {}, block = nil) @parent = options[:parent] # parent Container (i.e. flow/stack) @@ -25,8 +25,8 @@ module CyberarmEngine @fixed_x = @x if @x != 0 @fixed_y = @y if @y != 0 - @width = default(:width) || $window.width - @height = default(:height) || $window.height + @style.width = default(:width) || $window.width + @style.height = default(:height) || $window.height set_border_thickness(default(:border_thickness)) @@ -40,8 +40,6 @@ module CyberarmEngine raise "#{self.class} 'x' must be a number" unless @x.is_a?(Numeric) raise "#{self.class} 'y' must be a number" unless @y.is_a?(Numeric) raise "#{self.class} 'z' must be a number" unless @z.is_a?(Numeric) - raise "#{self.class} 'width' must be a number" unless @width.is_a?(Numeric) || @width.nil? - raise "#{self.class} 'height' must be a number" unless @height.is_a?(Numeric) || @height.nil? raise "#{self.class} 'options' must be a Hash" unless @options.is_a?(Hash) # raise "#{self.class} 'padding' must be a number" unless @padding.is_a?(Numeric) @@ -162,7 +160,11 @@ module CyberarmEngine end def width - (@style.border_thickness_left + @style.padding_left) + @width + (@style.padding_right + @style.border_thickness_right) + if visible? + (@style.border_thickness_left + @style.padding_left) + @style.width + (@style.padding_right + @style.border_thickness_right) + else + 0 + end end def outer_width @@ -170,7 +172,11 @@ module CyberarmEngine end def height - (@style.border_thickness_top + @style.padding_top) + @height + (@style.padding_bottom + @style.border_thickness_bottom) + if visible? + (@style.border_thickness_top + @style.padding_top) + @style.height + (@style.padding_bottom + @style.border_thickness_bottom) + else + 0 + end end def outer_height diff --git a/lib/cyberarm_engine/ui/image.rb b/lib/cyberarm_engine/ui/image.rb index a583cf1..5134632 100644 --- a/lib/cyberarm_engine/ui/image.rb +++ b/lib/cyberarm_engine/ui/image.rb @@ -35,14 +35,8 @@ module CyberarmEngine end def recalculate - unless @visible - @width = 0 - @height= 0 - return - end - - @width = @image.width * @scale_x - @height = @image.height * @scale_y + @style.width = @image.width * @scale_x + @style.height = @image.height * @scale_y end def value diff --git a/lib/cyberarm_engine/ui/label.rb b/lib/cyberarm_engine/ui/label.rb index 2adbce6..7777d4a 100644 --- a/lib/cyberarm_engine/ui/label.rb +++ b/lib/cyberarm_engine/ui/label.rb @@ -17,14 +17,8 @@ module CyberarmEngine end def recalculate - unless @visible - @width = 0 - @height= 0 - return - end - - @width = @text.width.round - @height= @text.height.round + @style.width = @text.width.round + @style.height= @text.height.round @text.x = @style.border_thickness_left + @style.padding_left + @x @text.y = @style.border_thickness_top + @style.padding_top + @y diff --git a/lib/cyberarm_engine/ui/toggle_button.rb b/lib/cyberarm_engine/ui/toggle_button.rb index 6b9c88a..fa173a8 100644 --- a/lib/cyberarm_engine/ui/toggle_button.rb +++ b/lib/cyberarm_engine/ui/toggle_button.rb @@ -38,13 +38,7 @@ module CyberarmEngine def recalculate super - unless @visible - @width = 0 - @height= 0 - return - end - - @width = @text.textobject.text_width(@options[:checkmark]) + @style.width = @text.textobject.text_width(@options[:checkmark]) update_background end