Closed al-ce closed 1 year ago
Hi @al-ce! It sounds great to have the ability to position the UI. I hadn't given it any thoughts at all yet tbh so feel free to open a PR :)
Sorry for doing advertisement here π
Unless it was a deliberate choice to not use nui.nvim
... nui.nvim
can actually take care of these UI needs for the plugin. It was created for plugin authors so that they don't have to spend time around UI codes and corner-cases, and focus on the functionality of the plugin instead.
Here's a list of plugins that use nui.nvim
: https://github.com/MunifTanjim/nui.nvim/wiki/nui.nvim-in-the-wild
Sorry for doing advertisement here π
Unless it was a deliberate choice to not use
nui.nvim
...nui.nvim
can actually take care of these UI needs for the plugin. It was created for plugin authors so that they don't have to spend time around UI codes and corner-cases, and focus on the functionality of the plugin instead.Here's a list of plugins that use
nui.nvim
: https://github.com/MunifTanjim/nui.nvim/wiki/nui.nvim-in-the-wild
Hey, glad you noticed this issue! No, it was not deliberate, I've seen nui.nvim
of course in my plugin dependencies but it just didn't cross my mind and haven't really read the docs π
I'm about to go looking but I'd appreciate your input, would implementing nui involve rebuilding the ui (with the benefits nui can bring) or can it be integrated into what currently exists?
No sunk cost attachments here, happy to follow @AckslD 's lead and help in either direction.
Thanks for sharing @MunifTanjim! No, not deliberate, I started prototyping at some point and one thing lead to another :)
Do you think there are advantages of switching over at this point? I won't have a lot of time for a while, but if anyone feels like switching over for any reason, even just for fun or to learn I'm happy. As long as the current functionality remains of course :)
would implementing nui involve rebuilding the ui
Using nui.nvim
would mean you can remove most of muren/ui.lua
.
And build the current ui with something like this:
local patterns_popup = Popup(...)
local replacements_popup = Popup(...)
local options_popup = Popup(...)
local preview_popup = Popup(...)
local layout = Layout({
relative = "editor",
position = { row = 0, col = "100%" },
size = { height = 22, width = 80 },
}, Layout.Box({
Layout.Box({
Layout.Box(patterns_popup, { grow = 2 }),
Layout.Box(replacements_popup, { grow = 2 }),
Layout.Box(options_popup, { size = 20 }),
}, { dir = "row", size = "50%" }),
Layout.Box(preview_popup, { size = "50%" })
}, { dir = "col" })
You can also leverage NuiText
and NuiLine
for highlighting. For example, rendering lines on options popup:
local option_text = Text("recursive", "@variable.builtin")
local option_lines = {
Line({ option_text })
}
for linenr, line in ipairs(option_lines) do
line:render(options_popup.bufnr, options_popup.ns_id, linenr)
end
Do you think there are advantages of switching over at this point?
nui.nvim
handles a lots of edge cases and provides nicer high level api to work with)But if the UI codes in this plugin is already complete (i.e. nothing new to introduce) then there's no advantages.
As long as the current functionality remains of course
nui.nvim
doesn't impose any restrictions at all. So there's no reason any functionality would need to be removed because of using nui.nvim
.
Closing this by #25. There might still be a reason to switch to nui.nvim
in the future.
Hi, thanks for the great plugin! I hope I didn't miss some built in way to do this, but I was wondering if you had plans to allow options for positioning the pop up window(s). This would be useful since sometimes I like to look back at the code in full for context.
I made some quick changes on a fork to show what I mean. I didn't want to make a PR without checking if this was in your roadmap or you wanted to handle this further down the line (also I haven't implemented any tests on the fork). Thanks!
https://github.com/al-ce/muren.nvim/commit/c5dbd230e2dba3aac11a168985ba3c4d1274bac3
Position could be set with anchors and offset opts. In this picture, the anchor is bottom-right with -2 offsets in each direction, keeping muren off the corner
If some combination of anchors, offsets, and width/height would place the window out of bounds, set it to the furthest in-bound position in the direction of the offset (notice that the anchors are bottom-right, but the offsets are -2000 in each direction, effectively making it a top-left anchored window)