mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
feat: add rule widget (#3209)
* feat: add rule widget * add star to init Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> * remove unnecessary validations * update rule styles * add tests for invalid rules * add minimum heights and widths * tidy up examples * remove old example * move examples styling to tcss * modify examples to fit docs screenshots * add docs first draft * add snapshot tests * add rule to widget gallery * make non-widget rule classes available * tentatively update changelog --------- Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> Co-authored-by: Will McGugan <willmcgugan@gmail.com>
This commit is contained in:
27
docs/examples/widgets/horizontal_rules.py
Normal file
27
docs/examples/widgets/horizontal_rules.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Rule, Label
|
||||
from textual.containers import Vertical
|
||||
|
||||
|
||||
class HorizontalRulesApp(App):
|
||||
CSS_PATH = "horizontal_rules.tcss"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
with Vertical():
|
||||
yield Label("solid (default)")
|
||||
yield Rule()
|
||||
yield Label("heavy")
|
||||
yield Rule(line_style="heavy")
|
||||
yield Label("thick")
|
||||
yield Rule(line_style="thick")
|
||||
yield Label("dashed")
|
||||
yield Rule(line_style="dashed")
|
||||
yield Label("double")
|
||||
yield Rule(line_style="double")
|
||||
yield Label("ascii")
|
||||
yield Rule(line_style="ascii")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = HorizontalRulesApp()
|
||||
app.run()
|
||||
13
docs/examples/widgets/horizontal_rules.tcss
Normal file
13
docs/examples/widgets/horizontal_rules.tcss
Normal file
@@ -0,0 +1,13 @@
|
||||
Screen {
|
||||
align: center middle;
|
||||
}
|
||||
|
||||
Vertical {
|
||||
height: auto;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
Label {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
27
docs/examples/widgets/vertical_rules.py
Normal file
27
docs/examples/widgets/vertical_rules.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Rule, Label
|
||||
from textual.containers import Horizontal
|
||||
|
||||
|
||||
class VerticalRulesApp(App):
|
||||
CSS_PATH = "vertical_rules.tcss"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
with Horizontal():
|
||||
yield Label("solid")
|
||||
yield Rule(orientation="vertical")
|
||||
yield Label("heavy")
|
||||
yield Rule(orientation="vertical", line_style="heavy")
|
||||
yield Label("thick")
|
||||
yield Rule(orientation="vertical", line_style="thick")
|
||||
yield Label("dashed")
|
||||
yield Rule(orientation="vertical", line_style="dashed")
|
||||
yield Label("double")
|
||||
yield Rule(orientation="vertical", line_style="double")
|
||||
yield Label("ascii")
|
||||
yield Rule(orientation="vertical", line_style="ascii")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = VerticalRulesApp()
|
||||
app.run()
|
||||
14
docs/examples/widgets/vertical_rules.tcss
Normal file
14
docs/examples/widgets/vertical_rules.tcss
Normal file
@@ -0,0 +1,14 @@
|
||||
Screen {
|
||||
align: center middle;
|
||||
}
|
||||
|
||||
Horizontal {
|
||||
width: auto;
|
||||
height: 80%;
|
||||
}
|
||||
|
||||
Label {
|
||||
width: 6;
|
||||
height: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
Reference in New Issue
Block a user