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
sandbox/darren/check.css
Normal file
28
sandbox/darren/check.css
Normal file
@@ -0,0 +1,28 @@
|
||||
Screen {
|
||||
align: center middle;
|
||||
}
|
||||
|
||||
Container {
|
||||
width: 50;
|
||||
height: 15;
|
||||
background: $boost;
|
||||
align: center middle;
|
||||
}
|
||||
|
||||
Checkbox {
|
||||
}
|
||||
|
||||
#check {
|
||||
background: red;
|
||||
border: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#check > .checkbox--switch {
|
||||
color: red;
|
||||
background: blue;
|
||||
}
|
||||
|
||||
#check:focus {
|
||||
tint: magenta 60%;
|
||||
}
|
||||
24
sandbox/darren/check.py
Normal file
24
sandbox/darren/check.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from textual.app import App, ComposeResult
|
||||
|
||||
from textual.containers import Container
|
||||
from textual.widgets import Checkbox, Footer
|
||||
|
||||
|
||||
class CheckboxApp(App):
|
||||
BINDINGS = [("s", "switch", "Press switch"), ("d", "toggle_dark", "Dark mode")]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Footer()
|
||||
yield Container(Checkbox(id="check", animate=True))
|
||||
|
||||
def action_switch(self) -> None:
|
||||
checkbox = self.query_one(Checkbox)
|
||||
checkbox.toggle()
|
||||
|
||||
def key_f(self):
|
||||
print(self.app.focused)
|
||||
|
||||
|
||||
app = CheckboxApp(css_path="check.css")
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
Reference in New Issue
Block a user