Skip to content

Commit

Permalink
fix(layout): starting current position for nested boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
MunifTanjim committed Mar 2, 2024
1 parent c3c7fd6 commit 1b24de4
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lua/nui/layout/float.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ function mod.process(box, meta)
end
-- luacov: enable

local current_position = {
col = 0,
local current_position = box.dir == "row" and {
col = meta.position.col,
row = 0,
} or {
col = 0,
row = meta.position.row,
}

local growable_child_factor = 0
Expand Down
63 changes: 63 additions & 0 deletions tests/nui/layout/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,69 @@ describe("nui.layout", function()
size = { height = 10, width = 10 },
})
end)

it("can handle col[box,row[box,col[box,box]]]", function()
layout = get_initial_layout({ position = 0, size = "100%" })

layout:mount()

layout:update(Layout.Box({
Layout.Box(p1, { size = "50%" }),
Layout.Box({
Layout.Box(p2, { size = "50%" }),
Layout.Box({
Layout.Box(p3, { size = "50%" }),
Layout.Box(p4, { size = "50%" }),
}, { dir = "col", size = "50%" }),
}, { dir = "row", size = "50%" }),
}, { dir = "col" }))

assert_component = get_assert_component(layout)

assert_component(p1, {
position = {
row = 0,
col = 0,
},
size = {
width = win_width,
height = percent(win_height, 50),
},
})

assert_component(p2, {
position = {
row = percent(win_height, 50),
col = 0,
},
size = {
width = percent(win_width, 50),
height = percent(win_height, 50),
},
})

assert_component(p3, {
position = {
row = percent(win_height, 50),
col = percent(win_width, 50),
},
size = {
width = percent(win_width, 50),
height = percent(percent(win_height, 50), 50),
},
})

assert_component(p4, {
position = {
row = percent(win_height, 50 + 25),
col = percent(win_width, 50),
},
size = {
width = percent(win_width, 50),
height = percent(percent(win_height, 50), 50),
},
})
end)
end)
end)

Expand Down

0 comments on commit 1b24de4

Please sign in to comment.