Moved min_width/height, max_width/height and fill control from Container into Element#dimensional_size so any element can use them

This commit is contained in:
2022-04-25 16:48:17 -05:00
parent f2ea0d9942
commit d81df5f4e2
2 changed files with 20 additions and 21 deletions

View File

@@ -124,26 +124,6 @@ module CyberarmEngine
@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
# min width/height
@width = @style.min_width if @style.min_width && @width < @style.min_width
@height = @style.min_height if @style.min_height && @height < @style.min_height
# max width/height
@width = @style.max_width if @style.max_width && @width > @style.max_width
@height = @style.max_height if @style.max_height && @height > @style.max_height
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.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 - noncontent_width if @parent.is_a?(Flow)
@height = space_available_height - noncontent_height if @parent.is_a?(Stack)
# 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
# Move child to parent after positioning