Skip to content

Commit cfd4a92

Browse files
committed
Minor refactoring
1 parent 54e8fd4 commit cfd4a92

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/element.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ pub fn Element(comptime T: type) type {
787787
/// shrink to based on the children. If children wrap according
788788
/// to the width of the parent, then the parent width is needed
789789
/// to calculate the height
790-
pub fn shrink_height(self: *Self, display: *Display(T), parent_width: f32) f32 {
790+
pub fn minimum_needed_height(self: *Self, display: *Display(T), parent_width: f32) f32 {
791791
if (self.visible == .hidden)
792792
return 0;
793793
if (self.layout.y == .fixed)
@@ -1062,7 +1062,7 @@ pub fn Element(comptime T: type) type {
10621062
///
10631063
/// If the text is centred or right aligned, then each line must be pushed along
10641064
/// by a certain offset amount.
1065-
inline fn layout_label(
1065+
pub inline fn layout_label(
10661066
element: *Self,
10671067
display_scale: f32,
10681068
parent_inner_width: f32,
@@ -1490,7 +1490,7 @@ pub fn Element(comptime T: type) type {
14901490
// Add spacing before next element, if needed
14911491
minimum_needed += parent.type.panel.spacing;
14921492
}
1493-
const height = element.shrink_height(display, available_width);
1493+
const height = element.minimum_needed_height(display, available_width);
14941494
minimum_needed += height;
14951495
}
14961496
// Bound to the minimum/maximum height
@@ -1511,7 +1511,7 @@ pub fn Element(comptime T: type) type {
15111511
for (parent.type.panel.children.items) |element| {
15121512
if (element.layout.position == .float) continue;
15131513

1514-
const height = element.shrink_height(display, available_width);
1514+
const height = element.minimum_needed_height(display, available_width);
15151515
if (height > minimum_needed)
15161516
minimum_needed = height;
15171517
}

src/engine.zig

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ pub fn Display(comptime T: type) type {
827827
},
828828
.shrinks => {
829829
// Shrink to the smallest the children will allow
830-
const new_height = element.shrink_height(self, available_width);
830+
const new_height = element.minimum_needed_height(self, available_width);
831831
if (element.rect.height != new_height) {
832832
element.rect.height = new_height;
833833
child_resized = true;
@@ -3136,7 +3136,7 @@ test "button sizing" {
31363136
.layout = .{ .x = .shrinks, .y = .shrinks },
31373137
});
31383138
try eq(5, panel.minimum_needed_width(display, 500));
3139-
try eq(8, panel.shrink_height(display, 500));
3139+
try eq(8, panel.minimum_needed_height(display, 500));
31403140

31413141
const not_quite_one_line = display.text_height.pixel_height(display.scale) - 5;
31423142
const not_quite_two_lines = display.text_height.pixel_height(display.scale) * 2 - 5;
@@ -3150,12 +3150,12 @@ test "button sizing" {
31503150
});
31513151
display.relayout();
31523152
try eq(50, button.minimum_needed_width(display, 500));
3153-
try eq(50, button.shrink_height(display, 500));
3153+
try eq(50, button.minimum_needed_height(display, 500));
31543154
button.layout.x = .shrinks;
31553155
button.layout.y = .shrinks;
31563156
try eq(30, button.minimum_needed_width(display, 500));
31573157
// The words will overflow the bottom of the box
3158-
try eq(not_quite_one_line, button.shrink_height(display, 500));
3158+
try eq(not_quite_one_line, button.minimum_needed_height(display, 500));
31593159

31603160
display.relayout();
31613161
try eq(30, panel.minimum_needed_width(display, 500));
@@ -3236,7 +3236,7 @@ test "text input sizing" {
32363236
defer l.destroy(allocator, display);
32373237
l.pad = .{ .top = 0, .bottom = 0, .left = 0, .right = 0 };
32383238
try eq(500, l.minimum_needed_width(display, 500));
3239-
try eq(50, l.shrink_height(display, 500));
3239+
try eq(50, l.minimum_needed_height(display, 500));
32403240
}
32413241

32423242
{
@@ -3252,7 +3252,7 @@ test "text input sizing" {
32523252
defer l.destroy(allocator, display);
32533253
l.pad = .{ .top = 0, .bottom = 0, .left = 0, .right = 0 };
32543254
try eq(500, l.minimum_needed_width(display, 500));
3255-
try eq(60, l.shrink_height(display, 500));
3255+
try eq(60, l.minimum_needed_height(display, 500));
32563256
}
32573257

32583258
{
@@ -3268,7 +3268,7 @@ test "text input sizing" {
32683268
defer l.destroy(allocator, display);
32693269
l.pad = .{ .top = 0, .bottom = 0, .left = 0, .right = 0 };
32703270
try eq(401, l.minimum_needed_width(display, 500));
3271-
try eq(display.text_height.pixel_height(display.scale), l.shrink_height(display, 500));
3271+
try eq(display.text_height.pixel_height(display.scale), l.minimum_needed_height(display, 500));
32723272
}
32733273

32743274
{
@@ -3284,7 +3284,7 @@ test "text input sizing" {
32843284
defer l.destroy(allocator, display);
32853285
l.pad = .{ .top = 0, .bottom = 0, .left = 0, .right = 0 };
32863286
try eq(401, @round(l.minimum_needed_width(display, 500)));
3287-
try eq(display.text_height.pixel_height(display.pixel_scale), l.shrink_height(display, 500));
3287+
try eq(display.text_height.pixel_height(display.pixel_scale), l.minimum_needed_height(display, 500));
32883288
}
32893289

32903290
{
@@ -3307,9 +3307,9 @@ test "text input sizing" {
33073307

33083308
// Display width of the words when rendered to the physical display
33093309
try eq(94, @round(l.minimum_needed_width(display, 500) / display.pixel_scale));
3310-
try eq(display.text_height.pixel_height(display.pixel_scale), l.shrink_height(display, 500));
3310+
try eq(display.text_height.pixel_height(display.pixel_scale), l.minimum_needed_height(display, 500));
33113311
// Display width on physical display with word wrap
3312-
try eq(2 * display.text_height.pixel_height(display.pixel_scale), l.shrink_height(display, 40 * display.pixel_scale));
3312+
try eq(2 * display.text_height.pixel_height(display.pixel_scale), l.minimum_needed_height(display, 40 * display.pixel_scale));
33133313
}
33143314

33153315
var panel = try display.add_panel(allocator, .{
@@ -3319,7 +3319,7 @@ test "text input sizing" {
33193319
.layout = .{ .x = .shrinks, .y = .shrinks },
33203320
});
33213321
try eq(5, panel.minimum_needed_width(display, 500));
3322-
try eq(8, panel.shrink_height(display, 500));
3322+
try eq(8, panel.minimum_needed_height(display, 500));
33233323

33243324
// Fixed width and height cant be shrunk or grown, except if minimum
33253325
// or maximum override it.
@@ -3333,7 +3333,7 @@ test "text input sizing" {
33333333
});
33343334
label.pad = .{ .top = 0, .bottom = 0, .left = 0, .right = 0 };
33353335
try eq(500, label.minimum_needed_width(display, 500));
3336-
try eq(60, label.shrink_height(display, 500));
3336+
try eq(60, label.minimum_needed_height(display, 500));
33373337

33383338
// Fixed width and height cant be shrunk or grown, except if minimum
33393339
// or maximum override it.
@@ -3347,14 +3347,14 @@ test "text input sizing" {
33473347
});
33483348
label.pad = .{ .top = 0, .bottom = 0, .left = 0, .right = 0 };
33493349
try eq(300, label.minimum_needed_width(display, 500));
3350-
try eq(100, label.shrink_height(display, 500));
3350+
try eq(100, label.minimum_needed_height(display, 500));
33513351

33523352
label.minimum.width = display.text_height.pixel_height(1);
33533353
label.minimum.height = display.text_height.pixel_height(1);
33543354
label.layout.x = .shrinks;
33553355
label.layout.y = .shrinks;
33563356
try eq(94, @round(label.minimum_needed_width(display, 500) / display.pixel_scale));
3357-
try eq(display.text_height.pixel_height(1), @round(label.shrink_height(display, 500) / display.pixel_scale));
3357+
try eq(display.text_height.pixel_height(1), @round(label.minimum_needed_height(display, 500) / display.pixel_scale));
33583358
label.layout.x = .grows;
33593359
try eq(401, @round(label.minimum_needed_width(display, 500)));
33603360

0 commit comments

Comments
 (0)