step 6: add animation and high rate update stress tests

This commit is contained in:
2026-07-02 15:06:10 +02:00
parent 1a476bc91d
commit f4716e0d19
9 changed files with 352 additions and 21 deletions

51
examples/animations.py Normal file
View File

@@ -0,0 +1,51 @@
# pyright: reportGeneralTypeIssues=false
import math
import time
import dearpygui.dearpygui as dpg
import dpg_gauges as dpgg
def main() -> None:
dpg.create_context()
started = time.monotonic()
def update() -> None:
elapsed = time.monotonic() - started
dpgg.set_value("animated", 50 + math.sin(elapsed * 2.0) * 50)
dpgg.set_value("smoothed", 50 + math.sin(elapsed * 7.0) * 50)
dpg.set_frame_callback(dpg.get_frame_count() + 1, update)
try:
with dpg.window(label="Animations", width=460, height=260):
dpgg.digital_gauge(
tag="animated",
label="Animated",
value=0,
width=360,
height=90,
animation=dpgg.AnimationConfig(enabled=True, duration=0.35),
)
dpgg.bar_gauge(
tag="smoothed",
label="Smoothed",
value=0,
width=360,
height=90,
animation=False,
smoothing=dpgg.SmoothingConfig(enabled=True, alpha=0.18, max_step=8),
)
dpg.create_viewport(title="dpg-gauges animations", width=500, height=300)
dpg.setup_dearpygui()
dpg.set_frame_callback(1, update)
dpg.show_viewport()
dpg.start_dearpygui()
finally:
dpg.destroy_context()
if __name__ == "__main__":
main()