Skip to main content
Version: Release

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 subtree
  • top_at(x, y) — pick the topmost widget at a point
  • get_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​

WidgetRole
Label / RichLabelText display
ButtonClickable label with callback
Toggle / RadioButtonOn/off and exclusive choices
SliderNumeric value with handle and meter
SelectorCycle through options
TextInputEditable text field
AnimatedLabelTypewriter-style text
ImageDisplays a surface/image
ContainerLayout host for children
ScrollingContainerContainer with scrollbars
CollapseContainerExpand/collapse content
SyncedVarReactive 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.