@@ -90,7 +90,7 @@ class BaseRenderCanvas:
9090 Arguments:
9191 size (tuple): the logical size (width, height) of the canvas.
9292 title (str): The title of the canvas. Can use '$backend' to show the RenderCanvas class name,
93- and '$fps' to show the fps.
93+ '$fps' to show the fps, and '$ms' to show the frame-time .
9494 update_mode (UpdateMode): The mode for scheduling draws and events. Default 'ondemand'.
9595 min_fps (float): A minimal frames-per-second to use when the ``update_mode`` is 'ondemand'. The default is 0:
9696 max_fps (float): A maximal frames-per-second to use when the ``update_mode`` is 'ondemand'
@@ -147,6 +147,7 @@ def __init__(
147147 self .__title_info = {
148148 "raw" : "" ,
149149 "fps" : "?" ,
150+ "ms" : "?" ,
150151 "backend" : self .__class__ .__name__ ,
151152 "loop" : self ._rc_canvas_group .get_loop ().__class__ .__name__
152153 if (self ._rc_canvas_group and self ._rc_canvas_group .get_loop ())
@@ -533,12 +534,14 @@ def _draw_frame_and_present(self):
533534
534535 # Notify the scheduler
535536 if self .__scheduler is not None :
536- fps = self .__scheduler .on_draw ()
537+ frame_time = self .__scheduler .on_draw ()
537538
538539 # Maybe update title
539- if fps is not None :
540- self .__title_info ["fps" ] = f"{ fps :0.1f} "
541- if "$fps" in self .__title_info ["raw" ]:
540+ if frame_time is not None :
541+ self .__title_info ["fps" ] = f"{ min (9999 , 1 / frame_time ):0.1f} "
542+ self .__title_info ["ms" ] = f"{ min (9999 , 1000 * frame_time ):0.1f} "
543+ raw_title = self .__title_info ["raw" ]
544+ if "$fps" in raw_title or "$ms" in raw_title :
542545 self .set_title (self .__title_info ["raw" ])
543546
544547 # Perform the user-defined drawing code. When this errors,
@@ -630,8 +633,12 @@ def set_logical_size(self, width: float, height: float) -> None:
630633 def set_title (self , title : str ) -> None :
631634 """Set the window title.
632635
633- The words "$backend", "$loop", and "$fps" can be used as variables that
634- are filled in with the corresponding values.
636+ A few special placeholders are supported:
637+
638+ * "$backend": the name of the backends's RenderCanvas subclass.
639+ * "$loop": the name of the used Loop subclass.
640+ * "$fps": the current frames per second, useful as an indication how smooth the rendering feels.
641+ * "$ms": the time between two rendered frames in milliseconds, useful for benchmarking.
635642 """
636643 self .__title_info ["raw" ] = title
637644 for k , v in self .__title_info .items ():
0 commit comments