-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4603 from Textualize/hatch
hatch css
- Loading branch information
Showing
17 changed files
with
666 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# <hatch> | ||
|
||
The `<hatch>` CSS type represents a character used in the [hatch](../styles/hatch.md) rule. | ||
|
||
## Syntax | ||
|
||
| Value | Description | | ||
| ------------ | ------------------------------ | | ||
| `cross` | A diagonal crossed line. | | ||
| `horizontal` | A horizontal line. | | ||
| `left` | A left leaning diagonal line. | | ||
| `right` | A right leaning diagonal line. | | ||
| `vertical` | A vertical line. | | ||
|
||
|
||
## Examples | ||
|
||
### CSS | ||
|
||
|
||
```css | ||
.some-class { | ||
hatch: cross green; | ||
} | ||
``` | ||
|
||
### Python | ||
|
||
```py | ||
widget.styles.hatch = ("cross", "red") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.containers import Horizontal, Vertical | ||
from textual.widgets import Static | ||
|
||
HATCHES = ("cross", "horizontal", "custom", "left", "right") | ||
|
||
|
||
class HatchApp(App): | ||
CSS_PATH = "hatch.tcss" | ||
|
||
def compose(self) -> ComposeResult: | ||
with Horizontal(): | ||
for hatch in HATCHES: | ||
static = Static(classes=f"hatch {hatch}") | ||
static.border_title = hatch | ||
with Vertical(): | ||
yield static | ||
|
||
|
||
if __name__ == "__main__": | ||
app = HatchApp() | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.hatch { | ||
height: 1fr; | ||
border: solid $secondary; | ||
&.cross { | ||
hatch: cross $success; | ||
} | ||
&.horizontal { | ||
hatch: horizontal $success 80%; | ||
} | ||
&.custom { | ||
hatch: "T" $success 60%; | ||
} | ||
&.left { | ||
hatch: left $success 40%; | ||
} | ||
&.right { | ||
hatch: right $success 20%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Hatch | ||
|
||
The `hatch` style fills a widget's background with a repeating character for a pleasing textured effect. | ||
|
||
## Syntax | ||
|
||
--8<-- "docs/snippets/syntax_block_start.md" | ||
hatch: (<a href="../../css_types/hatch"><hatch></a> | CHARACTER) <a href="../../css_types/color"><color></a> [<a href="../../css_types/percentage"><percentage></a>] | ||
--8<-- "docs/snippets/syntax_block_end.md" | ||
|
||
The hatch type can be specified with a constant, or a string. For example, `cross` for cross hatch, or `"T"` for a custom character. | ||
|
||
The color can be any Textual color value. | ||
|
||
An optional percentage can be used to set the opacity. | ||
|
||
## Examples | ||
|
||
|
||
An app to show a few hatch effects. | ||
|
||
=== "Output" | ||
|
||
```{.textual path="docs/examples/styles/hatch.py"} | ||
``` | ||
|
||
=== "hatch.py" | ||
|
||
```py | ||
--8<-- "docs/examples/styles/hatch.py" | ||
``` | ||
|
||
=== "hatch.tcss" | ||
|
||
```css | ||
--8<-- "docs/examples/styles/hatch.tcss" | ||
``` | ||
|
||
|
||
## CSS | ||
|
||
```css | ||
/* Red cross hatch */ | ||
hatch: cross red; | ||
/* Right diagonals, 50% transparent green. */ | ||
hatch: right green 50%; | ||
/* T custom character in 80% blue. **/ | ||
hatch: "T" blue 80%; | ||
``` | ||
|
||
|
||
## Python | ||
|
||
```py | ||
widget.styles.hatch = ("cross", "red") | ||
widget.styles.hatch = ("right", "rgba(0,255,0,128)") | ||
widget.styles.hatch = ("T", "blue") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.