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

Add title to CSS borders #1864

Closed
willmcgugan opened this issue Feb 23, 2023 · 4 comments · Fixed by #2064
Closed

Add title to CSS borders #1864

willmcgugan opened this issue Feb 23, 2023 · 4 comments · Fixed by #2064
Assignees
Labels
enhancement New feature or request Task

Comments

@willmcgugan
Copy link
Collaborator

willmcgugan commented Feb 23, 2023

We should add the ability to render a title (displayed in the top) and a subtitle (displayed in the bottom) to CSS borders. Something akin to Rich panels.

Widget should grow border_title and border_subtitle attributes, which should accept a str or Text in the setter, and return a Text in the getter.

Additionally, there should be new CSS declaration s:

border-title-align: <left, center, right>
border-subtitle-align: <left, center, right>

Note that it only makes sense to render a single line in the titles. So we need a little logic to get the first line.

If the line doesn't fit, it should be truncated with ellipsis. The Text object can do this (set no_wrap=True, and overflow="ellipsis")

See panel.py in Rich for inspiration.

@learnbyexample
Copy link
Contributor

Yeah, this would be great. In one of my projects, I apply border to a container and use Label widget to display a title before the container. Having a Panel like experience would be better.

Will there be a subtitle option as well?

@willmcgugan
Copy link
Collaborator Author

@learnbyexample Yeah, don't see why not.

@rodrigogiraoserrao rodrigogiraoserrao self-assigned this Mar 13, 2023
@rodrigogiraoserrao rodrigogiraoserrao added enhancement New feature or request Task labels Mar 13, 2023
@rodrigogiraoserrao
Copy link
Contributor

I have a couple of follow-up questions regarding the specs:

  • Suppose the border is blank, none, or hidden:
    • Do we display non-empty titles and subtitles?
    • What if the title or subtitle is empty?
    • What if the title or subtitle is None?
  • What is the text colour? The same as the corresponding border edge or the text colour of the widget?

rodrigogiraoserrao added a commit that referenced this issue Mar 14, 2023
willmcgugan added a commit that referenced this issue Mar 22, 2023
* Add Widget.border_title and border_subtitle.

Related issues: #1864

* Test setting border_(sub)title.

* Add border (sub)title references to StylesCache.

These internal references will make it easier for the instance of 'StylesCache' to know which border (sub)title to use, if/when needed.

* Add method to render border label.

* Add styles to align border (sub)title.

* Render border labels.

* Update styles template.

* Make new 'render_row' parameters optional.

* Add (sub)title border snapshot tests.

* Document border (sub)title and styles.

* Pass (sub)title directly as arguments.

Get rid of the watchers to make data flow easier to follow.
Related comment: https://github.com/Textualize/textual/pull/2064/files\#r1137746697

* Tweak example.

* Fix render_border_label.

This was wrong because border labels can be composed of multiple segments if they contain multiple styles. Additionally, we want to render a single blank space of padding around the title.

* Ensure we get no label when there's no space.

* Add tests for border label rendering.

* 'render_border_label' now returns iterable of segments.

* Add label to render_row.

* Fix calling signature in tests.

* Add padding to snapshot tests.

* Fix changelog.

* Update snapshot tests.

* Update snapshot tests.

* Border labels expand if there's no corners.

* Update CHANGELOG.md

* Fix docs.

* Remove irrelevant line.

* Fix snapshot tests.

* Don't share Console among tests.

* Simplify example in styles guide.

* Avoid expensive function call when possible.

* rewording

* positive branch first

* remove wasteful indirection

* fix changelog

---------

Co-authored-by: Will McGugan <[email protected]>
@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants