Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
m (→‎Handlers: -> "Scripts")
Tag: WoW API docs
Tag: WoW API docs
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{widget}}
+
{{widget}} {{tocright}}
<onlyinclude><includeonly><div style="font-size:smaller; float:right;">{{Edit|UIOBJECT Button|Edit Button}}</div></includeonly>{{api|t=o|Button}} (inherits from [[#Frame|Frame]]) responds to {{api|t=wh|OnClick|mouse clicks}}.</onlyinclude> A button might appear different whether it is pushed, normal (depressed), or highlighted (hovered).
+
<onlyinclude><includeonly><div style="font-size:smaller; float:right;">{{Edit|UIOBJECT Button|Edit Button}}</div></includeonly>[[UIOBJECT Button|Button]] (inherits from {{api|t=o|Frame}})</onlyinclude>
   
  +
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.
{{api|t=o|CheckButton}} and {{api|t=o|ItemButton}} further extend this widget type.
 
   
  +
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.
== Construction ==
 
=== Lua ===
 
With "Button" as the first argument to {{api|CreateFrame()}}
 
<syntaxhighlight lang="lua">
 
local button = CreateFrame("Button", "MyButton", UIParent)
 
</syntaxhighlight>
 
   
  +
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.
=== XML ===
 
With a {{api|t=x|Button}} element in an XML file.
 
<syntaxhighlight lang="xml">
 
<Button name="MyButton" parent="UIParent">
 
<!-- insert anchors, scripts, children and other components here in XML -->
 
</Button>
 
</syntaxhighlight>
 
   
  +
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.
== Methods ==
 
  +
===Button===
 
  +
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 ==
 
<onlyinclude>{{#switch:{{{t|widgetmethod}}}|w|wm|widgetmethod=
 
<onlyinclude>{{#switch:{{{t|widgetmethod}}}|w|wm|widgetmethod=
:; Interaction
 
 
: {{api|t=w|Button:Click()}} - Execute the click action of the button.
 
: {{api|t=w|Button:Click()}} - Execute the click action of the button.
 
: {{api|t=w|Button:Disable()}} - Disable the Button so that it cannot be clicked.
 
: {{api|t=w|Button:Disable()}} - Disable the Button so that it cannot be clicked.
 
: {{api|t=w|Button:Enable()}} - Enable to the Button so that it may be clicked.
 
: {{api|t=w|Button:Enable()}} - Enable to the Button so that it may be clicked.
 
: {{api|t=w|Button:GetButtonState()}} - Return the current state ("PUSHED","NORMAL") of the Button.
 
: {{api|t=w|Button:GetButtonState()}} - Return the current state ("PUSHED","NORMAL") of the Button.
 
: {{api|t=w|Button:GetDisabledFontObject()}} - Return the font object for the Button when disabled - New in 1.10.
 
: {{api|t=w|Button:GetDisabledTexture()}} - Get the texture for this button when disabled - New in 1.11.
 
: {{api|t=w|Button:GetFontString()}} - Get this button's label FontString - New in 1.11.
 
: {{api|t=w|Button:GetHighlightFontObject()}} - Return the font object for the Button when highlighted - New in 1.10.
 
: {{api|t=w|Button:GetHighlightTexture()}} - Get the texture for this button when highlighted.
 
: {{api|t=w|Button:GetMotionScriptsWhileDisabled()}} - Get whether the button is allowed to run its OnEnter and OnLeave scripts even while disabled - New in 3.3.
 
: {{api|t=w|Button:GetMotionScriptsWhileDisabled()}} - Get whether the button is allowed to run its OnEnter and OnLeave scripts even while disabled - New in 3.3.
 
: {{api|t=w|Button:GetNormalFontObject()}} - Get the Font Object of the button.
 
: {{api|t=w|Button:GetNormalTexture()}} - Get the normal texture for this button - New in 1.11.
 
: {{api|t=w|Button:GetNormalTexture()}} - Get the normal texture for this button - New in 1.11.
 
: {{api|t=w|Button:GetPushedTextOffset()}} - Get the text offset when this button is pushed (x, y) - New in 1.11.
 
: {{api|t=w|Button:GetPushedTexture()}} - Get the texture for this button when pushed - New in 1.11.
 
: {{api|t=w|Button:GetPushedTexture()}} - Get the texture for this button when pushed - New in 1.11.
 
: {{api|t=w|Button:GetText()}} - Get the text label for the Button.
 
: {{api|t=w|Button:GetTextHeight()}} - Get the height of the Button's text.
 
: {{api|t=w|Button:GetTextWidth()}} - Get the width of the Button's text.
 
: {{api|t=w|Button:IsEnabled()}} - Determine whether the Button is enabled.
 
: {{api|t=w|Button:IsEnabled()}} - Determine whether the Button is enabled.
: {{api|t=w|Button:RegisterForClicks(clickType[,clickType...])}} - Specify which mouse button up/down actions cause this button to receive an OnClick notification.
+
: {{api|t=w|Button:LockHighlight()}} - Set the Button to always be drawn highlighted.
  +
: {{api|t=w|Button:RegisterForClicks(clickType1 [, clickType2, ...])}} - Specify which mouse button up/down actions cause this button to receive an OnClick notification.
 
: {{api|t=w|Button:RegisterForMouse()}}
 
: {{api|t=w|Button:RegisterForMouse()}}
 
: {{api|t=w|Button:SetButtonState(state[, lock])}} - Set the state of the Button ("PUSHED", "NORMAL") and whether it is locked.
 
: {{api|t=w|Button:SetButtonState(state[, lock])}} - Set the state of the Button ("PUSHED", "NORMAL") and whether it is locked.
: {{api|t=w|Button:SetEnabled(boolean)}} - Same as Enable() or Disable()
 
: {{api|t=w|Button:SetMotionScriptsWhileDisabled([bool])}} - Set whether button should fire its OnEnter and OnLeave scripts even while disabled - New in 3.3.
 
 
:; Appearance
 
: {{api|t=w|Button:GetDisabledTexture()}} - Get the texture for this button when disabled - New in 1.11.
 
: {{api|t=w|Button:GetHighlightTexture()}} - Get the texture for this button when highlighted.
 
: {{api|t=w|Button:LockHighlight()}} - Set the Button to always be drawn highlighted.
 
 
: {{api|t=w|Button:SetDisabledAtlas(atlasName)}}
 
: {{api|t=w|Button:SetDisabledAtlas(atlasName)}}
 
: {{api|t=w|Button:SetDisabledFontObject([font])}} - Set the font object for settings when disabled - New in 1.10.
 
: {{api|t=w|Button:SetDisabledTexture(texture or texturePath)}} - Set the disabled texture for the Button - Updated in 1.10.
 
: {{api|t=w|Button:SetDisabledTexture(texture or texturePath)}} - Set the disabled texture for the Button - Updated in 1.10.
 
: {{api|t=w|Button:SetEnabled(boolean)}} - Same as Enable() or Disable()
 
: {{api|t=w|Button:SetFontString(fontString)}} - Set the button's label FontString - New in 1.11.
 
: {{api|t=w|Button:SetFormattedText(formatstring[, ...])}} - Set the formatted text label for the Button. - New in 2.3.
 
: {{api|t=w|Button:SetHighlightAtlas(atlasName[, blendmode)}}
 
: {{api|t=w|Button:SetHighlightAtlas(atlasName[, blendmode)}}
 
: {{api|t=w|Button:SetHighlightFontObject([font])}} - Set the font object for settings when highlighted - New in 1.10.
 
: {{api|t=w|Button:SetHighlightTexture(texture or texturePath[,alphaMode])}} - Set the highlight texture for the Button.
 
: {{api|t=w|Button:SetHighlightTexture(texture or texturePath[,alphaMode])}} - Set the highlight texture for the Button.
 
: {{api|t=w|Button:SetMotionScriptsWhileDisabled([bool])}} - Set whether button should fire its OnEnter and OnLeave scripts even while disabled - New in 3.3.
 
: {{api|t=w|Button:SetNormalAtlas(atlasName)}}
 
: {{api|t=w|Button:SetNormalAtlas(atlasName)}}
 
: {{api|t=w|Button:SetNormalFontObject(FontObject)}} - Set the Font Object of the button.
 
: {{api|t=w|Button:SetNormalTexture(texture or texturePath)}} - Set the normal texture for the Button - Updated in 1.10.
 
: {{api|t=w|Button:SetNormalTexture(texture or texturePath)}} - Set the normal texture for the Button - Updated in 1.10.
: {{api|t=w|Button:UnlockHighlight()}} - Set the Button to not always be drawn highlighted.
 
 
: {{api|t=w|Button:SetPushedAtlas(atlasName)}}
 
: {{api|t=w|Button:SetPushedAtlas(atlasName)}}
 
: {{api|t=w|Button:SetPushedTextOffset(x, y)}} - Set the text offset for this button when pushed - New in 1.11.
 
: {{api|t=w|Button:SetPushedTexture(texture or texturePath)}} - Set the pushed texture for the Button - Updated in 1.10.
 
: {{api|t=w|Button:SetPushedTexture(texture or texturePath)}} - Set the pushed texture for the Button - Updated in 1.10.
 
:; Label
 
: {{api|t=w|Button:GetDisabledFontObject()}} - Return the font object for the Button when disabled - New in 1.10.
 
: {{api|t=w|Button:GetFontString()}} - Get this button's label FontString - New in 1.11.
 
: {{api|t=w|Button:GetHighlightFontObject()}} - Return the font object for the Button when highlighted - New in 1.10.
 
: {{api|t=w|Button:GetNormalFontObject()}} - Get the Font Object of the button.
 
: {{api|t=w|Button:GetPushedTextOffset()}} - Get the text offset when this button is pushed (x, y) - New in 1.11.
 
: {{api|t=w|Button:GetText()}} - Get the text label for the Button.
 
: {{api|t=w|Button:GetTextHeight()}} - Get the height of the Button's text.
 
: {{api|t=w|Button:GetTextWidth()}} - Get the width of the Button's text.
 
: {{api|t=w|Button:SetDisabledFontObject([font])}} - Set the font object for settings when disabled - New in 1.10.
 
: {{api|t=w|Button:SetFontString(fontString)}} - Set the button's label FontString - New in 1.11.
 
: {{api|t=w|Button:SetFormattedText(formatstring[, ...])}} - Set the formatted text label for the Button. - New in 2.3.
 
: {{api|t=w|Button:SetHighlightFontObject([font])}} - Set the font object for settings when highlighted - New in 1.10.
 
: {{api|t=w|Button:SetNormalFontObject(FontObject)}} - Set the Font Object of the button.
 
: {{api|t=w|Button:SetPushedTextOffset(x, y)}} - Set the text offset for this button when pushed - New in 1.11.
 
 
: {{api|t=w|Button:SetText(text)}} - Set the text label for the Button.
 
: {{api|t=w|Button:SetText(text)}} - Set the text label for the Button.
 
: {{api|t=w|Button:UnlockHighlight()}} - Set the Button to not always be drawn highlighted.
 
}}</onlyinclude>
 
}}</onlyinclude>
   
  +
== Defined Script Handlers ==
=== Frame ===
 
{{:UIOBJECT Frame|t=w}}
 
 
=== Region ===
 
{{:UIOBJECT Region|t=w}}
 
 
=== UIObject ===
 
{{:UIOBJECT UIObject|t=w}}
 
 
=== ScriptObject ===
 
{{:UIOBJECT ScriptObject|t=w}}
 
 
== Scripts ==
 
=== Button ===
 
 
<onlyinclude>{{#switch:{{{t|widgethandler}}}|wh|widgethandler=
 
<onlyinclude>{{#switch:{{{t|widgethandler}}}|wh|widgethandler=
: {{api|t=wh|OnClick}}(self, button, down) - Run when the button is clicked.
+
: {{api|t=wh|OnClick(self, button, down)}} - Run when clicking a button.
: {{api|t=wh|OnDoubleClick}}(self, button) - Run when the button is double-clicked.
+
: {{api|t=wh|OnDoubleClick(self, button)}} - Run when double-clicking a button.
: {{api|t=wh|PostClick}}(self, button, down) - Run immediately following the button's `OnClick` handler with the same arguments.
+
: {{api|t=wh|PostClick(self, button, down)}} - Run immediately after `OnClick`.
: {{api|t=wh|PreClick}}(self, button, down) - Run immediately before the button's `OnClick` handler with the same arguments.
+
: {{api|t=wh|PreClick(self, button, down)}} - Run immediately before `OnClick`.
 
}}</onlyinclude>
 
}}</onlyinclude>
   
=== Frame ===
+
== See also ==
{{:UIOBJECT Frame|t=wh}}
 
 
=== ScriptObject ===
 
{{:UIOBJECT ScriptObject|t=wh}}
 
 
== See Also ==
 
 
*[[SecureActionButtonTemplate]] - Allows protected functions
 
*[[SecureActionButtonTemplate]] - Allows protected functions
 
*[[SecureUnitButtonTemplate]] - Allows protected functions directed toward a [[UnitId]]
 
*[[SecureUnitButtonTemplate]] - Allows protected functions directed toward a [[UnitId]]
 
*[[InsecureActionButtonTemplate]] - Allows protected functions outside combat
 
*[[InsecureActionButtonTemplate]] - Allows protected functions outside combat
  +
  +
== External links ==
  +
<!-- Please read https://wow.gamepedia.com/Wowpedia:External_links_policy before adding new links. -->
  +
{{Elinks-api|nogit=|wowprog=http://wowprogramming.com/docs/widgets/Button.html}}

Revision as of 03:05, 7 July 2021

Button (inherits from Frame)

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() - Execute the click action of the button.
Button:Disable() - Disable the Button so that it cannot be clicked.
Button:Enable() - Enable to the Button so that it may be clicked.
Button:GetButtonState() - Return the current state ("PUSHED","NORMAL") of the Button.
Button:GetDisabledFontObject() - Return the font object for the Button when disabled - New in 1.10.
Button:GetDisabledTexture() - Get the texture for this button when disabled - New in 1.11.
Button:GetFontString() - Get this button's label FontString - New in 1.11.
Button:GetHighlightFontObject() - Return the font object for the Button when highlighted - New in 1.10.
Button:GetHighlightTexture() - Get the texture for this button when highlighted.
Button:GetMotionScriptsWhileDisabled() - Get whether the button is allowed to run its OnEnter and OnLeave scripts even while disabled - New in 3.3.
Button:GetNormalFontObject() - Get the Font Object of the button.
Button:GetNormalTexture() - Get the normal texture for this button - New in 1.11.
Button:GetPushedTextOffset() - Get the text offset when this button is pushed (x, y) - New in 1.11.
Button:GetPushedTexture() - Get the texture for this button when pushed - New in 1.11.
Button:GetText() - Get the text label for the Button.
Button:GetTextHeight() - Get the height of the Button's text.
Button:GetTextWidth() - Get the width of the Button's text.
Button:IsEnabled() - Determine whether the Button is enabled.
Button:LockHighlight() - Set the Button to always be drawn highlighted.
Button:RegisterForClicks(clickType1 [, clickType2, ...]) - Specify which mouse button up/down actions cause this button to receive an OnClick notification.
Button:RegisterForMouse()
Button:SetButtonState(state[, lock]) - Set the state of the Button ("PUSHED", "NORMAL") and whether it is locked.
Button:SetDisabledAtlas(atlasName)
Button:SetDisabledFontObject([font]) - Set the font object for settings when disabled - New in 1.10.
Button:SetDisabledTexture(texture or texturePath) - Set the disabled texture for the Button - Updated in 1.10.
Button:SetEnabled(boolean) - Same as Enable() or Disable()
Button:SetFontString(fontString) - Set the button's label FontString - New in 1.11.
Button:SetFormattedText(formatstring[, ...]) - Set the formatted text label for the Button. - New in 2.3.
Button:SetHighlightAtlas(atlasName[, blendmode)
Button:SetHighlightFontObject([font]) - Set the font object for settings when highlighted - New in 1.10.
Button:SetHighlightTexture(texture or texturePath[,alphaMode]) - Set the highlight texture for the Button.
Button:SetMotionScriptsWhileDisabled([bool]) - Set whether button should fire its OnEnter and OnLeave scripts even while disabled - New in 3.3.
Button:SetNormalAtlas(atlasName)
Button:SetNormalFontObject(FontObject) - Set the Font Object of the button.
Button:SetNormalTexture(texture or texturePath) - Set the normal texture for the Button - Updated in 1.10.
Button:SetPushedAtlas(atlasName)
Button:SetPushedTextOffset(x, y) - Set the text offset for this button when pushed - New in 1.11.
Button:SetPushedTexture(texture or texturePath) - Set the pushed texture for the Button - Updated in 1.10.
Button:SetText(text) - Set the text label for the Button.
Button:UnlockHighlight() - Set the Button to not always be drawn highlighted.

Defined Script Handlers

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

See also

External links