mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Checkbox polishing + fix auto-width in Horizontal layout (#942)
* checkbox widget * fixes * Checkbox additions, fix content width in horizontal layout * Update docs, add tests for checkbox * Remove some test code * Small renaming of test class Co-authored-by: Will McGugan <willmcgugan@gmail.com>
This commit is contained in:
28
docs/examples/widgets/checkbox.css
Normal file
28
docs/examples/widgets/checkbox.css
Normal file
@@ -0,0 +1,28 @@
|
||||
Screen {
|
||||
align: center middle;
|
||||
}
|
||||
|
||||
.container {
|
||||
height: auto;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
Checkbox {
|
||||
height: auto;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.label {
|
||||
height: 3;
|
||||
content-align: center middle;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
#custom-design {
|
||||
background: darkslategrey;
|
||||
}
|
||||
|
||||
#custom-design > .checkbox--switch {
|
||||
color: dodgerblue;
|
||||
background: darkslateblue;
|
||||
}
|
||||
33
docs/examples/widgets/checkbox.py
Normal file
33
docs/examples/widgets/checkbox.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import Horizontal
|
||||
from textual.widgets import Checkbox, Static
|
||||
|
||||
|
||||
class CheckboxApp(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("[b]Example checkboxes\n", classes="label")
|
||||
yield Horizontal(
|
||||
Static("off: ", classes="label"), Checkbox(), classes="container"
|
||||
)
|
||||
yield Horizontal(
|
||||
Static("on: ", classes="label"),
|
||||
Checkbox(value=True),
|
||||
classes="container",
|
||||
)
|
||||
|
||||
focused_checkbox = Checkbox()
|
||||
focused_checkbox.focus()
|
||||
yield Horizontal(
|
||||
Static("focused: ", classes="label"), focused_checkbox, classes="container"
|
||||
)
|
||||
|
||||
yield Horizontal(
|
||||
Static("custom: ", classes="label"),
|
||||
Checkbox(id="custom-design"),
|
||||
classes="container",
|
||||
)
|
||||
|
||||
|
||||
app = CheckboxApp(css_path="checkbox.css")
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
Reference in New Issue
Block a user