Layout - discussion #1015
Replies: 2 comments 1 reply
-
Hi Federico, It's nice to have someone take an interest in the API! I changed the split method recently. Previously it was exactly like your last example. The reason I didn't like that is that the first call to I changed it so that split would accept multiple layout instances. I think you may have missed this from looking at the code, but that's the reason why it doesn't return anything - because there may be multiple layouts. So to compare old api with new api: layout.split(name='head', ratio=2, size=6)
layout.split(name='body', ratio=5, direction='horizontal')
layout.split(ratio=1, size=4).update(self.footer()) layout.split(
Layout(name="head", ratio=2, size=6),
Layout(name="body", ratio=5, direction="horizontal),
Layout(self.footer(), ratio=1, size=4)
) Granted, the second is a little more verbose. But I think it more explicitly indicates how things are nested. That may be a personal preference, but it also has a more objective benefit in that it makes it possible to extend it with other Layout classes. There could be a BTW the name index on Layout objects works recursively. So With that in mind, your code becomes something like this: layout.split(
Layout(name='head', ratio=2, size=6),
Layout(name='body', ratio=5, direction='horizontal'),
Layout(self.footer(), ratio=1, size=4)
)
# make header
title_panel, info_panel = self.make_header()
layout['head'].split(
Layout(title_panel, direction='horizontal'),
Layout(info_panel, direction='horizontal')
)
# make body
layout['br'].update(
Panel(Trajectory(), border_style=salmon, box=box.SIMPLE, title='trajectory')
)
layout['br'].split(
Layout(
Panel(self.make_logger(), style=indigo, title="LOG")
ratio=2
)
)
layout['bl'].split(
Layout(
Panel(
variables, style=orange, padding=(1, 3), title="Variables"
)
),
Layout(
Panel(state, style=green, title="Physics"),
ratio=2
),
Layout(
Panel(StackInfo(), title="Call stack", box=box.SIMPLE_HEAD)
)
) More verbose, but I think easier to scan. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
I think I messed up something in the way I've been getting the latest version of the layout code. I originally had a version which used this latest syntax, but then when I forked I will try again with the latest code and report back. By the way, if at any point I'm overstepping with suggesting changes or comments on the API please do let me know, I just really enjoy using rich and as a (non-professional) developer I always feel like I don't get enough feedback about my projects, so I try to give some where I can. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Will,
I'm loving the new
Layout
functionality, thought I'd drop a couple items for discussion.layout.split()
with no renderable.Currently if you are splitting layouts to create your structure, you will do something like:
The inner call to layout feels a bit cumbersome: if you are splitting a layout and not passing a renderable it could infer that it needs to spawn a new layout (and pass any
**kwargs
to it), thus making the sintax a bit simpler.layout.split
could return a copy of the new layoutCurrently the syntax looks like this:
but if
split
returned a pointer to the new layout, you could get:It's two small changes, but I feel like together they would make the code more concise and cleaner.
In an application of mine I'd go from:
to
(Note that the fact that you can do
layout.split().update()
means you can also avoid having to specify a name for leaf nodes.Beta Was this translation helpful? Give feedback.
All reactions