@@ -369,14 +369,14 @@ pub fn Element(comptime T: type) type {
369369 });
370370 }
371371 if (self .style != .normal ) {
372- _ = try out .write (" align =" );
372+ _ = try out .write (" style =" );
373373 _ = try out .write (@tagName (self .style ));
374374 }
375375 if (self .child_align .x != .start or self .child_align .y != .start ) {
376376 _ = try out .write (" align=" );
377- _ = try out .write (@tagName (self .layout .x ));
377+ _ = try out .write (@tagName (self .child_align .x ));
378378 _ = try out .write ("-" );
379- _ = try out .write (@tagName (self .layout .y ));
379+ _ = try out .write (@tagName (self .child_align .y ));
380380 }
381381 _ = try out .write (" layout=" );
382382 _ = try out .write (@tagName (self .layout .x ));
@@ -1216,17 +1216,18 @@ pub fn Element(comptime T: type) type {
12161216 /// by a certain offset amount.
12171217 ///
12181218 /// `parent_inner_width` should be the actual width the parent is
1219- /// passing down to this child element, minus left and right padding, and
1220- /// clamped to the min/max width (including padding)
1219+ /// willing/able to down to this child element, minus the parent
1220+ /// left and right padding, and clamped to the min/max
1221+ /// width (including padding)
12211222 pub inline fn layout_label (
12221223 element : * Self ,
12231224 display_scale : f32 ,
12241225 parent_inner_width : f32 ,
1225- ) void {
1226+ ) f32 {
12261227 std .debug .assert (element .type == .label or element .type == .checkbox );
12271228
1228- if (element .type == .label and element .type .label .text .len == 0 ) return ;
1229- if (element .type == .checkbox and element .type .checkbox .text .len == 0 ) return ;
1229+ if (element .type == .label and element .type .label .text .len == 0 ) return 0 ;
1230+ if (element .type == .checkbox and element .type .checkbox .text .len == 0 ) return 0 ;
12301231
12311232 const text_height = switch (element .type ) {
12321233 .label = > element .type .label .text_size ,
@@ -1238,6 +1239,7 @@ pub fn Element(comptime T: type) type {
12381239 .checkbox = > element .type .checkbox .elements .items ,
12391240 else = > unreachable ,
12401241 };
1242+ if (children .len == 0 ) return 0 ;
12411243
12421244 // Track the minimum needed width. Remember the longest line. Include
12431245 // any left/right padding.
@@ -1317,11 +1319,16 @@ pub fn Element(comptime T: type) type {
13171319 );
13181320
13191321 // Align words to centre or right if requested.
1320- if (children .len == 0 ) return ;
1322+ // centre and end alignment might need the `grows`
1323+ // full width, or the `shrinks` minimum width.
13211324 if (element .child_align .x == .centre or element .child_align .x == .end ) {
13221325 var line_start : usize = 0 ;
13231326 var line_end : usize = 0 ;
1324- const usable_width = wrap_at ;
1327+ const usable_width = switch (element .layout .x ) {
1328+ .grows = > wrap_at ,
1329+ .shrinks = > needed_width - element .pad .left - element .pad .right ,
1330+ .fixed = > element .rect .width - element .pad .left - element .pad .right ,
1331+ };
13251332 while (true ) : (line_end += 1 ) {
13261333 if (line_end + 1 == children .len ) {
13271334 element .do_word_alignment (
@@ -1343,23 +1350,7 @@ pub fn Element(comptime T: type) type {
13431350 }
13441351 }
13451352
1346- if (false ) {
1347- const t = switch (element .type ) {
1348- .button = > element .type .button .translated ,
1349- .label = > element .type .label .translated ,
1350- .checkbox = > element .type .checkbox .translated ,
1351- else = > "" ,
1352- };
1353- trace ("label {s} {t} \" {s}\" wrap={d} need={d} selected={d} (max_parent_width={d})" , .{
1354- element .name ,
1355- element .layout .x ,
1356- t ,
1357- wrap_at ,
1358- needed_width ,
1359- element .rect .width ,
1360- parent_inner_width ,
1361- });
1362- }
1353+ return needed_width ;
13631354 }
13641355
13651356 pub fn keypress (
0 commit comments