Skip to content

Commit

Permalink
Add Widget.border_title and border_subtitle.
Browse files Browse the repository at this point in the history
Related issues: #1864
  • Loading branch information
rodrigogiraoserrao committed Mar 14, 2023
1 parent 85cce4a commit 51b9cd8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## Unreleased

### Added

- Added `Widget.border_title` and `Widget.border_subtitle` to set border (sub)title for a widget https://github.com/Textualize/textual/issues/1864


## [0.15.1] - 2023-03-14

### Fixed
Expand Down
18 changes: 18 additions & 0 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ class Widget(DOMNode):
"""Widget will highlight links automatically."""
disabled = Reactive(False)
"""The disabled state of the widget. `True` if disabled, `False` if not."""
border_title = Reactive("")
"""The one-line border title, which may contain markup to be parsed."""
border_subtitle = Reactive("")
"""The one-line border subtitle, which may contain markup to be parsed."""

hover_style: Reactive[Style] = Reactive(Style, repaint=False)
highlight_link_id: Reactive[str] = Reactive("")
Expand Down Expand Up @@ -2353,6 +2357,20 @@ def watch_disabled(self) -> None:
"""Update the styles of the widget and its children when disabled is toggled."""
self._update_styles()

def validate_border_title(self, title: str) -> str:
"""Ensure we only use a single line for the border title."""
if not title:
return title
first, *_ = title.splitlines()
return first

def validate_border_subtitle(self, subtitle: str) -> str:
"""Ensure we only use a single line for the border subtitle."""
if not subtitle:
return subtitle
first, *_ = subtitle.splitlines()
return first

def _size_updated(
self, size: Size, virtual_size: Size, container_size: Size, layout: bool = True
) -> bool:
Expand Down

0 comments on commit 51b9cd8

Please sign in to comment.