mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Implement border (sub)title. (#2064)
* 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 <willmcgugan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
29692736d0
commit
2a810f8c87
@@ -257,6 +257,28 @@ There are many other border types. Run the following from the command prompt to
|
||||
textual borders
|
||||
```
|
||||
|
||||
|
||||
#### Title alignment
|
||||
|
||||
Widgets have two attributes, `border_title` and `border_subtitle` which (if set) will be displayed within the border.
|
||||
The `border_title` attribute is displayed in the top border, and `border_subtitle` is displayed in the bottom border.
|
||||
|
||||
There are two styles to set the alignment of these border labels, which may be set to "left", "right", or "center".
|
||||
|
||||
- [`border-title-align`](../styles/border_title_align.md) sets the alignment of the title, which defaults to "left".
|
||||
- [`border-subtitle-align`](../styles/border_subtitle_align.md) sets the alignment of the subtitle, which defaults to "right".
|
||||
|
||||
The following example sets both titles and changes the alignment of the title (top) to "center".
|
||||
|
||||
```py hl_lines="22-24"
|
||||
--8<-- "docs/examples/guide/styles/border_title.py"
|
||||
```
|
||||
|
||||
Note the addition of the titles and their alignments:
|
||||
|
||||
```{.textual path="docs/examples/guide/styles/border_title.py"}
|
||||
```
|
||||
|
||||
### Outline
|
||||
|
||||
[Outline](../styles/outline.md) is similar to border and is set in the same way. The difference is that outline will not change the size of the widget, and may overlap the content area. The following example sets an outline on a widget:
|
||||
|
||||
Reference in New Issue
Block a user