-
Notifications
You must be signed in to change notification settings - Fork 795
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 #5278 from Textualize/demo-tweaks
Add position:absolute and game to demo
- Loading branch information
Showing
30 changed files
with
1,194 additions
and
36 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 @@ | ||
# <position> | ||
|
||
The `<position>` CSS type defines how the the `offset` rule is applied.. | ||
|
||
|
||
## Syntax | ||
|
||
A [`<position>`](./position.md) may be any of the following values: | ||
|
||
| Value | Alignment type | | ||
| ---------- | ------------------------------------------------------------ | | ||
| `relative` | Offset is applied to widgets default position. | | ||
| `absolute` | Offset is applied to the origin (top left) of its container. | | ||
|
||
## Examples | ||
|
||
### CSS | ||
|
||
```css | ||
Label { | ||
position: absolute; | ||
offset: 10 5; | ||
} | ||
``` | ||
|
||
### Python | ||
|
||
```py | ||
widget.styles.position = "absolute" | ||
widget.styles.offset = (10, 5) | ||
``` |
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,15 @@ | ||
from textual.app import App, ComposeResult | ||
from textual.widgets import Label | ||
|
||
|
||
class PositionApp(App): | ||
CSS_PATH = "position.tcss" | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Label("Absolute", id="label1") | ||
yield Label("Relative", id="label2") | ||
|
||
|
||
if __name__ == "__main__": | ||
app = PositionApp() | ||
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 @@ | ||
Screen { | ||
align: center middle; | ||
} | ||
|
||
Label { | ||
padding: 1; | ||
background: $panel; | ||
border: thick $border; | ||
} | ||
|
||
Label#label1 { | ||
position: absolute; | ||
offset: 2 1; | ||
} | ||
|
||
Label#label2 { | ||
position: relative; | ||
offset: 2 1; | ||
} |
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,61 @@ | ||
|
||
# Position | ||
|
||
The `position` style modifies what [`offset`](./offset.md) is applied to. | ||
The default for `position` is `"relative"`, which means the offset is applied to the normal position of the widget. | ||
In other words, if `offset` is (1, 1), then the widget will be moved 1 cell and 1 line down from its usual position. | ||
|
||
The alternative value of `position` is `"absolute"`. | ||
With absolute positioning, the offset is relative to the origin (i.e. the top left of the container). | ||
So a widget with offset (1, 1) and absolute positioning will be 1 cell and 1 line down from the top left corner. | ||
|
||
!!! note | ||
|
||
Absolute positioning takes precedence over the parent's alignment rule. | ||
|
||
## Syntax | ||
|
||
--8<-- "docs/snippets/syntax_block_start.md" | ||
position: <a href="../../css_types/position"><position></a>; | ||
--8<-- "docs/snippets/syntax_block_end.md" | ||
|
||
|
||
## Examples | ||
|
||
|
||
Two labels, the first is absolute positioned and is displayed relative to the top left of the screen. | ||
The second label is relative and is displayed offset from the center. | ||
|
||
=== "Output" | ||
|
||
```{.textual path="docs/examples/styles/position.py"} | ||
``` | ||
|
||
=== "position.py" | ||
|
||
```py | ||
--8<-- "docs/examples/styles/position.py" | ||
``` | ||
|
||
=== "position.tcss" | ||
|
||
```css | ||
--8<-- "docs/examples/styles/position.tcss" | ||
``` | ||
|
||
|
||
|
||
|
||
## CSS | ||
|
||
```css | ||
position: relative; | ||
position: absolute; | ||
``` | ||
|
||
## Python | ||
|
||
```py | ||
widget.styles.position = "relative" | ||
widget.styles.position = "absolute" | ||
``` |
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
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.