Compare commits

4 Commits

View File

@@ -124,6 +124,26 @@ module CyberarmEngine
@width = _width || (@children.map { |c| c.x + c.outer_width }.max || 0).round @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 @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 end
# Move child to parent after positioning # Move child to parent after positioning
@@ -151,12 +171,14 @@ module CyberarmEngine
end end
def max_width def max_width
_width = dimensional_size(@style.width, :width) # _width = dimensional_size(@style.width, :width)
if _width # if _width
outer_width # outer_width
else # else
window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right) # window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
end # end
outer_width
end end
def fits_on_line?(element) # Flow def fits_on_line?(element) # Flow