Fixed weirdness for Container dynamic fill mode

This commit is contained in:
2022-04-04 10:08:39 -05:00
parent a4d02038c3
commit 08d068f156

View File

@@ -133,17 +133,16 @@ module CyberarmEngine
@width = @style.max_width if @style.max_width && @width > @style.max_width
@height = @style.max_height if @style.max_height && @height > @style.max_height
# FIXME: Detect if other siblings (parents children) also want to fill and share space with them
if @parent && @style.fill
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f # include self since we're dividing
space_available_width = ((@parent.content_width - (@parent.children.map(&:outer_width).sum - outer_width)) / fill_siblings).floor
space_available_height = ((@parent.content_height - (@parent.children.map(&:outer_height).sum - outer_height)) / fill_siblings).floor
space_available_width = ((@parent.content_width - (@parent.children.reject { |c| c.style.fill }).map(&:outer_width).sum) / fill_siblings).round
space_available_height = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings).round
@width = space_available_width - inner_width if @parent.is_a?(Flow)
@height = space_available_height - inner_height if @parent.is_a?(Stack)
# pp ["siblings: #{fill_siblings}", "parent is flow: #{@parent.is_a?(Flow)}", "parent is stack: #{@parent.is_a?(Stack)}", [@parent.content_width, space_available_width, @width, outer_width], [@parent.content_height, space_available_height, @height, outer_height]]
# pp ["siblings: #{fill_siblings}", "parent is #{@parent.inspect}", [@parent.content_width, space_available_width, @width, outer_width], [@parent.content_height, space_available_height, @height, outer_height]]
end
end