Widgets
Every default scene creates a GUI root at scene.root on the hud layer. Add widgets to that tree to build interfaces.
class MyScene(bf.Scene):
def do_when_added(self):
button = bf.gui.Button("Click me", callback=lambda: print("hi"))
self.root.add(button)
Core concepts
Widget tree
Widgets form a parent/child tree under Root. Common operations:
add(*children)/remove(*children)visit(func)— walk the subtreetop_at(x, y)— pick the topmost widget at a pointget_root()— climb to the scene root
Layouts
Containers arrange children with a layout. See Layouts.
panel = bf.gui.Container(bf.gui.Column(gap=8))
panel.add(
bf.gui.Label("Settings"),
bf.gui.Button("Apply"),
)
self.root.add(panel)
Constraints
See Constraints.
from batFramework.gui.constraints import constraints as c
widget.add_constraints(
c.Width(200),
c.Height(40),
c.Center(),
)
Focus
Root manages hover, focus, tab navigation, and tooltips.
Common widgets
| Widget | Role |
|---|---|
Label / RichLabel | Text display |
Button | Clickable label with callback |
Toggle / RadioButton | On/off and exclusive choices |
Slider | Numeric value with handle and meter |
Selector | Cycle through options |
TextInput | Editable text field |
AnimatedLabel | Typewriter-style text |
Image | Displays a surface/image |
Container | Layout host for children |
ScrollingContainer | Container with scrollbars |
CollapseContainer | Expand/collapse content |
SyncedVar | Reactive value shared by widgets |
Slider example
volume = bf.gui.SyncedVar(0.8)
slider = (
bf.gui.Slider("Volume", default_value=0.8, synced_var=volume)
.set_range(0, 1)
.set_step(0.05)
)
self.root.add(slider)
HUD camera
GUI lives on the hud layer with its own camera, so it stays screen-fixed while the world camera moves.