Skip to content

Commit

Permalink
Fix columnar arrangement - use hoffsets
Browse files Browse the repository at this point in the history
Now it gets the list of nested contents and their size ahead of time and
preprocesses it into a single number to use to pad out the gaps between.

This only needs to happen with the nested content is not a Frame with a
set size other than `:none`. The rest of the time, this code doesn't
really do anything.

At least it shouldn't!
  • Loading branch information
acook committed Oct 9, 2023
1 parent f6ad322 commit a2f1045
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
42 changes: 29 additions & 13 deletions lib/remedy/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,7 @@ def arrange_contents
# TODO: insert padding?
content_to_arrange.flatten
when :columnar
rows = maxsizeof(content_to_arrange).row
result = Array.new
rows.times do |row|
arranged_line = ""
content_to_arrange.each do |content|
line = content[row]
if line then
arranged_line << line
end
end
result << arranged_line
end
result
arrange_columnar content_to_arrange
when :arbitrary
arrange_arbitrary content_to_arrange
else
Expand Down Expand Up @@ -320,6 +308,34 @@ def arrange_arbitrary content_to_arrange
arrange_buffer.to_a
end

def arrange_columnar content_to_arrange
content_list = depth_sort(content_to_arrange)
rows = maxsizeof(content_list).row
result = Array.new

content_sizes = [0] # the first column starts with zero

content_list.each_with_object(content_sizes).with_index do |(content, cs), i|
content.available_size = available_size if content.respond_to? :available_size
cs << sizeof(content).width + cs[i]
end

rows.times do |row|
arranged_line = ""

content_list.each.with_index do |content, index|
line = content[row]
if line then
padding = fill * [content_sizes[index] - arranged_line.length, 0].max
arranged_line << padding
arranged_line << line
end
end
result << arranged_line
end
result
end

def align_contents! content_to_align, original_size
case halign
when :left
Expand Down
2 changes: 1 addition & 1 deletion spec/frame_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@
end

it "arranges contents next to each other" do
expected = "ab###\n #c#\n ###"
expected = "ab###\n #c#\n ###"
actual = f.to_s
expect(actual).to eq expected
end
Expand Down

0 comments on commit a2f1045

Please sign in to comment.