From 63a51d9d2f560a7885ad7e19d668d68e926e58a5 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Thu, 18 Nov 2021 11:58:11 -0600 Subject: [PATCH] Improved scroll_height calculation to adapt to how Flow's flow --- lib/cyberarm_engine/ui/element.rb | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/cyberarm_engine/ui/element.rb b/lib/cyberarm_engine/ui/element.rb index 5dd2992..04c38ce 100644 --- a/lib/cyberarm_engine/ui/element.rb +++ b/lib/cyberarm_engine/ui/element.rb @@ -370,19 +370,42 @@ module CyberarmEngine end def scroll_width - @children.sum(&:width) + noncontent_width + @children.sum(&:outer_width) end def scroll_height - @children.sum(&:height) + noncontent_height + if is_a?(CyberarmEngine::Element::Flow) + return 0 if @children.size.zero? + + pairs_ = [] + sorted_children_ = @children.sort_by(&:y) + a_ = [] + y_position_ = sorted_children_.first.y + + sorted_children_.each do |child| + unless child.y == y_position_ + y_position_ = child.y + pairs_ << a_ + a_ = [] + end + + a_ << child + end + + pairs_ << a_ unless pairs_.last == a_ + + pairs_.sum { |pair| pair.map(&:outer_height).max } + @style.padding_bottom + @style.border_thickness_bottom + else + @children.sum(&:outer_height) + @style.padding_bottom + @style.border_thickness_bottom + end end def max_scroll_width - scroll_width - width + scroll_width - outer_width end def max_scroll_height - scroll_height - height + scroll_height - outer_height end def dimensional_size(size, dimension)