Skip to content

Can I make long forms or nested layouts that are scrollable? #1065

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

Closed
andy0130tw opened this issue Jan 28, 2020 · 5 comments
Closed

Can I make long forms or nested layouts that are scrollable? #1065

andy0130tw opened this issue Jan 28, 2020 · 5 comments

Comments

@andy0130tw
Copy link

andy0130tw commented Jan 28, 2020

When building applications that prompt rich forms, we may need the capability that we could scroll some long contents, optionally with viewport following the cursor. An example that implements this concept is nmtui.

long form in nmtui

If a widget is simple, one approach is to (ab)use FormattedTextControl inside a window, typesetting (?) the content of each block and arrange cursor positions. This idea works well with smaller components, and is already seen in widgets like CheckboxList, #711 for editable buffers, and the option list of pyvim (this is especially brilliant, in my oponion).

When building some complex blocks to compose them, the logic to maintain contents/positions for a long block would be a nightmare. For an instance of what I mean complex, see cslack, in urwid.

complex form

It is straightforward to mock a view using HSplit and VSplit, however they seem to divide the screen and cannot be placed inside a window. I have seen a similar feature request in #949 and surveyed some showcases, but still have no idea on how to achieve this. Maybe I should start by inheriting UIContent. Is there some development docs that I can refer to create such a component?

@jonathanslenders
Copy link
Member

Hi @andy0130tw,

This is indeed a feature request that's been asked a couple of times before, and I haven't come around implementing it. At the moment it is not possible.

It should be doable, but not really easy either. If I have some time, I'll try to write down the steps to implement it.

I'm not entirely sure, but maybe it is possible to implement with Urwid.

@andy0130tw
Copy link
Author

@jonathanslenders Thanks for the quick response! I am new to TUI applications, and feel this toolkit is really handy from simple prompts to full-featured text editors. I really appreciate it.

Comparing from Urwid, my understanding is the design goal, and therefore, the strategy, is different. Urwid's manual deals with layouts a lot but lacks of default behaviors that glues the components together. Anyway, I really look forward to this feature gets implemented in this toolkit.

@lyz-code
Copy link

@andy0130tw Did you manage to get this working, or do you have any further tips on how to achieve it?

@jonathanslenders
Copy link
Member

Actually, this was implemented some time ago, using prompt_toolkit.layout.ScrollablePane. I forgot to mention it here.

See these examples: https://github.com/prompt-toolkit/python-prompt-toolkit/tree/master/examples/full-screen/scrollable-panes

Hope that works!

@andy0130tw
Copy link
Author

Wow, thanks. I have not actively used this package since then. Glad to see this feature implemented in this powerful toolkit!

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

No branches or pull requests

3 participants