Of all the various subtypes of Frame in the user interface system, Buttons are the most visible, since users interact with them frequently during game play. They are the primary means by which the user controls the game and their characters.
Buttons have an intrinsic FontString built-in, so they support both the SetText and the GetText methods. In addition, a button has three special visual states that can be decorated independently: one when the button is disabled, one when the button has been pushed but not yet released, and one when the mouse is over the button. The changes to the button's presentation happen automatically based on the button's definition.
The most important aspect of a Button is the fact that it can be clicked by the user. When a button is clicked the PreClick script handler will fire, followed by the OnClick handler, and finally the PostClick handler. These allow an addon developer lots of flexibility when creating an addon, especially in the presence of the secure environment and tainting system introduced in WoW 2.0.
To create a button, call CreateFrame with "Button" as the first argument, or construct one in an XML file with a <Button> element. Some handy templates for this include UIPanelButtonTemplate (which provides a standard red button), UIPanelCloseButton (a small red square with a yellow X in it) and SecureHandlerClickTemplate.
The most famous Buttons are probably unit frames, which make use of the SecureActionButtonTemplate (or its derivative, SecureUnitButtonTemplate) to control targeting and sometimes spell-casting. There are many insecure buttons as well (or more accurately, buttons which do not require security), such as the micro buttons on the action bar for opening various panels and menus, or the buttons around the minimap for revealing the calendar or displaying the world map.
Defined Methods
- Button:Click("button", down) - Performs a (virtual) mouse click on the button
- Button:Disable() - Disallows user interaction with the button
- Button:Enable() - Allows user interaction with the button
- state = Button:GetButtonState() - Returns the button's current state
- font = Button:GetDisabledFontObject() - Returns the font object used for the button's disabled state
- texture = Button:GetDisabledTexture() - Returns the texture used when the button is disabled
- fontstring = Button:GetFontString() - Returns the `FontString` object used for the button's label text
- font = Button:GetHighlightFontObject() - Returns the font object used when the button is highlighted
- texture = Button:GetHighlightTexture() - Returns the texture used when the button is highlighted
- isEnabled = Button:GetMotionScriptsWhileDisabled() - Determines whether [[docs/scripts/OnEnter|OnEnter]]/[[docs/scripts/OnLeave|OnLeave]] scripts will fire while the button is disabled
- font = Button:GetNormalFontObject() - Returns the font object used for the button's normal state
- texture = Button:GetNormalTexture() - Returns the texture used for the button's normal state
- x, y = Button:GetPushedTextOffset() - Returns the offset for moving the button's label text when pushed
- texture = Button:GetPushedTexture() - Returns the texture used when the button is pushed
- text = Button:GetText() - Returns the text of the button's label
- height = Button:GetTextHeight() - Returns the height of the button's text label
- width = Button:GetTextWidth() - Returns the width of the button's text label
- enabled = Button:IsEnabled() - Returns whether user interaction with the button is allowed
- Button:LockHighlight() - Locks the button in its highlight state
- Button:RegisterForClicks(...) - Registers a button to receive mouse clicks
- Button:SetButtonState("state", lock) - Sets the button's state
- Button:SetDisabledFontObject(font) - Sets the font object used for the button's disabled state
- Button:SetDisabledTexture(texture) or Button:SetDisabledTexture("filename") - Sets the texture used when the button is disabled
- Button:SetFontString(fontstring) - Sets the `FontString` object used for the button's label text
- Button:SetFormattedText("formatString", ...) - Sets the button's label text using format specifiers
- Button:SetHighlightFontObject(font) - Sets the font object used when the button is highlighted
- Button:SetHighlightTexture(texture [, "mode"]) or Button:SetHighlightTexture("filename" [, "mode"]) - Sets the texture used when the button is highlighted
- Button:SetMotionScriptsWhileDisabled(enabled) - Sets whether the button should fire [[docs/scripts/OnEnter|OnEnter]]/[[docs/scripts/OnLeave|OnLeave]] events while disabled
- Button:SetNormalFontObject(font) - Sets the font object used for the button's normal state
- Button:SetNormalTexture(texture) or Button:SetNormalTexture("filename") - Sets the texture used for the button's normal state
- Button:SetPushedTextOffset(x, y) - Sets the offset for moving the button's label text when pushed
- Button:SetPushedTexture(texture) or Button:SetPushedTexture("filename") - Sets the texture used when the button is pushed
- Button:SetText("text") - Sets the text displayed as the button's label
- Button:UnlockHighlight() - Unlocks the button's highlight state
Inherited Methods
- Button:AllowAttributeChanges() - Temporarily allows insecure code to modify the frame's attributes during combat
- enabled = Button:CanChangeAttribute() - Returns whether secure frame attributes can currently be changed
- canChange = Button:CanChangeProtectedState() - Returns whether protected properties of the region can be changed by non-secure scripts
- Button:ClearAllPoints() - Removes all anchor points from the region
- animationGroup = Button:CreateAnimationGroup(["name" [, "inheritsFrom"]]) - Creates a new AnimationGroup as a child of the region
- fontstring = Button:CreateFontString(["name" [, "layer" [, "inherits"]]]) - Creates a new [[docs/widgets/FontString|`FontString`]] as a child of the frame
- texture = Button:CreateTexture(["name" [, "layer" [, "inherits"]]]) - Creates a new [[docs/widgets/Texture|`Texture`]] as a child of the frame
- region = Button:CreateTitleRegion() - Creates a title region for dragging the frame
- Button:DisableDrawLayer("layer") - Prevents display of all child objects of the frame on a specified graphics layer
- Button:EnableDrawLayer("layer") - Allows display of all child objects of the frame on a specified graphics layer
- Button:EnableJoystick(enable) - Enables or disables joystick interactivity
- Button:EnableKeyboard(enable) - Enables or disables keyboard interactivity for the frame
- Button:EnableMouse(enable) - Enables or disables mouse interactivity for the frame
- Button:EnableMouseWheel(enable) - Enables or disables mouse wheel interactivity for the frame
- alpha = Button:GetAlpha() - Returns the opacity of the region relative to its parent
- ... = Button:GetAnimationGroups() - Returns a list of animation groups belonging to the region
- value = Button:GetAttribute("name") - Returns the value of a secure frame attribute
- backdrop = Button:GetBackdrop() - Returns information about the frame's backdrop graphic
- red, green, blue, alpha = Button:GetBackdropBorderColor() - Returns the shading color for the frame's border graphic
- red, green, blue, alpha = Button:GetBackdropColor() - Returns the shading color for the frame's background graphic
- bottom = Button:GetBottom() - Returns the distance from the bottom of the screen to the bottom of the region
- left, bottom, width, height = Button:GetBoundsRect() - Returns the position and dimension of the smallest area enclosing the frame and its children
- x, y = Button:GetCenter() - Returns the screen coordinates of the region's center
- ... = Button:GetChildren() - Returns a list of child frames of the frame
- left, right, top, bottom = Button:GetClampRectInsets() - Returns offsets from the frame's edges used when limiting user movement or resizing of the frame
- depth = Button:GetDepth() - Returns the 3D depth of the frame (for stereoscopic 3D setups)
- alpha = Button:GetEffectiveAlpha() - Returns the overall opacity of the frame
- depth = Button:GetEffectiveDepth() - Returns the overall 3D depth of the frame (for stereoscopic 3D configurations)
- scale = Button:GetEffectiveScale() - Returns the overall scale factor of the frame
- level = Button:GetFrameLevel() - Sets the level at which the frame is layered relative to others in its strata
- strata = Button:GetFrameStrata() - Returns the general layering strata of the frame
- height = Button:GetHeight() - Returns the height of the region
- left, right, top, bottom = Button:GetHitRectInsets() - Returns the insets from the frame's edges which determine its mouse-interactable area
- id = Button:GetID() - Returns the frame's numeric identifier
- left = Button:GetLeft() - Returns the distance from the left edge of the screen to the left edge of the region
- maxWidth, maxHeight = Button:GetMaxResize() - Returns the maximum size of the frame for user resizing
- minWidth, minHeight = Button:GetMinResize() - Returns the minimum size of the frame for user resizing
- name = Button:GetName() - Returns the widget object's name
- numChildren = Button:GetNumChildren() - Returns the number of child frames belonging to the frame
- numPoints = Button:GetNumPoints() - Returns the number of anchor points defined for the region
- numRegions = Button:GetNumRegions() - Returns the number of non-Frame child regions belonging to the frame
- type = Button:GetObjectType() - Returns the object's widget type
- parent = Button:GetParent() - Returns the object's parent object
- point, relativeTo, relativePoint, xOffset, yOffset = Button:GetPoint(index) - Returns information about one of the region's anchor points
- left, bottom, width, height = Button:GetRect() - Returns the position and dimensions of the region
- ... = Button:GetRegions() - Returns a list of non-Frame child regions belonging to the frame
- right = Button:GetRight() - Returns the distance from the left edge of the screen to the right edge of the region
- scale = Button:GetScale() - Returns the frame's scale factor
- handler = Button:GetScript("scriptType") - Returns the widget's handler function for a script
- width, height = Button:GetSize() - Returns the width and height of the region
- region = Button:GetTitleRegion() - Returns the frame's TitleRegion object
- top = Button:GetTop() - Returns the distance from the bottom of the screen to the top of the region
- width = Button:GetWidth() - Returns the width of the region
- hasScript = Button:HasScript("scriptType") - Returns whether the widget supports a script handler
- Button:Hide() - Hides the region
- Button:HookScript("scriptType", handler) - Securely hooks a script handler
- Button:IgnoreDepth(enable) - Sets whether the frame's depth property is ignored (for stereoscopic 3D setups)
- enabled = Button:IsClampedToScreen() - Returns whether the frame's boundaries are limited to those of the screen
- isDragging = Button:IsDragging() - Returns whether the region is currently being dragged
- registered = Button:IsEventRegistered("event") - Returns whether the frame is registered for a given [[docs/events|event]]
- enabled = Button:IsIgnoringDepth() - Returns whether the frame's depth property is ignored (for stereoscopic 3D setups)
- enabled = Button:IsJoystickEnabled() - Returns whether joystick interactivity is enabled for the frame
- enabled = Button:IsKeyboardEnabled() - Returns whether keyboard interactivity is enabled for the frame
- enabled = Button:IsMouseEnabled() - Returns whether mouse interactivity is enabled for the frame
- isOver = Button:IsMouseOver() - Returns whether the mouse cursor is over the given region
- enabled = Button:IsMouseWheelEnabled() - Returns whether mouse wheel interactivity is enabled for the frame
- movable = Button:IsMovable() - Returns whether the frame can be moved by the user
- isType = Button:IsObjectType("type") - Returns whether the object belongs to a given widget type
- isProtected, explicit = Button:IsProtected() - Returns whether the region is protected
- enabled = Button:IsResizable() - Returns whether the frame can be resized by the user
- shown = Button:IsShown() - Returns whether the region is shown
- enabled = Button:IsToplevel() - Returns whether the frame is automatically raised to the front when clicked
- enabled = Button:IsUserPlaced() - Returns whether the frame is flagged for automatic saving and restoration of position and dimensions
- visible = Button:IsVisible() - Returns whether the region is visible
- Button:Lower() - Reduces the frame's frame level below all other frames in its strata
- Button:Raise() - Increases the frame's frame level above all other frames in its strata
- Button:RegisterAllEvents() - Registers the frame for all events
- Button:RegisterEvent("event") - Registers the frame for an [[docs/events|event]]
- Button:RegisterForDrag(...) - Registers the frame for dragging
- Button:SetAllPoints([region]) or Button:SetAllPoints(["name"]) - Sets all anchor points of the region to match those of another region
- Button:SetAlpha(alpha) - Sets the opacity of the region relative to its parent
- Button:SetAttribute("name", value) - Sets a secure frame attribute
- Button:SetBackdrop(backdrop) - Sets a backdrop graphic for the frame
- Button:SetBackdropBorderColor(red, green, blue [, alpha]) - Sets a shading color for the frame's border graphic
- Button:SetBackdropColor(red, green, blue [, alpha]) - Sets a shading color for the frame's background graphic
- Button:SetClampRectInsets(left, right, top, bottom) - Sets offsets from the frame's edges used when limiting user movement or resizing of the frame
- Button:SetClampedToScreen(enable) - Sets whether the frame's boundaries should be limited to those of the screen
- Button:SetDepth(depth) - Sets the 3D depth of the frame (for stereoscopic 3D configurations)
- Button:SetFrameLevel(level) - Sets the level at which the frame is layered relative to others in its strata
- Button:SetFrameStrata("strata") - Sets the general layering strata of the frame
- Button:SetHeight(height) - Sets the region's height
- Button:SetHitRectInsets(left, right, top, bottom) - Sets the insets from the frame's edges which determine its mouse-interactable area
- Button:SetID(id) - Sets a numeric identifier for the frame
- Button:SetMaxResize(maxWidth, maxHeight) - Sets the maximum size of the frame for user resizing
- Button:SetMinResize(minWidth, minHeight) - Sets the minimum size of the frame for user resizing
- Button:SetMovable(enable) - Sets whether the frame can be moved by the user
- Button:SetParent(frame) or Button:SetParent("name") - Makes another frame the parent of this region
- Button:SetPoint("point" [, relativeTo [, "relativePoint" [, xOffset [, yOffset]]]]) - Sets an anchor point for the region
- Button:SetResizable(enable) - Sets whether the frame can be resized by the user
- Button:SetScale(scale) - Sets the frame's scale factor
- Button:SetScript("scriptType", handler) - Sets the widget's handler function for a script
- Button:SetSize(width, height) - Sets the size of the region to the specified values
- Button:SetToplevel(enable) - Sets whether the frame should automatically come to the front when clicked
- Button:SetUserPlaced(enable) - Flags the frame for automatic saving and restoration of position and dimensions
- Button:SetWidth(width) - Sets the region's width
- Button:Show() - Shows the region
- Button:StartMoving() - Begins repositioning the frame via mouse movement
- Button:StartSizing() - Begins resizing the frame via mouse movement
- Button:StopAnimating() - Stops any active animations involving the region or its children
- Button:StopMovingOrSizing() - Ends movement or resizing of the frame initiated with [[docs/widgets/Frame/StartMoving|`:StartMoving()`]] or [[docs/widgets/Frame/StartSizing|`:StartSizing()`]]
- Button:UnregisterAllEvents() - Unregisters the frame from any [[docs/events|events]] for which it is registered
- Button:UnregisterEvent("event") - Unregisters the frame for an event
Script Handlers
- OnAttributeChanged(self, "name", value) - Run when a frame attribute is changed
- OnChar(self, "text") - Run for each text character typed in the frame
- OnClick(self, "button", down) - Run when the button is clicked
- OnDisable(self) - Run when the frame is disabled
- OnDoubleClick(self, "button") - Run when the button is double-clicked
- OnDragStart(self, "button") - Run when the mouse is dragged starting in the frame
- OnDragStop(self) - Run when the mouse button is released after a drag started in the frame
- OnEnable(self) - Run when the frame is enabled
- OnEnter(self, motion) - Run when the mouse cursor enters the frame's interactive area
- OnEvent(self, "event", ...) - Run whenever an [[docs/events|event]] fires for which the frame is registered
- OnHide(self) - Run when the frame's visbility changes to hidden
- OnKeyDown(self, "key") - Run when a keyboard key is pressed if the frame is keyboard enabled
- OnKeyUp(self, "key") - Run when a keyboard key is released if the frame is keyboard enabled
- OnLeave(self, motion) - Run when the mouse cursor leaves the frame's interactive area
- OnLoad(self) - Run when the frame is created
- OnMouseDown(self, "button") - Run when a mouse button is pressed while the cursor is over the frame
- OnMouseUp(self, "button") - Run when the mouse button is released following a mouse down action in the frame
- OnMouseWheel(self, delta) - Run when the frame receives a mouse wheel scrolling action
- OnReceiveDrag(self) - Run when the mouse button is released after dragging into the frame
- OnShow(self) - Run when the frame becomes visible
- OnSizeChanged(self, width, height) - Run when a frame's size changes
- OnUpdate(self, elapsed) - Run each time the screen is drawn by the game engine
- PostClick(self, "button", down) - Run immediately following the button's `OnClick` handler with the same arguments
- PreClick(self, "button", down) - Run immediately before the button's `OnClick` handler with the same arguments