fix(layout): handle if child.grow results in height <= 0

This commit is contained in:
Munif Tanjim 2024-06-23 10:55:17 +06:00
parent a2bc1e9d03
commit 61574ce6e6
2 changed files with 58 additions and 0 deletions

View file

@ -57,6 +57,12 @@ local function get_child_size(parent, child, container_size, growable_dimension_
if child.component.border then
inner_size.width = inner_size.width - child.component.border._.size_delta.width
inner_size.height = inner_size.height - child.component.border._.size_delta.height
if inner_size.height <= 0 then
local height_adjustment = math.abs(inner_size.height) + 1
inner_size.height = inner_size.height + height_adjustment
outer_size.height = outer_size.height + height_adjustment
end
end
end

View file

@ -1098,6 +1098,58 @@ describe("nui.layout", function()
})
end)
it("handles if child.grow results in height <= 0", function()
layout = get_initial_layout({ position = 0, size = "100%" })
layout:update(Layout.Box({
Layout.Box(p1, { size = win_height }),
Layout.Box(p2, { grow = 1 }),
}, { dir = "col" }))
layout:mount()
local expected_layout_config = {
relative = {
type = "win",
winid = winid,
},
position = {
row = 0,
col = 0,
},
size = {
width = win_width,
height = win_height,
},
}
assert_layout_config(expected_layout_config)
assert_component = get_assert_component(layout)
assert_component(p1, {
position = {
row = 0,
col = 0,
},
size = {
width = win_width,
height = win_height,
},
})
assert_component(p2, {
position = {
row = win_height,
col = 0,
},
size = {
width = win_width,
height = 1,
},
})
end)
it("can change boxes", function()
layout = Layout(
{ position = 0, size = "100%" },