mirror of https://github.com/JoshKarpel/spiel
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from textual.widget import Widget
|
|
|
|
from spiel.transitions.protocol import Direction, Transition
|
|
|
|
|
|
class Swipe(Transition):
|
|
"""
|
|
A transition where the current and incoming slide are placed side-by-side
|
|
and gradually slide across the screen,
|
|
with the current slide leaving and the incoming slide entering.
|
|
"""
|
|
|
|
def initialize(
|
|
self,
|
|
from_widget: Widget,
|
|
to_widget: Widget,
|
|
direction: Direction,
|
|
) -> None:
|
|
to_widget.styles.offset = ("100%" if direction is Direction.Next else "-100%", 0)
|
|
|
|
def progress(
|
|
self,
|
|
from_widget: Widget,
|
|
to_widget: Widget,
|
|
direction: Direction,
|
|
progress: float,
|
|
) -> None:
|
|
match direction:
|
|
case Direction.Next:
|
|
from_widget.styles.offset = (f"-{progress:.2f}%", 0)
|
|
to_widget.styles.offset = (f"{100 - progress:.2f}%", 0)
|
|
case Direction.Previous:
|
|
from_widget.styles.offset = (f"{progress:.2f}%", 0)
|
|
to_widget.styles.offset = (f"-{100 - progress:.2f}%", 0)
|