From 4286ca06b0029400d0cc82964fd363fe58f7ecf1 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Wed, 15 Apr 2026 10:51:10 -0500 Subject: [PATCH] Fix up container's over estimating their width/height some more --- lib/cyberarm_engine/ui/elements/container.rb | 31 +++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/lib/cyberarm_engine/ui/elements/container.rb b/lib/cyberarm_engine/ui/elements/container.rb index 072e542..43a44e1 100644 --- a/lib/cyberarm_engine/ui/elements/container.rb +++ b/lib/cyberarm_engine/ui/elements/container.rb @@ -79,16 +79,17 @@ module CyberarmEngine end def render - # Gosu.clip_to( - # @x - 1 + styled(:margin_left) + styled(:border_thickness_left) + styled(:padding_left), - # @y - 1 + styled(:margin_top) + styled(:border_thickness_top) + styled(:padding_top), - # content_width + 1, - # content_height + 1 - # ) do + Gosu.clip_to( + @x - 1 + styled(:margin_left) + styled(:border_thickness_left) + styled(:padding_left), + @y - 1 + styled(:margin_top) + styled(:border_thickness_top) + styled(:padding_top), + content_width + 1, + content_height + 1 + ) do + Gosu.translate(@scroll_position.x, @scroll_position.y) do @children.each(&:draw) end - # end + end end def debug_draw @@ -182,20 +183,8 @@ module CyberarmEngine _width = dimensional_size(@style.width, :width) _height = dimensional_size(@style.height, :height) - width_correction = 0 - height_correction = 0 - o = self - while (par = o&.parent) - if o.is_a?(Container) - width_correction += o.styled(:margin_left) + o.styled(:padding_left) - height_correction += o.styled(:margin_top) + o.styled(:padding_top) - end - - o = par.parent - end - - @width = _width || (@children.map { |c| c.x + c.outer_width }.max.to_f - width_correction).floor - @height = _height || (@children.map { |c| c.y + c.outer_height }.max.to_f - height_correction).floor + @width = _width || (@children.map { |c| c.x + c.outer_width }.max.to_f - (styled(:margin_left) + styled(:padding_left))).floor + @height = _height || (@children.map { |c| c.y + c.outer_height }.max.to_f - (styled(:margin_top) + styled(:padding_top))).floor end # FIXME: Correctly handle alignment when element has siblings