Debug Overlay

F3 toggles the overlay, F4 cycles features.

▶ Run in browser

Tags: debug

Exercises the engine Debug HUD: profiler timings, UI control bounds, labels, and an event log. UI controls (buttons, panels, dropdown) drive the feature mix at runtime.

Source

 1"""Debug Overlay: F3 toggles the overlay, F4 cycles features.
 2
 3Exercises the engine `Debug` HUD: profiler timings, UI control bounds,
 4labels, and an event log. UI controls (buttons, panels, dropdown) drive
 5the feature mix at runtime.
 6"""
 7
 8from simvx.core import (
 9    AnchorPreset,
10    Button,
11    Debug,
12    DropDown,
13    HBoxContainer,
14    Label,
15    MarginContainer,
16    Node,
17    Panel,
18    VBoxContainer,
19    Vec2,
20)
21from simvx.graphics import App
22
23
24class DebugDemo(Node):
25    def on_ready(self):
26        # Add the debug overlay node
27        self.add_child(Debug.create_node())
28        # Enable debug by default for this demo
29        Debug.enabled = True
30
31        # Build a simple UI scene: anchored TOP_LEFT with a 50px gutter so
32        # the panel keeps its top-left placement at any window size.
33        root_panel = Panel(name="RootPanel")
34        root_panel.set_anchor_preset(AnchorPreset.TOP_LEFT)
35        root_panel.margin_left = 50
36        root_panel.margin_top = 50
37        root_panel.size = Vec2(400, 300)
38        self.add_child(root_panel)
39
40        margin = MarginContainer(name="Margin")
41        margin.margin_left = 10
42        margin.margin_top = 10
43        margin.size = Vec2(380, 280)
44        root_panel.add_child(margin)
45
46        vbox = VBoxContainer(name="VBox")
47        vbox.size = Vec2(360, 260)
48        margin.add_child(vbox)
49
50        title = Label("Debug Overlay Demo", name="Title")
51        title.size = Vec2(360, 30)
52        vbox.add_child(title)
53
54        btn1 = Button("Click Me", name="Button1")
55        btn1.size = Vec2(200, 30)
56        btn1.on_press = lambda: print("Button 1 clicked!")
57        vbox.add_child(btn1)
58
59        btn2 = Button("Another Button", name="Button2")
60        btn2.size = Vec2(200, 30)
61        btn2.on_press = lambda: print("Button 2 clicked!")
62        vbox.add_child(btn2)
63
64        btn_disabled = Button("Disabled", name="DisabledBtn")
65        btn_disabled.size = Vec2(200, 30)
66        btn_disabled.disabled = True
67        vbox.add_child(btn_disabled)
68
69        dropdown = DropDown(name="TestDropDown")
70        dropdown.size = Vec2(200, 30)
71        dropdown.items = ["Option A", "Option B", "Option C"]
72        vbox.add_child(dropdown)
73
74        hbox = HBoxContainer(name="HBox")
75        hbox.size = Vec2(360, 30)
76        vbox.add_child(hbox)
77
78        for i in range(3):
79            b = Button(f"Btn {i}", name=f"SmallBtn{i}")
80            b.size = Vec2(100, 30)
81            hbox.add_child(b)
82
83
84if __name__ == "__main__":
85    app = App(title="SimVX Debug Demo", width=1280, height=720)
86    app.run(DebugDemo())