Skip to content

Commit

Permalink
WIP: New split-float layout
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Jul 23, 2024
1 parent 8bafeea commit abb934e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/clojure-test/ui/layout.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local FloatLayout = require("clojure-test.ui.layout.float")
local SplitLayout = require("clojure-test.ui.layout.split")

local config = require("clojure-test.config")
local utils = require("clojure-test.utils")
Expand Down Expand Up @@ -82,6 +83,10 @@ function M.create(on_event)
layout_fn = FloatLayout
end

if config.layout.style == "split" then
layout_fn = SplitLayout
end

local layout = layout_fn()

function layout:map(mode, chord, fn, opts)
Expand Down
89 changes: 89 additions & 0 deletions lua/clojure-test/ui/layout/split.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
local NuiLayout = require("nui.layout")
local NuiPopup = require("nui.popup")
local NuiSplit = require("nui.split")

return function()
local top_left_popup = NuiPopup({
border = {
style = "rounded",
text = {
top = " Expected ",
top_align = "left",
},
},
})
local top_right_popup = NuiPopup({
border = {
style = "rounded",
text = {
top = " Result ",
top_align = "left",
},
},
})

local report_tree = NuiSplit({
position = "right",
size = "25%",
enter = true,
focusable = true,
})

local double = NuiLayout.Box({
NuiLayout.Box(top_left_popup, { grow = 1 }),
NuiLayout.Box(top_right_popup, { grow = 1 }),
}, { dir = "row", size = "70%" })

local single = NuiLayout.Box({
NuiLayout.Box(top_right_popup, { grow = 1 }),
}, { dir = "row", size = "70%" })

local root_layout = NuiLayout({
position = {
row = "25%",
col = "5%"
},
relative = "editor",
size = {
width = 150,
height = 60,
},
}, double)

local SplitLayout = {
layout = root_layout,

windows = {
tree = report_tree,
left = top_left_popup,
right = top_right_popup,
},
}

function SplitLayout:mount()
report_tree:mount()
root_layout:mount()
end

function SplitLayout:render_single()
root_layout:mount()
root_layout:update(single)
end

function SplitLayout:render_double()
root_layout:mount()
root_layout:update(double)
end

function SplitLayout:unmount()
report_tree:unmount()
root_layout:unmount()
end

function SplitLayout:on_focus_lost()
root_layout:unmount()
return true
end

return SplitLayout
end

0 comments on commit abb934e

Please sign in to comment.