frobar-ng: Improve animation
This commit is contained in:
parent
bfd31bb742
commit
ecf831d4ac
|
@ -139,13 +139,14 @@ class Section(ComposableText):
|
||||||
# Geometric series, with a cap
|
# Geometric series, with a cap
|
||||||
ANIM_A = 0.025
|
ANIM_A = 0.025
|
||||||
ANIM_R = 0.9
|
ANIM_R = 0.9
|
||||||
ANIM_MIN = 0.001
|
ANIM_MIN = 0.005
|
||||||
|
|
||||||
async def animate(self) -> None:
|
async def animate(self) -> None:
|
||||||
increment = 1 if self.size < self.targetSize else -1
|
increment = 1 if self.size < self.targetSize else -1
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
frameTime = loop.time()
|
frameTime = loop.time()
|
||||||
animTime = self.ANIM_A
|
animTime = self.ANIM_A
|
||||||
|
skipped = 0
|
||||||
|
|
||||||
while self.size != self.targetSize:
|
while self.size != self.targetSize:
|
||||||
self.size += increment
|
self.size += increment
|
||||||
|
@ -158,9 +159,12 @@ class Section(ComposableText):
|
||||||
|
|
||||||
# In case of stress, skip refreshing by not awaiting
|
# In case of stress, skip refreshing by not awaiting
|
||||||
if sleepTime > 0:
|
if sleepTime > 0:
|
||||||
|
if skipped > 0:
|
||||||
|
log.warning(f"Skipped {skipped} animation frame(s)")
|
||||||
|
skipped = 0
|
||||||
await asyncio.sleep(sleepTime)
|
await asyncio.sleep(sleepTime)
|
||||||
else:
|
else:
|
||||||
log.warning("Skipped an animation frame")
|
skipped += 1
|
||||||
|
|
||||||
def setText(self, text: str | None) -> None:
|
def setText(self, text: str | None) -> None:
|
||||||
# OPTI Don't redraw nor reset animation if setting the same text
|
# OPTI Don't redraw nor reset animation if setting the same text
|
||||||
|
|
Loading…
Reference in a new issue