From 3b155216f0bb167de47bc0b4e5cd6ee0224c60ec Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 26 Aug 2022 14:51:27 +0100 Subject: [PATCH] Docs for text-justify --- docs/examples/styles/text_justify.css | 24 +++++++++++++++++++++++ docs/examples/styles/text_justify.py | 28 +++++++++++++++++++++++++++ docs/styles/scrollbar.md | 2 +- docs/styles/text_justify.md | 21 ++++++++++++++++++-- mkdocs.yml | 11 ++++++----- sandbox/darren/text_justify.py | 28 +++++++++++---------------- sandbox/darren/text_justify.scss | 24 +++++++++++++++++++++++ src/textual/geometry.py | 2 +- src/textual/message_pump.py | 2 +- src/textual/widget.py | 3 --- 10 files changed, 115 insertions(+), 30 deletions(-) create mode 100644 docs/examples/styles/text_justify.css create mode 100644 docs/examples/styles/text_justify.py diff --git a/docs/examples/styles/text_justify.css b/docs/examples/styles/text_justify.css new file mode 100644 index 000000000..589f7bfd6 --- /dev/null +++ b/docs/examples/styles/text_justify.css @@ -0,0 +1,24 @@ +#one { + text-justify: left; + background: lightblue; + +} + +#two { + text-justify: center; + background: indianred; +} + +#three { + text-justify: right; + background: palegreen; +} + +#four { + text-justify: full; + background: palevioletred; +} + +Static { + padding: 1; +} diff --git a/docs/examples/styles/text_justify.py b/docs/examples/styles/text_justify.py new file mode 100644 index 000000000..cc86529f8 --- /dev/null +++ b/docs/examples/styles/text_justify.py @@ -0,0 +1,28 @@ +from __future__ import annotations + +from textual.app import App, ComposeResult +from textual.widgets import Static + +TEXT = ( + "I must not fear. Fear is the mind-killer. Fear is the little-death that " + "brings total obliteration. I will face my fear. I will permit it to pass over " + "me and through me." +) + + +class TextJustify(App): + def compose(self) -> ComposeResult: + left = Static("[b]Left justified[/]\n" + TEXT, id="one") + yield left + + right = Static("[b]Center justified[/]\n" + TEXT, id="two") + yield right + + center = Static("[b]Right justified[/]\n" + TEXT, id="three") + yield center + + full = Static("[b]Full justified[/]\n" + TEXT, id="four") + yield full + + +app = TextJustify(css_path="text_justify.css") diff --git a/docs/styles/scrollbar.md b/docs/styles/scrollbar.md index 57b4346d7..85003779d 100644 --- a/docs/styles/scrollbar.md +++ b/docs/styles/scrollbar.md @@ -12,7 +12,7 @@ There are a number of rules to set the colors used in Textual scrollbars. You wo | `scrollbar-background-active` | Scrollbar background when the thumb is being dragged | | `scrollbar-corner-color` | The gap between the horizontal and vertical scrollbars | -## Example: +## Syntax ``` scrollbar-color: ; diff --git a/docs/styles/text_justify.md b/docs/styles/text_justify.md index b0cfcdf25..ab829a75f 100644 --- a/docs/styles/text_justify.md +++ b/docs/styles/text_justify.md @@ -2,6 +2,8 @@ The `text-justify` rule justifies text within a widget. +This property is not the same as the `text-justify` property in browser CSS. + ## Syntax ``` @@ -19,8 +21,7 @@ text-justify: [left|center|right|full]; ## Example -In this example, we can see, from top to bottom, - `left`, `center`, `right`, and `full` justified text respectively. +This example shows, from top to bottom: `left`, `center`, `right`, and `full` justified text. === "text_justify.py" @@ -38,3 +39,19 @@ In this example, we can see, from top to bottom, ```{.textual path="docs/examples/styles/text_justify.py"} ``` + +## CSS + +```sass +/* Set text in all Widgets to be right justified */ +Widget { + text-justify: right; +} +``` + +## Python + +```python +# Set text in the widget to be right justified +widget.styles.text_justify = "right" +``` diff --git a/mkdocs.yml b/mkdocs.yml index 5d17dd154..5735b0ab5 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -6,10 +6,10 @@ nav: - "getting_started.md" - "introduction.md" - Guide: - - "guide/devtools.md" + - "guide/devtools.md" - "guide/CSS.md" - "guide/events.md" - + - "actions.md" - Events: - "events/blur.md" @@ -35,7 +35,7 @@ nav: - "events/resize.md" - "events/screen_resume.md" - "events/screen_suspend.md" - - "events/show.md" + - "events/show.md" - Styles: - "styles/background.md" - "styles/border.md" @@ -53,9 +53,10 @@ nav: - "styles/outline.md" - "styles/overflow.md" - "styles/padding.md" + - "styles/scrollbar.md" - "styles/scrollbar_gutter.md" - "styles/scrollbar_size.md" - - "styles/scrollbar.md" + - "styles/text_justify.md" - "styles/text_style.md" - "styles/tint.md" - "styles/visibility.md" @@ -81,7 +82,7 @@ markdown_extensions: - admonition - def_list - meta - + - toc: permalink: true baselevel: 1 diff --git a/sandbox/darren/text_justify.py b/sandbox/darren/text_justify.py index e76c4ab0e..74f8afdfe 100644 --- a/sandbox/darren/text_justify.py +++ b/sandbox/darren/text_justify.py @@ -1,35 +1,29 @@ from __future__ import annotations -from rich.text import Text - from textual.app import App, ComposeResult from textual.widgets import Static -TEXT = """I must not fear. -Fear is the mind-killer. -Fear is the little-death that brings total obliteration. -I will face my fear. -I will permit it to pass over me and through me. -And when it has gone past, I will turn the inner eye to see its path. -Where the fear has gone there will be nothing. Only I will remain.""" +TEXT = ( + "I must not fear. Fear is the mind-killer. Fear is the little-death that " + "brings total obliteration. I will face my fear. I will permit it to pass over " + "me and through me. And when it has gone past, I will turn the inner eye to " + "see its path. Where the fear has gone there will be nothing. Only I will " + "remain. " +) class TextJustify(App): def compose(self) -> ComposeResult: - left = Static(Text(TEXT)) - left.styles.text_justify = "left" + left = Static("[b]Left justified[/]\n" + TEXT, id="one") yield left - right = Static(TEXT) - right.styles.text_justify = "right" + right = Static("[b]Center justified[/]\n" + TEXT, id="two") yield right - center = Static(TEXT) - center.styles.text_justify = "center" + center = Static("[b]Right justified[/]\n" + TEXT, id="three") yield center - full = Static(TEXT) - full.styles.text_justify = "full" + full = Static("[b]Full justified[/]\n" + TEXT, id="four") yield full diff --git a/sandbox/darren/text_justify.scss b/sandbox/darren/text_justify.scss index e69de29bb..589f7bfd6 100644 --- a/sandbox/darren/text_justify.scss +++ b/sandbox/darren/text_justify.scss @@ -0,0 +1,24 @@ +#one { + text-justify: left; + background: lightblue; + +} + +#two { + text-justify: center; + background: indianred; +} + +#three { + text-justify: right; + background: palegreen; +} + +#four { + text-justify: full; + background: palevioletred; +} + +Static { + padding: 1; +} diff --git a/src/textual/geometry.py b/src/textual/geometry.py index 537932cfc..3dfd634c6 100644 --- a/src/textual/geometry.py +++ b/src/textual/geometry.py @@ -619,7 +619,7 @@ class Region(NamedTuple): """Move the offset of the Region. Args: - translate (tuple[int, int]): Offset to add to region. + offset (tuple[int, int]): Offset to add to region. Returns: Region: A new region shifted by (x, y) diff --git a/src/textual/message_pump.py b/src/textual/message_pump.py index 7f8d0bb91..e7eeb4c18 100644 --- a/src/textual/message_pump.py +++ b/src/textual/message_pump.py @@ -242,7 +242,7 @@ class MessagePump(metaclass=MessagePumpMeta): name: str | None = None, repeat: int = 0, pause: bool = False, - ): + ) -> Timer: """Call a function at periodic intervals. Args: diff --git a/src/textual/widget.py b/src/textual/widget.py index 806f89cf1..d1c31761f 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -1382,9 +1382,6 @@ class Widget(DOMNode): def render(self) -> RenderableType: """Get renderable for widget. - Args: - style (Styles): The Styles object for this Widget. - Returns: RenderableType: Any renderable """