UI System¶
SimVX provides a set of UI controls and layout containers for building game interfaces.
Controls¶
All controls inherit from Control, which provides rect-based layout, mouse interaction, and focus management.
Label¶
from simvx.core import Label
label = Label(text="Score: 0", font_size=24)
label.position = Vec2(10, 10)
root.add_child(label)
TextEdit¶
from simvx.core import TextEdit
edit = TextEdit(placeholder="Enter name...")
edit.text_changed.connect(lambda text: print(text))
root.add_child(edit)
Slider¶
from simvx.core import Slider
slider = Slider(min_value=0, max_value=100, value=50)
slider.value_changed.connect(lambda v: print(f"Volume: {v}"))
root.add_child(slider)
ProgressBar¶
from simvx.core import ProgressBar
bar = ProgressBar(min_value=0, max_value=100, value=75)
root.add_child(bar)
Containers¶
Containers automatically arrange their children.
HBoxContainer / VBoxContainer¶
from simvx.core import HBoxContainer, VBoxContainer, Button
menu = VBoxContainer(separation=10)
menu.add_child(Button(text="New Game"))
menu.add_child(Button(text="Load Game"))
menu.add_child(Button(text="Settings"))
root.add_child(menu)
GridContainer¶
from simvx.core import GridContainer
grid = GridContainer(columns=3, h_separation=5, v_separation=5)
for i in range(9):
grid.add_child(Button(text=str(i + 1)))
MarginContainer¶
from simvx.core import MarginContainer
margin = MarginContainer(
margin_left=20, margin_right=20,
margin_top=10, margin_bottom=10,
)
margin.add_child(Label(text="Padded content"))
Theming¶
Apply consistent styling across controls:
from simvx.core import Theme
theme = Theme(
bg_color=(0.2, 0.2, 0.2, 1.0),
fg_color=(1.0, 1.0, 1.0, 1.0),
accent_color=(0.3, 0.6, 1.0, 1.0),
font_size=16,
)
Input Handling¶
UI input is routed through the SceneTree:
tree.ui_input(mouse_pos=(100, 200), button=1, pressed=True)
tree.ui_input(key="return", pressed=True)
API Reference¶
See simvx.core.ui for the complete UI API.