lib/cyberarm_engine/ui/elements/container.rb in cyberarm_engine-0.21.0 vs lib/cyberarm_engine/ui/elements/container.rb in cyberarm_engine-0.22.0
- old
+ new
@@ -134,11 +134,35 @@
@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
+ # FIXME: Correctly handle alignment when element has siblings
+ # FIXME: Enable alignment for any element, not just containers
+ if @style.v_align
+ space = space_available_height
+
+ case @style.v_align
+ when :center
+ @y = parent.height / 2 - height / 2
+ when :bottom
+ @y = parent.height - height
+ end
+ end
+
+ if @style.h_align
+ space = space_available_width
+
+ case @style.h_align
+ when :center
+ @x = parent.width / 2 - width / 2
+ when :right
+ @x = parent.width - width
+ end
+ end
+
+ # Move children to parent after positioning
@children.each do |child|
child.x += (@x + @style.border_thickness_left) - style.margin_left
child.y += (@y + @style.border_thickness_top) - style.margin_top
child.stylize
@@ -170,21 +194,19 @@
outer_width
end
def fits_on_line?(element) # Flow
- p [@options[:id], @width] if @options[:id]
@current_position.x + element.outer_width <= max_width &&
@current_position.x + element.outer_width <= window.width
end
def position_on_current_line(element) # Flow
element.x = element.style.margin_left + @current_position.x
element.y = element.style.margin_top + @current_position.y
@current_position.x += element.outer_width
- @current_position.x = @style.margin_left if @current_position.x >= max_width
end
def tallest_neighbor(querier, _y_position) # Flow
response = querier
@children.each do |child|
@@ -193,17 +215,17 @@
end
response
end
- def position_on_next_line(child) # Flow
- @current_position.x = @style.margin_left
- @current_position.y += tallest_neighbor(child, @current_position.y).outer_height
+ def position_on_next_line(element) # Flow
+ @current_position.x = @style.margin_left + @style.padding_left
+ @current_position.y += tallest_neighbor(element, @current_position.y).outer_height
- child.x = child.style.margin_left + @current_position.x
- child.y = child.style.margin_top + @current_position.y
+ element.x = element.style.margin_left + @current_position.x
+ element.y = element.style.margin_top + @current_position.y
- @current_position.x += child.outer_width
+ @current_position.x += element.outer_width
end
def move_to_next_line(element) # Stack
element.x = element.style.margin_left + @current_position.x
element.y = element.style.margin_top + @current_position.y