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:SetEnabled() - This function is not yet documented
- 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:GetPropagateKeyboardInput() - This function is not yet documented
- Button:IsForbidden() - This function is not yet documented
- Button:RegisterUnitEvent() - This function is not yet documented
- Button:SetDontSavePosition() - This function is not yet documented
- Button:SetPropagateKeyboardInput() - This function is not yet documented
- Button:SetShown() - This function is not yet documented
- 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