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:
Rodrigo Girão Serrão
2023-03-22 11:07:38 +00:00
committed by GitHub
parent 29692736d0
commit 2a810f8c87
24 changed files with 1370 additions and 67 deletions

View File

@@ -19,23 +19,7 @@ rule-name: <a href="../../css_types/type_one">&lt;type-one&gt;</a>;
### Values
<!--
If this rule only needs one type, include it directly:
--8<-- "docs/snippets/type_syntax/only_type.md"
-->
<!--
If this rule needs two or more types:
### &lt;first-type&gt;
--8<-- "docs/snippets/type_syntax/first_type.md"
### &lt;second-type&gt;
--8<-- "docs/snippets/type_syntax/second_type.md"
...
For enum-like styles that don't warrant a dedicated type.
-->
### Defaults
@@ -120,12 +104,12 @@ Copy the same examples as the ones shown in the CSS above.
If the programmatic way of setting the rule differs significantly from the CSS way, make note of that here.
```py
rule_name = value1
rule_name = value2
rule_name = (different_syntax_value, shown_here)
widget.styles.rule_name = value1
widget.styles.rule_name = value2
widget.styles.rule_name = (different_syntax_value, shown_here)
rule_name_variant = value3
rule_name_variant = value4
widget.styles.rule_name_variant = value3
widget.styles.rule_name_variant = value4
```
-->