Skip to content

Commit

Permalink
[STUDIO] Bypass scroll frame rate limiting for longer intervals (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
ObaraEmmanuel committed Nov 7, 2024
1 parent dec8edb commit d10d9c2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion hoverset/ui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import functools
import logging
import os
import time
import tkinter as tk
import tkinter.ttk as ttk
import webbrowser
Expand Down Expand Up @@ -1253,6 +1254,7 @@ def __init__(self, master=None, **cnf):
# self.after(200, self.on_configure)
self._limit_var = [0, 0] # limit var for x and y
self._max_frame_skip = 3
self._last_render = time.perf_counter_ns()
self.fill_x = True # Set to True to disable the x scrollbar and fit content to width
self.fill_y = False # Set to True to disable the y scrollbar and fit content to height
self._prev_region = (0, 0, 0, 0)
Expand Down Expand Up @@ -1284,7 +1286,13 @@ def config_all(self, **cnf):
def _limiter(self, callback, axis, *args):
# Frame limiting reduces lags while scrolling by skipping a number of scroll events to reduce the burden
# of performing expensive redrawing by tkinter
if self._limit_var[axis] == self._max_frame_skip:
render_time = time.perf_counter_ns()
render_diff = render_time - self._last_render
self._last_render = render_time

# Max human click rate is about 15 CPS = 70ms/click
# Always render if it's been longer than 70ms since last render
if self._limit_var[axis] == self._max_frame_skip or render_diff > 7e7:
callback(*args)
self._limit_var[axis] = 0
else:
Expand Down

0 comments on commit d10d9c2

Please sign in to comment.