Skip to content

Widgets ​

Widgets are the declarative constructors you build your UI out of. Each one maps to a Roblox GuiObject and is called as a table constructor:

luau
PeanutUI.Frame {
    size = PeanutUI.Size(200, 200)
}

Calling convention ​

Every widget accepts an optional props table and an optional children table:

luau
PeanutUI.Frame(props, children)
  • props — a flat table of widget arguments. Properties, events, and modifiers are written as keys directly; transitions, animations, children, onSetup, and widgetName are reserved keys.
  • children — a table of child widgets. Equivalent to props.children, but kept separate so structure is visible at a glance.
luau
PeanutUI.Frame(
    { size = PeanutUI.Size(200, 200) },
    {
        PeanutUI.TextLabel { text = "Hi" },
        PeanutUI.TextButton { text = "Click" },
    }
)

WARNING

Passing both props.children and a second children argument errors. Use one or the other.

Flat props ​

Properties, events, and modifiers are classified by key name, so you write them flat:

luau
PeanutUI.TextButton {
    text = "Click me",
    size = PeanutUI.Size(200, 60),
    cornerRadius = { all = PeanutUI.Unit(12) },
    Activated = function()
        print("clicked")
    end,
}

See Flat props in the widgets guide for the full rules.

Available widgets ​

WidgetRoblox object
FrameFrame
CanvasGroupCanvasGroup
ImageLabelImageLabel
ImageButtonImageButton
TextLabelTextLabel
TextButtonTextButton
TextBoxTextBox
ScrollingFrameScrollingFrame
ViewportFrameViewportFrame
VideoFrameVideoFrame

Shared properties ​

All widgets share the base properties from DefaultProperties:

PropertyTypeDescription
visiblebooleanWhether the widget is rendered.
layoutOrdernumberOrder used by layout modifiers.
zIndexnumberDraw order.
clipsDescendantsbooleanWhether children are clipped to bounds.
sizeSizeReactive size.
positionPositionReactive position.
anchorPointVector2Anchor point.
rotationnumberRotation in degrees.
automaticSizeEnum.AutomaticSizeAutomatic sizing mode.
backgroundColorColor3Background color.
backgroundTransparencynumberBackground transparency.
namestringInstance name.
absoluteSizestringAbsolute size of widget. Downscaled.
absolutePositionstringAbsolute position of widget. Downscaled.
absoluteRotationstringAbsolute rotation of widget.
screenSizestringActual size of widget on screen. Useful for rendering.
screenPositionstringActual position of widget on screen. Useful for rendering.

Shared events ​

All widgets support the base events from DefaultEvents:

EventSignature
InputBegan(inputObject: InputObject) -> ...boolean?
InputChanged(inputObject: InputObject) -> ...boolean?
InputEnded(inputObject: InputObject) -> ...boolean?
MouseEnter(x: number, y: number) -> ...boolean?
MouseMoved(x: number, y: number) -> ...boolean?
MouseLeave(x: number, y: number) -> ...boolean?
SelectionChanged(amISelected: boolean, previousSelection: GuiObject, newSelection: GuiObject) -> ...boolean?
TouchTap(touchPositions: {Vector2}) -> ...boolean?

Widget lifecycle events (ChildAdded, ChildRemoved, ParentChanged, PropertyChanged, ObjectCreated, Destroying, Destroyed) are also available on every widget.

Methods ​

Every widget instance exposes the following methods. They are grouped by the feature they come from; a widget only implements the features it declares (check with isImplemented).

Lifecycle ​

MethodSignatureDescription
destroy() -> ()Destroys the widget, its object, and its children.
isDestroyed() -> booleanWhether the widget has been destroyed.
isImplemented(field: string, isFeature: boolean?) -> booleanWhether a method (or feature) is implemented.
getObject() -> Instance?The underlying Roblox instance, if created.
getObjectRef() -> ProtectedRef<Instance?>Reactive ref to the underlying instance.

Properties ​

MethodSignatureDescription
setProperty(key: string, value: any | Ref<any>) -> ()Sets a property. Accepts a plain value or a ref.
getProperty(key: string) -> anyReads a property's current value.
snapProperty(key: string, value: any | Ref<any>) -> ()Sets a property without running its transition.
observe(key: string, callback: (newValue: any) -> ...boolean?) -> (() -> ())Watches a property; returns an unwatch function.
getRef(key: string) -> ProtectedRef<any>A reactive ref for a property.
setTransition(key: string, transition: Transition?) -> ()Attaches or clears a transition for a property.

Events ​

MethodSignatureDescription
listen(name: string, callback: any) -> (() -> ())Subscribes to an event; returns an unsubscribe function.

Parenting ​

MethodSignatureDescription
setParent(parent: WidgetLike?) -> ()Reparents the widget.
getParent() -> Interface?The current parent widget.
getSpace() -> SpaceLike?The Space the widget belongs to.

Children ​

MethodSignatureDescription
addChild(child: WidgetLike) -> ()Adds a child widget.
removeChild(child: WidgetLike, andDestroy: boolean?) -> ()Removes a child, optionally destroying it.
clearChildren() -> ()Removes and destroys all children.
children{Interface}Read-only list of child widgets.

Modifiers ​

MethodSignatureDescription
setModifier(name: string, params: any?) -> ()Adds or updates a modifier.
getModifier(name: string, index: number?) -> ComponentGets a modifier component by name.

Animations ​

MethodSignatureDescription
setAnimation(name: string | number, animation: MaybeResolvedAnimation?, disableAutoPlay: boolean?) -> ()Attaches or clears an animation.
getAnimationControl(name: string | number) -> AnimationControlGets a control handle for an animation.

AnimationControl ​

Returned by getAnimationControl:

MethodSignatureDescription
animate() -> ()Starts the animation.
stop() -> ()Stops the animation.
pause() -> ()Pauses the animation.
continue() -> ()Resumes a paused animation.
isRunning() -> booleanWhether the animation is running.