mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 05:02:34 +00:00
Element width and height are now proper styles, removed width/height setters when element is not visible, Element.width and Element.height now return 0 if Element is invisible
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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|
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user