nui.nvim icon indicating copy to clipboard operation
nui.nvim copied to clipboard

Improvements to layout docs

Open danielo515 opened this issue 2 years ago • 8 comments

Hello. The layout component is a great addition, thank you. I think the docs can be improved. I base my observations in my own experience, feel free to correct me. The docs mention that the first argument can be either options or a component, where component is either split or popup. Does that mean that, if I provide a split the components will be mounted inside? Or what is it for? I also noticed that not all values are allowed for percentage strings. Anything below 10% (eg 5%, 05%) will be rejected. Is 10% the minimum or is there some other thing to consider?

If you provide values that go beyond 100% (top element being 90% and bottom 20% for example) an error is thrown at runtime.

Last but not least, the box component seems to be compatible with all nui components, but the input one doesn't seems to fit very well. It appears slightly disconnected from the rest of the layout. I can provide an screenshot later.

Regards

danielo515 avatar Nov 27 '22 13:11 danielo515

I think the docs can be improved. I base my observations in my own experience, feel free to correct me.

Any improvements of the documentation is very welcomed!

You can also add various example codes in the wiki page: https://github.com/MunifTanjim/nui.nvim/wiki/nui.layout

A good place to find example codes is the test file: https://github.com/MunifTanjim/nui.nvim/blob/d12a6977846b2fa978bff89b439e509320854e10/tests/nui/layout/init_spec.lua

The docs mention that the first argument can be either options or a component, where component is either split or popup. Does that mean that, if I provide a split the components will be mounted inside? Or what is it for?

Yes, that's exactly it. If the first parameter is a split, the components will be mounted inside that split.

If you provide values that go beyond 100% (top element being 90% and bottom 20% for example) an error is thrown at runtime.

Yes, that's expected. You should take care of it when you set the sizes in percentage.

Last but not least, the box component seems to be compatible with all nui components, but the input one doesn't seems to fit very well. It appears slightly disconnected from the rest of the layout.

Input is actually a popup under the hood: https://github.com/MunifTanjim/nui.nvim/blob/d12a6977846b2fa978bff89b439e509320854e10/lua/nui/input/init.lua#L28

But the height is fixed to 1: https://github.com/MunifTanjim/nui.nvim/blob/d12a6977846b2fa978bff89b439e509320854e10/lua/nui/input/init.lua#L44

So you can't use input with percentage size. You should set a fixed size to input, and use the grow option to fill up the space with other sibling components.

MunifTanjim avatar Nov 27 '22 18:11 MunifTanjim

I also noticed that not all values are allowed for percentage strings. Anything below 10% (eg 5%, 05%) will be rejected. Is 10% the minimum or is there some other thing to consider?

What do you mean by "rejected"? Does it cause any error? For Popup components there's no such limitation.

For Split components, it depends on these vim options:

  • 'winminheight'
  • 'winheight'
  • 'winminwidth'
  • 'winwidth'

MunifTanjim avatar Nov 27 '22 18:11 MunifTanjim

That wiki doesn’t seem to exists

danielo515 avatar Nov 27 '22 20:11 danielo515

That wiki doesn’t seem to exists

It's a public wiki. Anybody should be able to create the page by going to that link.

MunifTanjim avatar Nov 27 '22 20:11 MunifTanjim

That wiki doesn’t seem to exists

It's a public wiki. Anybody should be able to create the page by going to that link.

Ok, I read that incorrectly. I thought you suggested me to check more code samples at the wiki. That with the fact that there are links to the wiki-page in the docs made me think this was a link error. But now I see what you mean.

So you can't use input with percentage size. You should set a fixed size to input, and use the grow option to fill up the space with other sibling components.

Oh, that grow property sounds amazing! Didn't saw it! Gonna try it.

By the way, when I say the Input does not look right, it is not only the placement, but also the appearance (borders and so). Take a look at this screenshot:

image

It is a bit detached and doesn't have any border, despite I added the border style to be rounded, like all the other Popups. Maybe I'm just doing a bad combination of properties.

What do you mean by "rejected"? Does it cause any error? For Popup components there's no such limitation.

I get an error saying that height must be a positive Integer:

Error detected while processing :source (no file):
E5108: Error executing lua ...m/site/pack/packer/start/nui.nvim/lua/nui/popup/init.lua:140: 'height' key must be a positive Integer
stack traceback:
        [C]: in function 'nvim_open_win'
        ...m/site/pack/packer/start/nui.nvim/lua/nui/popup/init.lua:140: in function '_open_window'
        ...m/site/pack/packer/start/nui.nvim/lua/nui/popup/init.lua:222: in function 'mount'
        ...m/site/pack/packer/start/nui.nvim/lua/nui/input/init.lua:112: in function 'mount'
        ...site/pack/packer/start/nui.nvim/lua/nui/layout/float.lua:129: in function 'mount_box'
        .../site/pack/packer/start/nui.nvim/lua/nui/layout/init.lua:273: in function 'mount'
        [string ":source (no file)"]:187: in function 'Form'
        [string ":source (no file)"]:202: in main chunk
Press ENTER or type command to continue

But that seems to be based in certain combinations I didn't figure out yet, because that error was also thrown with this piece of code:

  local llayout = Layout(
    {
      position = "50%",
      size = {
        width = 80,
        height = 40,
      },
    },
    Layout.Box({
      Layout.Box(layout.input, { size = 1 }),
      Layout.Box(layout.popup, { grow = 1 }),
      Layout.Box(layout.help, { size = "10%" }),
    }, { dir = "col" })
  )

So, changing the first input size to be "%5" or 1 both throws the height error.

Yes, that's expected. You should take care of it when you set the sizes in percentage.

And that is perfectly reasonable, but is it documented anywhere?

Thanks for your pointers, I will keep working on getting it right. Regards

danielo515 avatar Nov 28 '22 05:11 danielo515

Can you try setting size = 3 for the input?

MunifTanjim avatar Nov 29 '22 08:11 MunifTanjim

Do you mean in the input config or in the layout box? I tried setting the input size.height and that did not change anything. However, modifying the box size to, let's say 5 this is what I get

image

As you can see, it is indeed larger, but it is still disconnected. If you want to play around, here is the full file: https://github.com/danielo515/dotfiles/blob/master/chezmoi/dot_config/lvim/exact_lua/user/form/form.lua

danielo515 avatar Nov 29 '22 09:11 danielo515

Can you try with the latest commit? https://github.com/MunifTanjim/nui.nvim/pull/231

MunifTanjim avatar Jan 03 '23 09:01 MunifTanjim