@@ -606,6 +606,8 @@ pub fn drawRuler(self: *Workspace, orientation: RulerOrientation) void {
606606 return ;
607607 };
608608 const largest_label_size = font .textSize (largest_label );
609+ const natural_scale = dvui .currentWindow ().natural_scale ;
610+ const largest_label_phys = largest_label_size .scale (natural_scale , dvui .Size .Physical );
609611 const base_ruler_size = largest_label_size .w + pixi .editor .settings .ruler_padding ;
610612
611613 const ruler_thickness : f32 = switch (orientation ) {
@@ -642,7 +644,7 @@ pub fn drawRuler(self: *Workspace, orientation: RulerOrientation) void {
642644 });
643645 defer top_box .deinit ();
644646
645- self .drawRulerContent (file , font , orientation , ruler_thickness , largest_label );
647+ self .drawRulerContent (file , font , orientation , ruler_thickness , largest_label , null );
646648 },
647649 .vertical = > {
648650 var ruler_box = dvui .box (@src (), .{ .dir = .vertical }, .{
@@ -653,18 +655,20 @@ pub fn drawRuler(self: *Workspace, orientation: RulerOrientation) void {
653655 });
654656 defer ruler_box .deinit ();
655657
656- self .drawRulerContent (file , font , orientation , ruler_thickness , largest_label );
658+ self .drawRulerContent (file , font , orientation , ruler_thickness , largest_label , largest_label_phys );
657659 },
658660 }
659661}
660662
663+ /// `largest_row_index_*` come from `drawRuler` (widest row index string and its measured size in physical pixels).
661664fn drawRulerContent (
662665 self : * Workspace ,
663666 file : * pixi.Internal.File ,
664667 font : dvui.Font ,
665668 orientation : RulerOrientation ,
666669 ruler_size : f32 ,
667- _ : []const u8 ,
670+ largest_row_index_label : []const u8 ,
671+ largest_row_index_size_phys : ? dvui.Size.Physical ,
668672) void {
669673 const scale = file .editor .canvas .scale ;
670674 const canvas = file .editor .canvas ;
@@ -792,6 +796,12 @@ fn drawRulerContent(
792796 .vertical = > .horizontal ,
793797 };
794798
799+ // Shared layout width for every row tick (widest index string); actual glyph size may differ per cell.
800+ const vertical_row_layout_size_phys : ? dvui.Size.Physical = switch (orientation ) {
801+ .vertical = > largest_row_index_size_phys ,
802+ .horizontal = > null ,
803+ };
804+
795805 var index : usize = 0 ;
796806 while (index < count ) : (index += 1 ) {
797807 var reorderable = reorder .reorderable (@src (), .{
@@ -880,7 +890,8 @@ fn drawRulerContent(
880890 .horizontal = > .horizontal ,
881891 .vertical = > .vertical ,
882892 },
883- .largest_label = null ,
893+ .largest_label = if (orientation == .vertical ) largest_row_index_label else null ,
894+ .ref_size_physical = vertical_row_layout_size_phys ,
884895 });
885896
886897 const cell_rect = cell_box .data ().rectScale ().r ;
@@ -963,19 +974,27 @@ pub const TextLabelOptions = struct {
963974 rect : dvui.Rect.Physical ,
964975 color : dvui.Color ,
965976 mode : Mode = .horizontal ,
977+ /// Widest row index string (e.g. `"99"`); layout cell size uses this, text may be a shorter index.
966978 largest_label : ? []const u8 = null ,
979+ /// When set, layout size for that widest string (already × `natural_scale`); skips `textSize(largest_label)` per cell.
980+ ref_size_physical : ? dvui.Size.Physical = null ,
967981};
968982
969983pub fn drawRulerLabel (_ : * Workspace , options : TextLabelOptions ) void {
970984 const font = options .font ;
971985 const label = options .label ;
972986 const rect = options .rect ;
973987 const color = options .color ;
988+ const natural = dvui .currentWindow ().natural_scale ;
974989
975- const label_size = font .textSize (options .largest_label orelse label ).scale (dvui .currentWindow ().natural_scale , dvui .Size .Physical );
976- const actual_label_size = font .textSize (label ).scale (dvui .currentWindow ().natural_scale , dvui .Size .Physical );
990+ const ref_for_layout = options .largest_label orelse label ;
991+ const label_size = options .ref_size_physical orelse font .textSize (ref_for_layout ).scale (natural , dvui .Size .Physical );
992+ const actual_label_size = if (std .mem .eql (u8 , ref_for_layout , label ))
993+ label_size
994+ else
995+ font .textSize (label ).scale (natural , dvui .Size .Physical );
977996
978- const padding = pixi .editor .settings .ruler_padding * dvui . currentWindow (). natural_scale ;
997+ const padding = pixi .editor .settings .ruler_padding * natural ;
979998
980999 var label_rect = rect ;
9811000
@@ -990,7 +1009,7 @@ pub fn drawRulerLabel(_: *Workspace, options: TextLabelOptions) void {
9901009 .color = color ,
9911010 .rs = .{
9921011 .r = label_rect ,
993- .s = dvui . currentWindow (). natural_scale ,
1012+ .s = natural ,
9941013 },
9951014 }) catch {
9961015 dvui .log .err ("Failed to render text" , .{});
@@ -1006,7 +1025,7 @@ pub fn drawRulerLabel(_: *Workspace, options: TextLabelOptions) void {
10061025 .color = color ,
10071026 .rs = .{
10081027 .r = label_rect ,
1009- .s = dvui . currentWindow (). natural_scale ,
1028+ .s = natural ,
10101029 },
10111030 }) catch {
10121031 dvui .log .err ("Failed to render text" , .{});
0 commit comments