mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
@@ -22,7 +22,7 @@ Switch {
|
||||
background: darkslategrey;
|
||||
}
|
||||
|
||||
#custom-design > .switch--switch {
|
||||
#custom-design > .switch--slider {
|
||||
color: dodgerblue;
|
||||
background: darkslateblue;
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ class Switch(Widget, can_focus=True):
|
||||
"""
|
||||
|
||||
COMPONENT_CLASSES: ClassVar[set[str]] = {
|
||||
"switch--switch",
|
||||
"switch--slider",
|
||||
}
|
||||
"""
|
||||
| Class | Description |
|
||||
| :- | :- |
|
||||
| `switch--switch` | Targets the switch of the switch. |
|
||||
| `switch--slider` | Targets the slider of the switch. |
|
||||
"""
|
||||
|
||||
DEFAULT_CSS = """
|
||||
@@ -48,7 +48,7 @@ class Switch(Widget, can_focus=True):
|
||||
padding: 0 2;
|
||||
}
|
||||
|
||||
Switch > .switch--switch {
|
||||
Switch > .switch--slider {
|
||||
background: $panel-darken-2;
|
||||
color: $panel-lighten-2;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class Switch(Widget, can_focus=True):
|
||||
|
||||
}
|
||||
|
||||
Switch.-on > .switch--switch {
|
||||
Switch.-on > .switch--slider {
|
||||
color: $success;
|
||||
}
|
||||
"""
|
||||
@@ -128,7 +128,7 @@ class Switch(Widget, can_focus=True):
|
||||
self.set_class(slider_pos == 1, "-on")
|
||||
|
||||
def render(self) -> RenderableType:
|
||||
style = self.get_component_rich_style("switch--switch")
|
||||
style = self.get_component_rich_style("switch--slider")
|
||||
return ScrollBarRender(
|
||||
virtual_size=100,
|
||||
window_size=50,
|
||||
@@ -144,12 +144,17 @@ class Switch(Widget, can_focus=True):
|
||||
return 1
|
||||
|
||||
def on_click(self) -> None:
|
||||
"""Toggle the state of the switch."""
|
||||
self.toggle()
|
||||
|
||||
def action_toggle(self) -> None:
|
||||
"""Toggle the state of the switch."""
|
||||
self.toggle()
|
||||
|
||||
def toggle(self) -> None:
|
||||
"""Toggle the switch value. As a result of the value changing,
|
||||
a Switch.Changed message will be posted."""
|
||||
"""Toggle the switch value.
|
||||
|
||||
As a result of the value changing, a `Switch.Changed` message will
|
||||
be posted.
|
||||
"""
|
||||
self.value = not self.value
|
||||
|
||||
Reference in New Issue
Block a user