Probably fix layout issues caused by floating point errors where an element is wrapped when it has space (e.g. 2 elements with a width 0.5 not fitting properly)

This commit is contained in:
2022-05-02 19:08:47 -05:00
parent 300e7c4e59
commit 31e909eb30
6 changed files with 16 additions and 14 deletions

View File

@@ -441,7 +441,7 @@ module CyberarmEngine
raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
new_size = if size.is_a?(Numeric) && size.between?(0.0, 1.0)
(@parent.send(:"content_#{dimension}") * size).round - send(:"noncontent_#{dimension}").round
(@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
else
size
end
@@ -450,11 +450,15 @@ module CyberarmEngine
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f # include self since we're dividing
if dimension == :width && @parent.is_a?(Flow)
space_available_width = ((@parent.content_width - (@parent.children.reject { |c| c.style.fill }).map(&:outer_width).sum) / fill_siblings).round
space_available_width = ((@parent.content_width - (@parent.children.reject { |c| c.style.fill }).map(&:outer_width).sum) / fill_siblings)
space_available_width = space_available_width.nan? ? 0 : space_available_width.floor # The parent element might not have its dimensions, yet.
return space_available_width - noncontent_width
elsif dimension == :height && @parent.is_a?(Stack)
space_available_height = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings).round
space_available_height = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings)
space_available_height = space_available_height.nan? ? 0 : space_available_height.floor # The parent element might not have its dimensions, yet.
return space_available_height - noncontent_height
end
@@ -509,8 +513,6 @@ module CyberarmEngine
end
def background_image=(image_path)
pp @style.background_image_canvas.image
@style.background_image = image_path.is_a?(Gosu::Image) ? image_path : get_image(image_path)
update_background_image
end

View File

@@ -64,8 +64,8 @@ module CyberarmEngine
@scale_y = 1
end
@width = _width || @image.width.round * @scale_x
@height = _height || @image.height.round * @scale_y
@width = _width || @image.width.floor * @scale_x
@height = _height || @image.height.floor * @scale_y
update_background
else

View File

@@ -122,8 +122,8 @@ module CyberarmEngine
_width = dimensional_size(@style.width, :width)
_height = dimensional_size(@style.height, :height)
@width = _width || (@children.map { |c| c.x + c.outer_width }.max || 0).round
@height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).round
@width = _width || (@children.map { |c| c.x + c.outer_width }.max || 0).floor
@height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).floor
end
# Move child to parent after positioning

View File

@@ -98,7 +98,7 @@ module CyberarmEngine
end
def row_at(y)
((y - @text.y) / @text.textobject.height).round
((y - @text.y) / @text.textobject.height).floor
end
def column_at(x, y)

View File

@@ -45,8 +45,8 @@ module CyberarmEngine
@scale_y = 1
end
@width = _width || @image.width.round * @scale_x
@height = _height || @image.height.round * @scale_y
@width = _width || @image.width.floor * @scale_x
@height = _height || @image.height.floor * @scale_y
update_background
end

View File

@@ -43,8 +43,8 @@ module CyberarmEngine
handle_text_wrapping(_width)
@width = _width || @text.width.round
@height = _height || @text.height.round
@width = _width || @text.width.floor
@height = _height || @text.height.floor
@text.y = @style.border_thickness_top + @style.padding_top + @y
@text.z = @z + 3