mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 13:12: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(@toggle_button)
|
||||||
add(@label)
|
add(@label)
|
||||||
|
|
||||||
@width = @toggle_button.width + @label.width
|
@style.width = @toggle_button.width + @label.width
|
||||||
@height = @toggle_button.height + @label.height
|
@style.height = @toggle_button.height + @label.height
|
||||||
end
|
end
|
||||||
|
|
||||||
def text=(text)
|
def text=(text)
|
||||||
|
|||||||
@@ -65,16 +65,12 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
@current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
|
@current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
|
||||||
unless @visible
|
return unless visible?
|
||||||
@width = 0
|
|
||||||
@height= 0
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
layout
|
layout
|
||||||
|
|
||||||
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
|
@style.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.height = @max_height ? @max_height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
|
||||||
|
|
||||||
# Move child to parent after positioning
|
# Move child to parent after positioning
|
||||||
@children.each do |child|
|
@children.each do |child|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render
|
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
|
draw_text
|
||||||
Gosu.draw_rect(caret_position, @text.y, @caret_width, @caret_height, @caret_color, @z + 40) if @focus && @show_caret
|
Gosu.draw_rect(caret_position, @text.y, @caret_width, @caret_height, @caret_color, @z + 40) if @focus && @show_caret
|
||||||
end
|
end
|
||||||
@@ -80,13 +80,7 @@ module CyberarmEngine
|
|||||||
def recalculate
|
def recalculate
|
||||||
super
|
super
|
||||||
|
|
||||||
unless @visible
|
@style.width = default(:width)
|
||||||
@width = 0
|
|
||||||
@height= 0
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
@width = default(:width)
|
|
||||||
update_background
|
update_background
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ module CyberarmEngine
|
|||||||
include Common
|
include Common
|
||||||
|
|
||||||
attr_accessor :x, :y, :z, :enabled
|
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)
|
def initialize(options = {}, block = nil)
|
||||||
@parent = options[:parent] # parent Container (i.e. flow/stack)
|
@parent = options[:parent] # parent Container (i.e. flow/stack)
|
||||||
@@ -25,8 +25,8 @@ module CyberarmEngine
|
|||||||
@fixed_x = @x if @x != 0
|
@fixed_x = @x if @x != 0
|
||||||
@fixed_y = @y if @y != 0
|
@fixed_y = @y if @y != 0
|
||||||
|
|
||||||
@width = default(:width) || $window.width
|
@style.width = default(:width) || $window.width
|
||||||
@height = default(:height) || $window.height
|
@style.height = default(:height) || $window.height
|
||||||
|
|
||||||
set_border_thickness(default(:border_thickness))
|
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} '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} '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} '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} 'options' must be a Hash" unless @options.is_a?(Hash)
|
||||||
|
|
||||||
# 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)
|
||||||
@@ -162,7 +160,11 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def width
|
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
|
end
|
||||||
|
|
||||||
def outer_width
|
def outer_width
|
||||||
@@ -170,7 +172,11 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def height
|
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
|
end
|
||||||
|
|
||||||
def outer_height
|
def outer_height
|
||||||
|
|||||||
@@ -35,14 +35,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
unless @visible
|
@style.width = @image.width * @scale_x
|
||||||
@width = 0
|
@style.height = @image.height * @scale_y
|
||||||
@height= 0
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
@width = @image.width * @scale_x
|
|
||||||
@height = @image.height * @scale_y
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
|
|||||||
@@ -17,14 +17,8 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
unless @visible
|
@style.width = @text.width.round
|
||||||
@width = 0
|
@style.height= @text.height.round
|
||||||
@height= 0
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
@width = @text.width.round
|
|
||||||
@height= @text.height.round
|
|
||||||
|
|
||||||
@text.x = @style.border_thickness_left + @style.padding_left + @x
|
@text.x = @style.border_thickness_left + @style.padding_left + @x
|
||||||
@text.y = @style.border_thickness_top + @style.padding_top + @y
|
@text.y = @style.border_thickness_top + @style.padding_top + @y
|
||||||
|
|||||||
@@ -38,13 +38,7 @@ module CyberarmEngine
|
|||||||
def recalculate
|
def recalculate
|
||||||
super
|
super
|
||||||
|
|
||||||
unless @visible
|
@style.width = @text.textobject.text_width(@options[:checkmark])
|
||||||
@width = 0
|
|
||||||
@height= 0
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
@width = @text.textobject.text_width(@options[:checkmark])
|
|
||||||
update_background
|
update_background
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user