mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
more efficient order styles
This commit is contained in:
@@ -482,7 +482,10 @@ class Stylesheet:
|
||||
node._has_hover_style = "hover" in all_pseudo_classes
|
||||
node._has_focus_within = "focus-within" in all_pseudo_classes
|
||||
node._has_order_style = not all_pseudo_classes.isdisjoint(
|
||||
{"first-of-type", "last-of-type", "odd", "even"}
|
||||
{"first-of-type", "last-of-type"}
|
||||
)
|
||||
node._has_odd_or_even = (
|
||||
"odd" in all_pseudo_classes or "even" in all_pseudo_classes
|
||||
)
|
||||
|
||||
cache_key: tuple | None = None
|
||||
|
||||
@@ -775,10 +775,9 @@ class WidgetsScreen(PageScreen):
|
||||
WidgetsScreen {
|
||||
align-horizontal: center;
|
||||
Markdown { background: transparent; }
|
||||
& > VerticalScroll {
|
||||
#container {
|
||||
scrollbar-gutter: stable;
|
||||
&> * {
|
||||
|
||||
& > * {
|
||||
&:even { background: $boost; }
|
||||
padding-bottom: 1;
|
||||
}
|
||||
@@ -789,7 +788,7 @@ class WidgetsScreen(PageScreen):
|
||||
BINDINGS = [Binding("escape", "blur", "Unfocus any focused widget", show=False)]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
with lazy.Reveal(containers.VerticalScroll(can_focus=True)):
|
||||
with lazy.Reveal(containers.VerticalScroll(id="container", can_focus=True)):
|
||||
yield Markdown(WIDGETS_MD, classes="column")
|
||||
yield Buttons()
|
||||
yield Checkboxes()
|
||||
|
||||
@@ -223,6 +223,8 @@ class DOMNode(MessagePump):
|
||||
self._has_focus_within: bool = False
|
||||
self._has_order_style: bool = False
|
||||
"""The node has an ordered dependent pseudo-style (`:odd`, `:even`, `:first-of-type`, `:last-of-type`)"""
|
||||
self._has_odd_or_even: bool = False
|
||||
"""The node has the pseudo class `odd` or `even`."""
|
||||
self._reactive_connect: (
|
||||
dict[str, tuple[MessagePump, Reactive[object] | object]] | None
|
||||
) = None
|
||||
|
||||
@@ -177,6 +177,11 @@ class Timer:
|
||||
|
||||
async def _tick(self, *, next_timer: float, count: int) -> None:
|
||||
"""Triggers the Timer's action: either call its callback, or sends an event to its target"""
|
||||
|
||||
app = active_app.get()
|
||||
if app._exit:
|
||||
return
|
||||
|
||||
if self._callback is not None:
|
||||
try:
|
||||
await invoke(self._callback)
|
||||
@@ -185,7 +190,6 @@ class Timer:
|
||||
# Re-raise CancelledErrors that would be caught by the following exception block in Python 3.7
|
||||
raise
|
||||
except Exception as error:
|
||||
app = active_app.get()
|
||||
app._handle_exception(error)
|
||||
else:
|
||||
event = events.Timer(
|
||||
|
||||
@@ -1253,11 +1253,18 @@ class Widget(DOMNode):
|
||||
parent, *widgets, before=insert_before, after=insert_after
|
||||
)
|
||||
|
||||
def update_styles(children: Iterable[DOMNode]) -> None:
|
||||
def update_styles(children: list[DOMNode]) -> None:
|
||||
"""Update order related CSS"""
|
||||
for child in children:
|
||||
if child._has_order_style:
|
||||
child._update_styles()
|
||||
if before is not None or after is not None:
|
||||
# If the new children aren't at the end.
|
||||
# we need to update both odd/even and first-of-type/last-of-type
|
||||
for child in children:
|
||||
if child._has_order_style or child._has_odd_or_even:
|
||||
child._update_styles()
|
||||
else:
|
||||
for child in children:
|
||||
if child._has_order_style:
|
||||
child._update_styles()
|
||||
|
||||
self.call_later(update_styles, list(self.children))
|
||||
await_mount = AwaitMount(self, mounted)
|
||||
|
||||
Reference in New Issue
Block a user