re-implemented sorting
This commit is contained in:
		
							parent
							
								
									44869a7926
								
							
						
					
					
						commit
						07993f5bb5
					
				
							
								
								
									
										2948
									
								
								output.pdf
								
								
								
								
							
							
						
						
									
										2948
									
								
								output.pdf
								
								
								
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -30,6 +30,13 @@ const Card = struct { | |||
| const TextCard = struct { | ||||
|     lines: [][]const u8 = undefined, | ||||
| }; | ||||
| const CardSortContext = struct { | ||||
|     const Self = @This(); | ||||
|     list: []TextCard, | ||||
|     pub fn lessThan(ctx: Self, a: usize, b: usize) bool { | ||||
|         return ctx.list[a].lines.len < ctx.list[b].lines.len; | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| //dimension constants and defaults | ||||
| const cardWidth = 30; | ||||
|  | @ -89,6 +96,7 @@ pub fn main() !void { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     cards.sort(CardSortContext{ .list = cards.values() }); | ||||
|     var allPrinted = std.ArrayList([]const u8).init(allocator); | ||||
| 
 | ||||
|     const pdf_doc: *c.pdf_doc = @ptrCast(c.pdf_create(c.PDF_A4_WIDTH, c.PDF_A4_HEIGHT, &c.pdf_info{ .creator = ("My Software" ++ " " ** 53).* }).?); | ||||
|  | @ -213,9 +221,6 @@ const cardRow = struct { | |||
|                 const strippedLine = std.mem.trimRight(u8, line, " "); | ||||
|                 const paddedLine = try std.fmt.allocPrint(gpa.allocator(), lineFormatter, .{strippedLine}); | ||||
|                 // const theoreticalLength = (paddedLine.len * 3) + 1; | ||||
|                 std.debug.print("{s}\n", .{paddedLine}); | ||||
|                 std.debug.print("expected {d}, got: ", .{dw.strWidth(spacer)}); | ||||
|                 std.debug.print("{d}\n", .{dw.strWidth(paddedLine)}); | ||||
|                 assert(dw.strWidth(paddedLine) == dw.strWidth(spacer)); | ||||
|                 // assert(theoreticalLength == pageWidth); | ||||
|                 const placeholder = if (idx < lines.items(.first).len) lines.get(idx) else cardRow{}; | ||||
|  |  | |||
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in New Issue