Complex input "form" #121
-
Hello, thanks for this great library. Regards |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
So I have been playing with this a bit, and I have found some limitations that make me think the library is not meant to render several ui elements at the same time. |
Beta Was this translation helpful? Give feedback.
-
Right now, creating complex layout is a completely manual process. You'll need to calculate the positions of various components yourself. But it will get easier in the future, check: #18. I already started working on it: #120, but can't promise when it'll be finished. |
Beta Was this translation helpful? Give feedback.
-
My expectation was something like this: local input1 = Input(input_options, {})
local popup1 = Popup(popup_options) -- This includes relative row and col from input 1
local popup2 = Popup(popup_options_including_popup1_stuff) -- same as above but from popup1
input1:mount()
popup1:mount()
popup2:mount()
But instead I have to do it like this local input1 = Input(input_options, {})
input1:mount()
local popup1 = Popup(popup_options) -- This includes relative row and col from input 1
popup1:mount()
local popup2 = Popup(popup_options_including_popup1_stuff) -- same as above but from popup1
popup2:mount() With obviously a lot more logic in between. In order to keep things as close as possible I also tried mapping things in the WinEnter event but it fails. It seems that the win enter event is triggered before the component can be considered mounted, so I can't do this: ---Binds the requested keys to the available actions withinthe contex of the provided popup
---@param mode 'n'|'i'
---@param binds { switch_key: string|string[], exit_key}
---@param popup Popup
---@param alt_win integer alternative window to jump on switch
local function bindKeys(mode, binds, popup, alt_win)
local opts = { noremap = true }
local function map(key, cb)
popup:map(mode, key, cb, opts)
end
if not vim.tbl_islist(binds.switch_key) then
binds.switch_key = { binds.switch_key }
end
for _, key in ipairs(binds.switch_key) do
map(key, function()
vim.api.nvim_set_current_win(alt_win)
vim.cmd('startinsert')
end)
end
map(binds.exit_key, exit)
end
-- Mount the popup only after the input has been mounted
input:on({ event.WinEnter },
function()
layout.popup:mount()
layout.help:mount()
-- bindKeys('n', { switch_key = '<Tab>', exit_key = 'q' }, layout.input, layout./popup.bufnr) -- <- THIS FAILS
bindKeys('n', { switch_key = '<Tab>', exit_key = 'q' }, layout.popup, layout.input.bufnr)
end, { once = true })
I came to the conclusion that I will be better doing the row and column calculations myself rather that relying on the built in ones. That way I will be able to get all the relative positioning, configure all the components and then mount them all at once without introducing that much dependencies between each other. I still miss some more declarative helpers, because I still have to wait to the components to mount in order to map keymaps to them AND be able to access their window IDs (which I need to alternate window key-bindings) Hope you can give me some guidance about having a more declarative way of doing all this before I start trying to build my own abstraction on top of your library. |
Beta Was this translation helpful? Give feedback.
Right now, creating complex layout is a completely manual process. You'll need to calculate the positions of various components yourself.
But it will get easier in the future, check: #18.
I already started working on it: #120, but can't promise when it'll be finished.