Skip to content

ColorPicker

A color swatch with an optional label that opens Blizzard's ColorPickerFrame when clicked, with optional alpha (opacity) support.

Create with AceGUI:Create("ColorPicker"). It inherits the Common Widget API.

Widget type: ColorPicker

Methods

SetColor

method#
lua
widget:SetColor(r, g, b, a?)

Stores the current color and tints the swatch texture to match.

Parameters

ParameterTypeDefaultDescription
rnumberRed component in the 01 range.
gnumberGreen component in the 01 range.
bnumberBlue component in the 01 range.
a (optional)number1Alpha in the 01 range.

SetHasAlpha

method#
lua
widget:SetHasAlpha(HasAlpha)

Controls whether the color picker exposes the opacity slider. When alpha is disabled, the widget forces alpha to 1 in its callbacks.

Parameters

ParameterTypeDefaultDescription
HasAlphabooleantrue to allow editing the alpha channel.

SetLabel

method#
lua
widget:SetLabel(text?)

Sets the text shown to the right of the swatch.

Parameters

ParameterTypeDefaultDescription
text (optional)stringThe label string, or nil to clear.

SetDisabled

method#
lua
widget:SetDisabled(disabled)

Enables or disables the swatch. A disabled swatch will not open the color picker and its label is greyed.

Parameters

ParameterTypeDefaultDescription
disabledbooleantrue to disable, false to enable.

Defaults

On acquire the widget resets to: height 24, width 200, alpha disabled, color black opaque (0, 0, 0, 1), not disabled, and no label.

Callbacks

OnValueChanged

callback#
lua
OnValueChanged(r, g, b, a)

Fired live while the ColorPickerFrame is open and the color is changed (and not equal to the previous value). Subscribe with widget:SetCallback.

Parameters

ParameterTypeDefaultDescription
rnumberRed component in the 01 range.
gnumberGreen component in the 01 range.
bnumberBlue component in the 01 range.
anumberAlpha in the 01 range.

OnValueConfirmed

callback#
lua
OnValueConfirmed(r, g, b, a)

Fired once after the color picker is closed (on the final alpha callback), to signal the user committed a value, including via cancel which restores the original color. Subscribe with widget:SetCallback.

Parameters

ParameterTypeDefaultDescription
rnumberRed component in the 01 range.
gnumberGreen component in the 01 range.
bnumberBlue component in the 01 range.
anumberAlpha in the 01 range.

OnEnter

callback#
lua
OnEnter()

Fired when the mouse enters the swatch. Subscribe with widget:SetCallback.

OnLeave

callback#
lua
OnLeave()

Fired when the mouse leaves the swatch. Subscribe with widget:SetCallback.

Example

lua
local cp = AceGUI:Create("ColorPicker")
cp:SetLabel("Bar color")
cp:SetHasAlpha(true)
cp:SetColor(db.r, db.g, db.b, db.a)
cp:SetCallback("OnValueConfirmed", function(widget, event, r, g, b, a)
    db.r, db.g, db.b, db.a = r, g, b, a
end)

Ace3, a World of Warcraft addon framework.