Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to layout docs #212

Open
danielo515 opened this issue Nov 27, 2022 · 8 comments
Open

Improvements to layout docs #212

danielo515 opened this issue Nov 27, 2022 · 8 comments

Comments

@danielo515
Copy link

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

@MunifTanjim
Copy link
Owner

MunifTanjim commented Nov 27, 2022

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:

local Input = Popup:extend("NuiInput")

But the height is fixed to 1:

popup_options.size.height = 1

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
Copy link
Owner

MunifTanjim commented Nov 27, 2022

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'

@danielo515
Copy link
Author

That wiki doesn’t seem to exists

@MunifTanjim
Copy link
Owner

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.

@danielo515
Copy link
Author

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

@MunifTanjim
Copy link
Owner

Can you try setting size = 3 for the input?

@danielo515
Copy link
Author

danielo515 commented Nov 29, 2022

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

@MunifTanjim
Copy link
Owner

MunifTanjim commented Jan 3, 2023

Can you try with the latest commit? #231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants