ColorPicker

Package: Libraries.Interface.Controls · Inherits from: Libraries.Interface.Events.FocusListener, Libraries.Interface.Controls.Control, Libraries.Interface.Events.SliderListener, Libraries.Interface.Events.TextChangeListener, Libraries.Interface.Item, Libraries.Interface.Item2D, Libraries.Interface.Events.MouseListener, Libraries.Language.Object

A ColorPicker is the content of the pop-over a ColorWell opens to choose a color. From the top, it holds a HueRing around a SaturationBrightnessSquare, then red, green and blue SliderFields from 0 to 255, a field for the hex code, such as "#4A5A6E", with the color's name beside it, 16 ColorSwatch buttons in one group, and the Cancel and OK buttons. Changing any part updates the others, and the well shows the color as it changes. Tab moves through the ring, the square, the red, green and blue sliders and their number fields, the hex field, the swatches, Cancel and OK. Enter or OK keeps the color; Escape, Cancel or a click outside the pop-over puts the old color back. Either way the pop-over closes and the focus goes back to the well. For screen readers, the picker is a group named after its well, such as "Fog color". The ring says its degrees and the hue's name, the square its saturation, brightness and color, and each swatch its hex code and name, such as "#FF0000, red". Programs don't usually make a ColorPicker themselves: a ColorWell makes one the first time it opens.

Example Code

use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.ColorWell
use Libraries.Game.Graphics.Color

Form form
Page page = form:GetMainPage()

Color gray
gray:SetHexColor("#4A5A6E")
// Pressing the well opens its ColorPicker below it.
ColorWell fog = page:AddColorWell("Fog color", gray)

form:Display()

Actions

Accept()

This action keeps the color and closes the picker, as OK and Enter do. The well's listeners are told of the change, as final.

Example

use Libraries.Interface.Controls.ColorPicker
ColorPicker picker
picker:Accept()

AllowsAlpha()

This action returns whether the hex field shows and takes the alpha.

Returns

boolean: True if the alpha is shown.

Example

use Libraries.Interface.Controls.ColorPicker
ColorPicker picker
boolean alpha = picker:AllowsAlpha()

Cancel()

This action puts the old color back and closes the picker, as Cancel, Escape and a click outside it do.

Example

use Libraries.Interface.Controls.ColorPicker
ColorPicker picker
picker:Cancel()

ClickedMouse(Libraries.Interface.Events.MouseEvent event)

This action is told of mouse clicks on the pop-over's layer that miss the pop-over: the picker cancels. A click on the well itself stops here, so it closes the picker rather than opening it again; any other click goes on to what is under it.

Parameters

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Events.MouseEvent
ColorPicker picker
MouseEvent event
picker:ClickedMouse(event)

GainedFocus(Libraries.Interface.Events.FocusEvent event)

This action is told when the swatch group or the hex field gains the focus. Once the group has the focus, the arrow keys choose swatches.

Parameters

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Events.FocusEvent
ColorPicker picker
FocusEvent event
picker:GainedFocus(event)

GetBlueField()

This action returns the slider field for blue, from 0 to 255.

Returns

Libraries.Interface.Controls.SliderField: The blue field.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.SliderField
ColorPicker picker
SliderField blue = picker:GetBlueField()

GetCancelButton()

This action returns the Cancel button.

Returns

Libraries.Interface.Controls.Button: The button.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.Button
ColorPicker picker
Button cancel = picker:GetCancelButton()

GetColor()

This action returns a copy of the color the picker shows.

Returns

Libraries.Game.Graphics.Color: The color.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Game.Graphics.Color
ColorPicker picker
Color color = picker:GetColor()

GetColorWell()

This action returns the well this picker belongs to, or undefined.

Returns

Libraries.Interface.Controls.ColorWell: The color well.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.ColorWell
ColorPicker picker
ColorWell well = picker:GetColorWell()

GetGreenField()

This action returns the slider field for green, from 0 to 255.

Returns

Libraries.Interface.Controls.SliderField: The green field.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.SliderField
ColorPicker picker
SliderField green = picker:GetGreenField()

GetHexField()

This action returns the hex field.

Returns

Libraries.Interface.Controls.TextField: The field.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.TextField
ColorPicker picker
TextField field = picker:GetHexField()

GetHexText()

This action returns the color's hex code as the hex field shows it, such as "#4A5A6E", with the alpha when it is allowed.

Returns

text: The hex code.

Example

use Libraries.Interface.Controls.ColorPicker
ColorPicker picker
text hex = picker:GetHexText()

GetHueRing()

This action returns the hue ring.

Returns

Libraries.Interface.Controls.HueRing: The ring.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.HueRing
ColorPicker picker
HueRing ring = picker:GetHueRing()

GetOKButton()

This action returns the OK button.

Returns

Libraries.Interface.Controls.Button: The button.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.Button
ColorPicker picker
Button ok = picker:GetOKButton()

GetRedField()

This action returns the slider field for red, from 0 to 255.

Returns

Libraries.Interface.Controls.SliderField: The red field.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.SliderField
ColorPicker picker
SliderField red = picker:GetRedField()

GetSaturationBrightnessSquare()

This action returns the saturation and brightness square.

Returns

Libraries.Interface.Controls.SaturationBrightnessSquare: The square.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.SaturationBrightnessSquare
ColorPicker picker
SaturationBrightnessSquare square = picker:GetSaturationBrightnessSquare()

GetSwatchGroup()

This action returns the group of swatches.

Returns

Libraries.Interface.Controls.ButtonGroup: The group.

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.ButtonGroup
ColorPicker picker
ButtonGroup swatches = picker:GetSwatchGroup()

IsAccessibleParent()

This action tells accessibility tools, such as screen readers, that the picker is a group holding its parts.

Returns

boolean: true, because the picker contains its parts for accessibility.

Example

use Libraries.Interface.Controls.ColorPicker
ColorPicker picker
boolean holds = picker:IsAccessibleParent()

IsHoldingSwatchSelection()

This action returns true while the swatch group is gaining the focus. A group of radio buttons chooses one as it gains the focus; the swatches don't take that choice, so moving to them doesn't change the color. ColorSwatch asks this, so most users won't need to.

Returns

boolean: True while a swatch shouldn't be chosen by the group gaining the focus.

Example

use Libraries.Interface.Controls.ColorPicker
ColorPicker picker
boolean holding = picker:IsHoldingSwatchSelection()

LoadGraphics(Libraries.Interface.Layouts.LayoutProperties properties)

This action loads the view of the swatch group the first time, which draws an outline around the swatches while the group has the focus and none is chosen. The game engine calls this as needed, so most users won't need to call it directly.

Parameters

Example

use Libraries.Interface.Controls.ColorPicker
ColorPicker picker
picker:LoadGraphics(picker:GetDefaultLayoutProperties())

LostFocus(Libraries.Interface.Events.FocusEvent event)

This action is told when the swatch group or the hex field loses the focus. Leaving the hex field shows the color's code there again, in place of anything left half typed.

Parameters

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Events.FocusEvent
ColorPicker picker
FocusEvent event
picker:LostFocus(event)

ReleasedMouse(Libraries.Interface.Events.MouseEvent event)

This action is told when a mouse button comes up on the pop-over's layer. It does nothing.

Parameters

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Events.MouseEvent
ColorPicker picker
MouseEvent event
picker:ReleasedMouse(event)

SetAllowsAlpha(boolean allow)

This action sets whether the hex field shows and takes the alpha as well, as 8 hex digits such as "#4A5A6E80". Otherwise it shows 6, and 6 typed digits keep the color's alpha.

Parameters

  • allow boolean: True to show and take the alpha.

Example

use Libraries.Interface.Controls.ColorPicker
ColorPicker picker
picker:SetAllowsAlpha(true)

SetColor(Libraries.Game.Graphics.Color newColor)

This action sets the color the picker shows, as a program does: every part changes to match, but the well isn't told.

Parameters

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Game.Graphics.Color
Color color
ColorPicker picker
picker:SetColor(color:Teal())

SetColorWell(Libraries.Interface.Controls.ColorWell newWell)

This action sets the well this picker belongs to. The picker takes the well's name, which screen readers say as the focus enters it, and tells the well of each change, of OK and of Cancel. ColorWell calls this, so most users won't need to.

Parameters

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.ColorWell
ColorWell well
well:SetName("Fog color")
ColorPicker picker
picker:SetColorWell(well)

SliderChanged(Libraries.Interface.Events.SliderChangedEvent event)

This action is called when the user changes the hue ring, either of the square's sliders, or the red, green or blue field, with a key, the pointer, a typed number or a screen reader: the color changes, and the other parts and the well show it.

Parameters

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Events.SliderChangedEvent
ColorPicker picker
SliderChangedEvent event
event:SetSlider(picker:GetHueRing())
picker:SliderChanged(event)

SwatchChosen(Libraries.Interface.Controls.ColorSwatch swatch)

This action is called when the user chooses a swatch: the color becomes the swatch's, keeping the alpha, and the other parts and the well show it. ColorSwatch calls this, so most users won't need to.

Parameters

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Controls.ColorSwatch
use Libraries.Game.Graphics.Color
Color color
ColorSwatch swatch
swatch:SetColor(color:Red())
ColorPicker picker
picker:SwatchChosen(swatch)

TextChanged(Libraries.Interface.Events.TextChangeEvent event)

This action is called when the hex field's text changes. A complete hex code, 6 digits (or 8 when the alpha is allowed), with or without "#", changes the color; anything else waits for more typing.

Parameters

Example

use Libraries.Interface.Controls.ColorPicker
use Libraries.Interface.Events.TextChangeEvent
ColorPicker picker
TextChangeEvent event
picker:TextChanged(event)

Inherited Actions

261 actions from Libraries.Interface.Controls.Control
60 actions from Libraries.Interface.Item
202 actions from Libraries.Interface.Item2D
3 actions from Libraries.Language.Object