Skip to content

Modifiers ​

Modifiers attach Roblox UIComponents to a widget — rounded corners, padding, strokes, layouts, and constraints. They are written as keys directly on a widget's props table:

luau
PeanutUI.Frame {
    size = PeanutUI.Size(200, 200),
    cornerRadius = { all = PeanutUI.Unit(12) },
    padding = { all = PeanutUI.Unit(16) },
}

Singular and plural forms ​

Some modifiers accept either a single setup or a list:

SingularPlural
strokestrokes
shadowshadows
luau
PeanutUI.Frame {
    strokes = {
        { thickness = 2, color = Color3.new(1, 1, 1) },
        { thickness = 2, color = Color3.new(0, 0, 0), borderOffset = PeanutUI.Unit(2) },
    },
}

Per-modifier options ​

Every modifier setup also accepts transitions and animations:

luau
PeanutUI.Frame {
    cornerRadius = {
        all = PeanutUI.Unit(12),
        transitions = { all = Transitions.Ease(0.3, "EaseOut") },
    },
}

Available modifiers ​

Styling ​

ModifierDescription
flexFlex layout behavior.
cornerRadiusRounded corners.
paddingInner padding.
strokeBorder stroke.
gradientGradient fill.
shadowDrop shadow.

Layouts ​

ModifierDescription
listLinear layout.
gridGrid layout.
tableTable layout.

Constraints ​

ModifierDescription
aspectRatioLock aspect ratio.
sizeConstraintMin/max size.
textSizeConstraintMin/max text size.
scaleUI scale.

Methods ​

getModifier(name, index?) returns a modifier component. Components expose the same reactive API as widgets, scoped to the modifier's own properties:

MethodSignatureDescription
setProperty(key: string, value: any | Ref<any>) -> ()Sets a modifier property.
getProperty(key: string) -> anyReads a modifier property.
snapProperty(key: string, value: any | Ref<any>) -> ()Sets a property without running its transition.
observe(key: string, callback: (newValue: any) -> ()) -> (() -> ())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.
setModifier(name: string, params: any?) -> ()Adds or updates a nested modifier.
getModifier(name: string, index: number?) -> ComponentGets a nested modifier component.
setAnimation(name: string | number, animation: MaybeResolvedAnimation?) -> ()Attaches or clears an animation.
getAnimationControl(name: string | number) -> AnimationControlGets a control handle for an animation.
destroy() -> ()Destroys the modifier component.
isDestroyed() -> booleanWhether the component has been destroyed.
mountTo(object: Instance) -> ()Mounts the component onto a UIComponent.
getComponent() -> UIComponent?The underlying Roblox UIComponent.
getScaleObjectFn() -> (value: T, getOriginal: boolean?) -> TThe current scale function.
setScaleObjectFn(fn: ((value: T, getOriginal: boolean?) -> T)?) -> ()Replaces the scale function.
luau
const corner = widget.getModifier("cornerRadius")
corner.setProperty("all", PeanutUI.Unit(16))
corner.observe("all", function(value)
    print("radius is now", value)
end)