mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-15 20:52:35 +00:00
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:
@@ -429,11 +429,30 @@ module CyberarmEngine
|
||||
def dimensional_size(size, dimension)
|
||||
raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
|
||||
|
||||
if size.is_a?(Numeric) && size.between?(0.0, 1.0)
|
||||
new_size = if size.is_a?(Numeric) && size.between?(0.0, 1.0)
|
||||
(@parent.send(:"content_#{dimension}") * size).round - send(:"noncontent_#{dimension}").round
|
||||
else
|
||||
size
|
||||
end
|
||||
|
||||
if @parent && @style.fill # Handle fill behavior
|
||||
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
|
||||
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
|
||||
return space_available_height - noncontent_height
|
||||
end
|
||||
|
||||
else # Handle min_width/height and max_width/height
|
||||
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size < @style.send(:"min_#{dimension}")
|
||||
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size > @style.send(:"max_#{dimension}")
|
||||
end
|
||||
|
||||
new_size
|
||||
end
|
||||
|
||||
def background=(_background)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user