koerschens 3 жил өмнө
parent
commit
bd2401ed6b
1 өөрчлөгдсөн 12 нэмэгдсэн , 6 устгасан
  1. 12 6
      python/renderer.py

+ 12 - 6
python/renderer.py

@@ -67,8 +67,12 @@ class Renderer:
         first_line = build_line("=", len(lines[-1]))
         
         final_lines = []
+        
+        print(len(line_blocks))
 
         n_rows = ceil(len(line_blocks) / self.columns)
+        
+        calc_index = lambda row, col, n_rows, n_cols: row * n_cols + col
 
         # Format rows and columns
         for row in range(n_rows):
@@ -78,21 +82,23 @@ class Renderer:
 
             # Find max size of the blocks in the same row:
             for col in range(self.columns):
-                if col * n_rows + row < len(line_blocks):
-                    if len(line_blocks[col * n_rows + row]) > max_size:
-                        max_size = len(line_blocks[col * n_rows + row])
+                idx = calc_index(row, col, n_rows, self.columns)
+                if idx < len(line_blocks):
+                    if len(line_blocks[idx]) > max_size:
+                        max_size = len(line_blocks[idx])
 
             for col in range(self.columns):
-                if col * n_rows + row < len(line_blocks):
+                idx = calc_index(row, col, n_rows, self.columns)
+                if idx < len(line_blocks):
                     if len(lines) == 0:
                         lines.extend(
                             self.expand_rendered_block_to_size(
-                                line_blocks[col * n_rows + row], 
+                                line_blocks[idx], 
                                 max_size
                             )
                         )
                     else:
-                        for i, line in enumerate(self.expand_rendered_block_to_size(line_blocks[col * n_rows + row], max_size)):
+                        for i, line in enumerate(self.expand_rendered_block_to_size(line_blocks[idx], max_size)):
                             lines[i] += line
             
             final_lines.extend(lines)