Widget script handlers

From Warcraft Wiki
Jump to navigation Jump to search

Widget scripts allow you to respond to user interaction and other types of widget events (such as a frame being shown or hidden). This page lists the available scripts and the list of widget types for which each script is valid.

Example

Registers for mouse clicks on a Button widget with the OnClick script.
local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
btn:SetPoint("CENTER")
btn:SetSize(100, 40)
btn:SetText("Click me")
btn:SetScript("OnClick", function(self, button, down)
	print("Pressed", button, down and "down" or "up")
end)
btn:RegisterForClicks("AnyDown", "AnyUp")
-- Pressed LeftButton down
-- Pressed LeftButton up


Note
Note: This list is up to date as of Patch 10.2.6 (53840) Mar 18 2024

Script Types

AnimationGroup

OnFinished(self, requested) - Invoked when the animation group finishes animating.
OnLoop(self, loopState) - Invoked when the animation group's loop state changes.
OnPause(self) - Invoked when the animation group is paused.
OnPlay(self) - Invoked when the animation group begins to play.
OnStop(self, requested) - Invoked when the animation group is stopped.
OnUpdate(self, elapsed) - Invoked on every frame.
OnLoad(self) - Invoked when the object is created.

Animation

OnFinished(self, requested) - Invoked when the animation finishes animating.
OnPause(self) - Invoked when the animation is paused.
OnPlay(self) - Invoked when the animation begins to play.
OnStop(self, requested) - Invoked when the animation is stopped.
OnUpdate(self, elapsed) - Invoked on every frame.
OnLoad(self) - Invoked when the object is created.

ScriptRegion

OnShow(self) - Invoked when the widget is shown.
OnHide(self) - Invoked when the widget is hidden.
OnEnter(self, motion) - Invoked when the cursor enters the widget's interactive area.
OnLeave(self, motion) - Invoked when the mouse cursor leaves the widget's interactive area.
OnMouseDown(self, button) - Invoked when a mouse button is pressed while the cursor is over the widget.
OnMouseUp(self, button, isInside) - Invoked when the mouse button is released following a mouse down action in the widget.
OnMouseWheel(self, delta) - Invoked when the widget receives a mouse wheel scrolling action.
OnLoad(self) - Invoked when the widget is created.

Frame

OnAttributeChanged(self, key, value) - Invoked when a secure frame attribute is changed.
OnChar(self, text) - Invoked for each text character typed in the frame.
OnDisable(self) - Invoked when the frame is disabled.
OnDragStart(self, button) - Invoked when the mouse is dragged starting in the frame
OnDragStop(self) - Invoked when the mouse button is released after a drag started in the frame,
OnEnable(self) - Invoked when the frame is enabled.
OnEvent(self, event, ...) - Invoked whenever an event fires for which the frame is registered.
OnGamePadButtonDown(self, button) - Invoked when a gamepad button is pressed.
OnGamePadButtonUp(self, button) - Invoked when a gamepad button is released.
OnGamePadStick(self, stick, x, y, len) - Invoked when a gamepad stick is moved.
OnHyperlinkClick(self, link, text, button, region, left, bottom, width, height) - Invoked when the mouse clicks a hyperlink on the FontInstance object.
OnHyperlinkEnter(self, link, text, region, left, bottom, width, height) - Invoked when the mouse moves over a hyperlink on the FontInstance object.
OnHyperlinkLeave(self) - Invoked when the mouse moves away from a hyperlink on the FontInstance object.
OnKeyDown(self, key) - Invoked when a keyboard key is pressed if the frame is keyboard enabled.
OnKeyUp(self, key) - Invoked when a keyboard key is released if the frame is keyboard enabled.
OnReceiveDrag(self) - Invoked when the mouse button is released after dragging into the frame.
OnSizeChanged(self, width, height) - Invoked when a frame's size changes.
OnUpdate(self, elapsed) - Invoked on every frame.

Button

OnClick(self, self, button, down) - Invoked when clicking a button.
OnDoubleClick(self, self, button) - Invoked when double-clicking a button.
PostClick(self, button, down) - Invoked immediately after `OnClick`.
PreClick(self, button, down) - Invoked immediately before `OnClick`.

Model

OnAnimFinished(self) - Invoked when the model's animation finishes.
OnAnimStarted(self) - Invoked when the model's animation starts.
OnModelLoaded(self) - Invoked when the model is loaded.

CinematicModel

OnPanFinished(self) - Invoked when the camera has finished panning.

DressUpModel

OnDressModel(self) - Invoked when the dressup model is updated.

ModelScene

OnDressModel(self) - Invoked when the modelscene model is updated.

ModelSceneActor

Scripts for this widget can only be set from XML.

OnAnimFinished(self)
OnModelCleared(self)
OnModelLoaded(self)
OnModelLoading(self)

EditBox

OnArrowPressed(self, key)
OnCharComposition(self, text) - Invoked when changing the input composition mode.
OnCursorChanged(self, x, y, w, h) - Invoked when moving the text insertion cursor.
OnEditFocusGained(self) - Invoked when gaining edit focus.
OnEditFocusLost(self) - Invoked when losing edit focus.
OnEnterPressed(self) - Invoked when pressing Enter while the widget has focus.
OnEscapePressed(self) - Invoked when pressing Escape while the widget has focus.
OnSpacePressed(self) - Invoked when pressing Space while the widget has focus.
OnInputLanguageChanged(self, language) - Invoked when changing the language input mode.
OnTabPressed(self) - Invoked when pressing Tab while the widget has focus.
OnTextChanged(self, userInput) - Invoked when changing the value.
OnTextSet(self) - Invoked when setting the value programmatically.

GameTooltip

OnTooltipAddMoney(self, cost, maxcost) - Run when an amount of money should be added to the tooltip.
OnTooltipCleared(self) - Run when the tooltip is hidden or its content is cleared.
OnTooltipSetAchievement(self) - Run when the tooltip is filled with information about an achievement.
OnTooltipSetDefaultAnchor(self) - Run when the tooltip is repositioned to its default anchor location.
OnTooltipSetEquipmentSet(self) - Run when the tooltip is filled with information about an equipment set.
OnTooltipSetFramestack(self, highlightFrame) - Run when the tooltip is filled with a list of frames under the mouse cursor.
OnTooltipSetItem(self) - Run when the tooltip is filled with information about an item.
OnTooltipSetQuest(self) - Run when the tooltip is filled with information about a quest.
OnTooltipSetSpell(self) - Run when the tooltip is filled with information about a spell.
OnTooltipSetUnit(self) - Run when the tooltip is filled with information about a unit.

ColorSelect

OnColorSelect(self, r, g, b) - Invoked when the ColorSelect frame's color selection changes.

Cooldown

OnCooldownDone(self) - Invoked when the cooldown has finished.

MovieFrame

OnMovieFinished(self) - Invoked when a movie frame's movie ends.
OnMovieHideSubtitle(self) - Invoked when the movie's most recently displayed subtitle should be hidden.
OnMovieShowSubtitle(self, text) - Invoked when a subtitle for the playing movie should be displayed.

ScrollFrame

OnHorizontalScroll(self, offset) - Invoked when the horizontal scroll position changes.
OnScrollRangeChanged(self, xrange, yrange) - Invoked when the scroll position changes.
OnVerticalScroll(self, offset) - Invoked when the vertical scroll position changes.

Slider

OnMinMaxChanged(self, min, max) - Invoked when the slider's minimum and maximum values change.
OnValueChanged(self, value, userInput) - Invoked when the slider's value changes.

StatusBar

OnMinMaxChanged(self, min, max) - Invoked when the status bar's minimum and maximum values change.
OnValueChanged(self, value) - Invoked when the status bar's value changes.

FogOfWarFrame

OnUiMapChanged(self, uiMapID)

References