peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.64k stars 238 forks source link

Centered Label on Top of Widgets #233

Closed akennedy4155 closed 4 years ago

akennedy4155 commented 5 years ago

I saw that Labels are placed by default to the left of a Widget. I found this when making a ListBox with a label.

I'd like an option to have a label placed centered and on top of the widget rather than on the left.

I thought about making this custom to the ListBox subclass that I am creating as part of my project, but inspecting the code makes this seem like something that happens at the level of a Widget and the way that Layout interacts with the Widget's offset.

I'm happy to work on this and submit a PR if you identify that this is something that would be useful to the code-base.

My work would be an option for a widget to either have the label as it is now, or on top of the widget. I think this would involve making a vertical offset property and some logic within the Layout to adjust how the Widget is displayed.

If something like this already exists, let me know. Otherwise, if you think it would be valuable I can work on it and submit a PR with some tests.

peterbrittain commented 5 years ago

Thanks for the offer. Contributions are always welcome!

There may be a simpler solution for you here... Have you considered just using the separate Label widget for your use case? You can add this widget before your ListBox in the Layout column and then you"ll have what you want (including the centre alignment).

peterbrittain commented 5 years ago

Did that suggestion work for you? If so, I think the existing function is right and we just need to explain the usage.

akennedy4155 commented 5 years ago

Sorry for the late response. This worked for me, and was a good solution that I didn't think of. Thanks for taking the time to help out!

peterbrittain commented 5 years ago

No problem. Glad I could help. Will keep this open until docs have been updated...