Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document CSS Styles #629

Merged
merged 32 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7ba36c1
docs
willmcgugan Jul 30, 2022
7040d00
more docs
willmcgugan Jul 30, 2022
99ccbc5
moar docs
willmcgugan Jul 30, 2022
0fe4b97
more docs
willmcgugan Jul 31, 2022
3f0f9ee
tint style
willmcgugan Jul 31, 2022
8b5b410
added tint and offset
willmcgugan Jul 31, 2022
7dc8dab
Merge branch 'layer-dock' into docs
willmcgugan Jul 31, 2022
a174557
added borders utility
willmcgugan Jul 31, 2022
62db35f
add borders command
willmcgugan Jul 31, 2022
ae9862c
borders tweak
willmcgugan Jul 31, 2022
fa4b971
more docs
willmcgugan Aug 4, 2022
971ef9e
more border
willmcgugan Aug 4, 2022
5ff9b5e
Merge branch 'css' into docs
willmcgugan Aug 4, 2022
ca1ec68
text style docs
willmcgugan Aug 4, 2022
a9c475c
words and tables
willmcgugan Aug 4, 2022
676c8ae
words and tables
willmcgugan Aug 4, 2022
3960366
words
willmcgugan Aug 4, 2022
cbd0a6e
Update docs/examples/styles/background.py
willmcgugan Aug 5, 2022
b388a13
Update docs/examples/styles/border.py
willmcgugan Aug 5, 2022
7e985b6
Update docs/examples/styles/box_sizing.py
willmcgugan Aug 5, 2022
b4aa7ec
Update docs/examples/styles/display.py
willmcgugan Aug 5, 2022
38047e4
Update docs/examples/styles/offset.py
willmcgugan Aug 5, 2022
6602cd7
Update docs/styles/visibility.md
willmcgugan Aug 5, 2022
33dc6ac
Update docs/styles/color.md
willmcgugan Aug 5, 2022
331cbc6
Update docs/examples/styles/visibility.py
willmcgugan Aug 5, 2022
fa61ca0
Update docs/introduction.md
willmcgugan Aug 5, 2022
3976698
Update docs/introduction.md
willmcgugan Aug 5, 2022
078fc24
Update docs/styles/background.md
willmcgugan Aug 5, 2022
cb0537e
Update docs/styles/background.md
willmcgugan Aug 5, 2022
7fd3fe5
Update docs/styles/border.md
willmcgugan Aug 5, 2022
ce5e36e
Update docs/styles/box_sizing.md
willmcgugan Aug 5, 2022
8697312
Update docs/examples/styles/color.py
willmcgugan Aug 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/events/mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

The `Mount` event is sent to a widget and Application when it is first mounted.

The mount event is typically used to set the initial state of a widget or to add new children widgets.

- [ ] Bubbles

## Parameters
Expand Down
4 changes: 4 additions & 0 deletions docs/events/resize.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ The `Resize` event is sent to a widget when its size changes and when it is firs
`event.container_size`

: The size of the widget's container.

## Code

::: textual.events.Mount
1 change: 1 addition & 0 deletions docs/examples/light_dark.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ def compose(self):

def handle_pressed(self, event):
self.dark = not self.dark
self.bell()
event.button.label = "Lights ON" if self.dark else "Lights OFF"
9 changes: 9 additions & 0 deletions docs/examples/styles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
These are the examples from the documentation, used to generate screenshots.

You can run them with the textual CLI.

For example:

```
textual run text_style.py
```
29 changes: 29 additions & 0 deletions docs/examples/styles/background.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from textual.app import App
from textual.widgets import Static


class BackgroundApp(App):
CSS = """
Static {
height: 1fr;
content-align: center middle;
color: white;
}
#static1 {
background: red;
}
#static2 {
background: rgb(0, 255, 0);
}
#static3 {
background: hsl(240, 100%, 50%);
}
"""

def compose(self):
yield Static("Hello, World!", id="static1")
yield Static("Hello, World!", id="static2")
yield Static("Hello, World!", id="static3")
willmcgugan marked this conversation as resolved.
Show resolved Hide resolved


app = BackgroundApp()
40 changes: 40 additions & 0 deletions docs/examples/styles/border.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from textual.app import App
from textual.widgets import Static


class BorderApp(App):
CSS = """
Screen {
background: white;
}
Screen > Static {
height: 5;
content-align: center middle;
color: white;
margin: 1;
box-sizing: border-box;
}
#static1 {
background: red 20%;
color: red;
border: solid red;
}
#static2 {
background: green 20%;
color: green;
border: dashed green;
}
#static3 {
background: blue 20%;
color: blue;
border: tall blue;
}
"""

def compose(self):
yield Static("Hello, World!", id="static1")
yield Static("Hello, World!", id="static2")
yield Static("Hello, World!", id="static3")
willmcgugan marked this conversation as resolved.
Show resolved Hide resolved


app = BorderApp()
32 changes: 32 additions & 0 deletions docs/examples/styles/box_sizing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from textual.app import App
from textual.widgets import Static


class BoxSizingApp(App):
CSS = """
Screen {
background: white;
color: black;
}
Static {
background: blue 20%;
height: 5;
margin: 2;
padding: 1;
border: wide black;
}
#static1 {
box-sizing: border-box;
}
#static2 {
box-sizing: content-box;
}

"""

def compose(self):
yield Static("Hello, World!", id="static1")
yield Static("Hello, World!", id="static2")
willmcgugan marked this conversation as resolved.
Show resolved Hide resolved


app = BoxSizingApp()
28 changes: 28 additions & 0 deletions docs/examples/styles/color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from textual.app import App
from textual.widgets import Static


class ColorApp(App):
CSS = """
Static {
height:1fr;
content-align: center middle;
}
#static1 {
color: red;
}
#static2 {
color: rgb(0, 255, 0);
}
#static3 {
color: hsl(240, 100%, 50%)
}
"""

def compose(self):
yield Static("Hello, World!", id="static1")
yield Static("Hello, World!", id="static2")
yield Static("Hello, World!", id="static3")
willmcgugan marked this conversation as resolved.
Show resolved Hide resolved


app = ColorApp()
27 changes: 27 additions & 0 deletions docs/examples/styles/display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from textual.app import App
from textual.widgets import Static


class DisplayApp(App):
CSS = """
Screen {
background: green;
}
Static {
height: 5;
background: white;
color: blue;
border: heavy blue;
}
Static.remove {
display: none;
}
"""

def compose(self):
yield Static("Widget 1")
yield Static("widget 2", classes="remove")
yield Static("widget 3")
willmcgugan marked this conversation as resolved.
Show resolved Hide resolved


app = DisplayApp()
18 changes: 18 additions & 0 deletions docs/examples/styles/height.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from textual.app import App
from textual.widget import Widget


class HeightApp(App):
CSS = """
Screen > Widget {
background: green;
height: 50%;
color: white;
}
"""

def compose(self):
yield Widget()


app = HeightApp()
33 changes: 33 additions & 0 deletions docs/examples/styles/margin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from textual.app import App
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."""


class MarginApp(App):
CSS = """

Screen {
background: white;
color: black;
}

Static {
margin: 4 8;
background: blue 20%;
border: blue wide;
}

"""

def compose(self):
yield Static(TEXT)


app = MarginApp()
46 changes: 46 additions & 0 deletions docs/examples/styles/offset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from textual.app import App
from textual.widgets import Static


class OffsetApp(App):
CSS = """
Screen {
background: white;
color: black;
layout: horizontal;
}
Static {
width: 20;
height: 10;
content-align: center middle;
}

.paul {
offset: 8 2;
background: red 20%;
border: outer red;
color: red;
}

.duncan {
offset: 4 10;
background: green 20%;
border: outer green;
color: green;
}

.chani {
offset: 0 5;
background: blue 20%;
border: outer blue;
color: blue;
}
"""

def compose(self):
yield Static("Paul", classes="paul")
yield Static("Duncan", classes="duncan")
yield Static("Chani", classes="chani")
willmcgugan marked this conversation as resolved.
Show resolved Hide resolved


app = OffsetApp()
31 changes: 31 additions & 0 deletions docs/examples/styles/outline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from textual.app import App
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."""


class OutlineApp(App):
CSS = """
Screen {
background: white;
color: black;
}
Static {
margin: 4 8;
background: green 20%;
outline: wide green;
}
"""

def compose(self):
yield Static(TEXT)


app = OutlineApp()
44 changes: 44 additions & 0 deletions docs/examples/styles/overflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from textual.app import App
from textual.widgets import Static
from textual.layout import Horizontal, Vertical

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 OverflowApp(App):
CSS = """
Screen {
background: $background;
color: black;
}

Vertical {
width: 1fr;
}

Static {
margin: 1 2;
background: blue 20%;
border: blue wide;
height: auto;
}

#right {
overflow-y: hidden;
}
"""

def compose(self):
yield Horizontal(
Vertical(Static(TEXT), Static(TEXT), Static(TEXT), id="left"),
Vertical(Static(TEXT), Static(TEXT), Static(TEXT), id="right"),
)


app = OverflowApp()
Loading