Skip to content

Commit

Permalink
Merge branch 'main' into allow-maximize
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan authored Oct 7, 2024
2 parents cc1a451 + 1e208b4 commit 459efab
Show file tree
Hide file tree
Showing 10 changed files with 382 additions and 259 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased


### Changed

- `Screen.ALLOW_IN_MAXIMIZED_VIEW` will now default to `App.ALLOW_IN_MAXIMIZED_VIEW` https://github.com/Textualize/textual/pull/5088
- Widgets matching `.-textual-system` will now be included in the maximize view by default https://github.com/Textualize/textual/pull/5088
- Digits are now thin by default, style with text-style: bold to get bold digits https://github.com/Textualize/textual/pull/5094

### Added

- Added support for A-F to Digits widget https://github.com/Textualize/textual/pull/5094

## [0.82.0] - 2024-10-03

Expand Down
21 changes: 21 additions & 0 deletions docs/blog/images/compositor/cuts.excalidraw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/widgets/digits.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A widget to display numerical values in tall multi-line characters.

The digits 0-9 are supported, in addition to the following characters `+`, `-`, `^`, `:`, and `×`.
The digits 0-9 and characters A-F are supported, in addition to `+`, `-`, `^`, `:`, and `×`.
Other characters will be displayed in a regular size font.

You can set the text to be displayed in the constructor, or call [`update()`][textual.widgets.Digits.update] to change the text after the widget has been mounted.
Expand Down
105 changes: 100 additions & 5 deletions src/textual/renderables/digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from rich.segment import Segment
from rich.style import Style, StyleType

DIGITS = " 0123456789+-^x:"
DIGITS3X3 = """\
DIGITS = " 0123456789+-^x:ABCDEF"
DIGITS3X3_BOLD = """\
Expand Down Expand Up @@ -55,6 +55,96 @@
:
╭─╮
├─┤
╵ ╵
┌─╮
├─┤
└─╯
╭─╮
╰─╯
┌─╮
│ │
└─╯
╭─╴
├─
╰─╴
╭─╴
├─
""".splitlines()


DIGITS3X3 = """\
╭─╮
│ │
╰─╯
╶╮
╶┴╴
╶─╮
┌─┘
╰─╴
╶─╮
─┤
╶─╯
╷ ╷
╰─┤
╭─╴
╰─╮
╶─╯
╭─╴
├─╮
╰─╯
╶─┐
╭─╮
├─┤
╰─╯
╭─╮
╰─┤
╶─╯
╶┼╴
╶─╴
^
×
:
╭─╮
├─┤
╵ ╵
┌─╮
├─┤
└─╯
╭─╮
╰─╯
┌─╮
│ │
└─╯
╭─╴
├─
╰─╴
╭─╴
├─
""".splitlines()


Expand Down Expand Up @@ -91,6 +181,11 @@ def render(self, style: Style) -> RenderResult:
row2 = digit_pieces[1].append
row3 = digit_pieces[2].append

if style.bold:
digits = DIGITS3X3_BOLD
else:
digits = DIGITS3X3

for character in self._text:
try:
position = DIGITS.index(character) * 3
Expand All @@ -99,9 +194,9 @@ def render(self, style: Style) -> RenderResult:
row2(" ")
row3(character)
else:
row1(DIGITS3X3[position].ljust(3))
row2(DIGITS3X3[position + 1].ljust(3))
row3(DIGITS3X3[position + 2].ljust(3))
row1(digits[position].ljust(3))
row2(digits[position + 1].ljust(3))
row3(digits[position + 2].ljust(3))

new_line = Segment.line()
for line in digit_pieces:
Expand Down
3 changes: 1 addition & 2 deletions src/textual/widgets/_digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class Digits(Widget):
Digits {
width: 1fr;
height: auto;
text-align: left;
text-style: bold;
text-align: left;
box-sizing: border-box;
}
"""
Expand Down
110 changes: 55 additions & 55 deletions tests/snapshot_tests/__snapshots__/test_snapshots/test_digits.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 57 additions & 58 deletions tests/snapshot_tests/__snapshots__/test_snapshots/test_recompose.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions tests/snapshot_tests/snapshot_apps/digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@

class DigitApp(App):
CSS = """
#digits1 {
.left {
text-align: left;
}
#digits2 {
.center {
text-align:center;
}
#digits3 {
.right {
text-align:right;
}
.bold {
text-style: bold;
}
"""

def compose(self) -> ComposeResult:
yield Digits("3.1427", id="digits1")
yield Digits(" 0123456789+-.,", id="digits2")
yield Digits("3x10^4", id="digits3")
yield Digits("3.1427", classes="left")
yield Digits(" 0123456789+-.,ABCDEF", classes="center")
yield Digits(" 0123456789+-.,ABCDEF", classes="center bold")
yield Digits("3x10^4", classes="right")


if __name__ == "__main__":
Expand Down

0 comments on commit 459efab

Please sign in to comment.