mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 05:02:34 +00:00
Added partial support for fixed element width/height and added support for dynamic width/height (currently only works on Containers)
This commit is contained in:
@@ -31,7 +31,9 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def render
|
||||
Gosu.clip_to(@x, @y, width, height) do
|
||||
@children.each(&:draw)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -61,13 +63,16 @@ module CyberarmEngine
|
||||
layout
|
||||
|
||||
if is_root?
|
||||
@style.width = window.width
|
||||
@style.height = window.height
|
||||
@width = @style.width = window.width
|
||||
@height = @style.height = window.height
|
||||
else
|
||||
@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
|
||||
_width = dimensional_size(@style.width, :width)
|
||||
_height= dimensional_size(@style.height,:height)
|
||||
@width = _width ? _width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
|
||||
@height = _height ? _height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
|
||||
end
|
||||
|
||||
|
||||
# Move child to parent after positioning
|
||||
@children.each do |child|
|
||||
child.x += @x
|
||||
|
||||
@@ -79,7 +79,7 @@ module CyberarmEngine
|
||||
def recalculate
|
||||
super
|
||||
|
||||
@style.width = default(:width)
|
||||
@width = dimensional_size(@style.width, :width) || default(:width)
|
||||
update_background
|
||||
end
|
||||
|
||||
|
||||
@@ -23,11 +23,14 @@ module CyberarmEngine
|
||||
@y = @style.y
|
||||
@z = @style.z
|
||||
|
||||
@width = 0
|
||||
@height = 0
|
||||
|
||||
@fixed_x = @x if @x != 0
|
||||
@fixed_y = @y if @y != 0
|
||||
|
||||
@style.width = default(:width) || $window.width
|
||||
@style.height = default(:height) || $window.height
|
||||
@style.width = default(:width) || nil
|
||||
@style.height = default(:height) || nil
|
||||
|
||||
stylize
|
||||
|
||||
@@ -159,7 +162,7 @@ module CyberarmEngine
|
||||
|
||||
def width
|
||||
if visible?
|
||||
(@style.border_thickness_left + @style.padding_left) + @style.width + (@style.padding_right + @style.border_thickness_right)
|
||||
(@style.border_thickness_left + @style.padding_left) + @width + (@style.padding_right + @style.border_thickness_right)
|
||||
else
|
||||
0
|
||||
end
|
||||
@@ -171,7 +174,7 @@ module CyberarmEngine
|
||||
|
||||
def height
|
||||
if visible?
|
||||
(@style.border_thickness_top + @style.padding_top) + @style.height + (@style.padding_bottom + @style.border_thickness_bottom)
|
||||
(@style.border_thickness_top + @style.padding_top) + @height + (@style.padding_bottom + @style.border_thickness_bottom)
|
||||
else
|
||||
0
|
||||
end
|
||||
@@ -181,6 +184,19 @@ module CyberarmEngine
|
||||
@style.margin_top + height + @style.margin_bottom
|
||||
end
|
||||
|
||||
private def dimensional_size(size, dimension)
|
||||
raise "dimension must be either :width or :height" unless dimension == :width || dimension == :height
|
||||
if size && size.is_a?(Numeric)
|
||||
if size.between?(0.0, 1.0)
|
||||
@parent.send(:"#{dimension}") * size
|
||||
else
|
||||
size
|
||||
end
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def background=(_background)
|
||||
@style.background_canvas.background=(_background)
|
||||
update_background
|
||||
|
||||
@@ -5,21 +5,7 @@ module CyberarmEngine
|
||||
@path = path
|
||||
|
||||
@image = Gosu::Image.new(path, retro: @options[:image_retro])
|
||||
if @options[:width] && @options[:height]
|
||||
@scale_x = @options[:width].to_f / @image.width
|
||||
@scale_y = @options[:height].to_f / @image.height
|
||||
elsif @options[:width]
|
||||
@scale_x = @options[:width].to_f / @image.width
|
||||
@scale_y = @scale_x
|
||||
elsif @options[:height]
|
||||
@scale_y = @options[:height].to_f / @image.height
|
||||
@scale_x = @scale_y
|
||||
else
|
||||
@scale_x, @scale_y = 1, 1
|
||||
end
|
||||
|
||||
raise "Scale X" unless @scale_x.is_a?(Numeric)
|
||||
raise "Scale Y" unless @scale_y.is_a?(Numeric)
|
||||
@scale_x, @scale_y = 1, 1
|
||||
end
|
||||
|
||||
def render
|
||||
@@ -35,8 +21,24 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def recalculate
|
||||
@style.width = @image.width * @scale_x
|
||||
@style.height = @image.height * @scale_y
|
||||
_width = dimensional_size(@style.width, :width)
|
||||
_height= dimensional_size(@style.height,:height)
|
||||
|
||||
if _width && _height
|
||||
@scale_x = _width.to_f / @image.width
|
||||
@scale_y = _height.to_f / @image.height
|
||||
elsif _width
|
||||
@scale_x = _width.to_f / @image.width
|
||||
@scale_y = @scale_x
|
||||
elsif _height
|
||||
@scale_y = _height.to_f / @image.height
|
||||
@scale_x = @scale_y
|
||||
else
|
||||
@scale_x, @scale_y = 1, 1
|
||||
end
|
||||
|
||||
@width = _width ? _width : @image.width.round * @scale_x
|
||||
@height= _height ? _height : @image.height.round * @scale_y
|
||||
end
|
||||
|
||||
def value
|
||||
|
||||
@@ -17,8 +17,10 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def recalculate
|
||||
@style.width = @text.width.round
|
||||
@style.height= @text.height.round
|
||||
_width = dimensional_size(@style.width, :width)
|
||||
_height= dimensional_size(@style.height,:height)
|
||||
@width = _width ? _width : @text.width.round
|
||||
@height= _height ? _height : @text.height.round
|
||||
|
||||
@text.x = @style.border_thickness_left + @style.padding_left + @x
|
||||
@text.y = @style.border_thickness_top + @style.padding_top + @y
|
||||
|
||||
Reference in New Issue
Block a user