ColorWell

Package: Libraries.Interface.Controls · Inherits from: Libraries.Interface.Controls.Button, Libraries.Interface.Controls.Control, Libraries.Interface.Item, Libraries.Interface.Item2D, Libraries.Language.Object, Libraries.Interface.Events.TextureLoadListener

A ColorWell is a button that shows a color: a small square of it, then its hex code, such as "#4A5A6E". Pressing it, with the mouse, a finger, Space or Enter, opens a ColorPicker in a pop-over just below it, to choose a new color with a hue ring, a saturation and brightness square, swatches or a hex code. The well shows the color as it changes. OK or Enter keeps the new color; Cancel, Escape or a click outside the pop-over puts the old one back. Either way the focus comes back to the well. Listeners (AddColorWellListener) are told of each change while the picker is open, as not final, and once more, as final, when OK keeps a new color or a cancel puts the old one back. For screen readers, the well's name is its label, such as "Fog color", and its description is the color's hex code and then its name, such as "#4A5A6E, dim gray", kept up to date as the color changes. The hex code comes first because the name is only the closest of a list of named colors. Its colors come from the interface options under the key "ColorWell".

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")
ColorWell fog = page:AddColorWell("Fog color", gray)

form:Display()

Actions

Accept()

This action keeps the color chosen in the picker and closes it, as OK and Enter do. If the color changed since the picker opened, listeners are told, as final, with the color before it opened as the old color. The focus comes back to the well. ColorPicker calls this, so most users won't need to.

Example

use Libraries.Interface.Controls.ColorWell
ColorWell well
well:Open()
well:Accept()

Activate(Libraries.Interface.Events.BehaviorEvent event)

This action is called when the well is pressed: it runs the well's behavior, if it has one, then opens the picker, or closes it if it is open.

Parameters

Example

use Libraries.Interface.Controls.ColorWell
use Libraries.Interface.Events.BehaviorEvent
ColorWell well
BehaviorEvent event
event:SetItem(well)
well:Activate(event)

AddColorWellListener(Libraries.Interface.Events.ColorWellListener listener)

This action adds a listener, told when the user changes the color.

Parameters

Example

use Libraries.Interface.Controls.ColorWell
use Libraries.Interface.Events.ColorWellListener
ColorWellListener listener
ColorWell well
well:AddColorWellListener(listener)

AllowsAlpha()

This action returns whether the picker shows and takes the alpha.

Returns

boolean: True if the alpha is shown.

Example

use Libraries.Interface.Controls.ColorWell
ColorWell well
boolean alpha = well:AllowsAlpha()

Close()

This action closes the picker, if it is open, and puts back the color the well had when it opened, as Cancel, Escape and a click outside it do. If the color had changed, listeners are told, as final. The focus comes back to the well.

Example

use Libraries.Interface.Controls.ColorWell
ColorWell well
well:Open()
well:Close()

GetColor()

This action returns a copy of the well's color.

Returns

Libraries.Game.Graphics.Color: The color.

Example

use Libraries.Interface.Controls.ColorWell
use Libraries.Game.Graphics.Color
ColorWell well
Color color = well:GetColor()

GetColorPicker()

This action returns the picker the well opens, or undefined before it first opens.

Returns

Libraries.Interface.Controls.ColorPicker: The picker.

Example

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

GetColorText()

This action returns the words screen readers say for the color: the hex code, then the name of the closest named color, such as "#4A5A6E, dim gray".

Returns

text: The color's words.

Example

use Libraries.Interface.Controls.ColorWell
ColorWell well
text words = well:GetColorText()

IsOpen()

This action returns true while the picker is open.

Returns

boolean: True if the picker is showing.

Example

use Libraries.Interface.Controls.ColorWell
ColorWell well
boolean open = well:IsOpen()

LoadGraphics(Libraries.Interface.Layouts.LayoutProperties properties)

This action loads the button's graphics, then adds the square of color at its left. The game engine calls this as needed, so most users won't need to call it directly.

Parameters

Example

use Libraries.Interface.Controls.ColorWell
ColorWell well
well:LoadGraphics(well:GetDefaultLayoutProperties())

Open()

This action opens the picker in a pop-over just below the well, or above it if there's no room below, with the focus on the hue ring.

Example

use Libraries.Interface.Controls.ColorWell
ColorWell well
well:Open()

PreviewColor(Libraries.Game.Graphics.Color newColor)

This action shows a color the user is choosing in the picker: the well shows it, screen readers are told, and so are listeners, as not final. ColorPicker calls this, so most users won't need to.

Parameters

Example

use Libraries.Interface.Controls.ColorWell
use Libraries.Game.Graphics.Color
Color color
ColorWell well
well:PreviewColor(color:Orange())

RemoveColorWellListener(Libraries.Interface.Events.ColorWellListener listener)

This action removes a listener.

Parameters

Example

use Libraries.Interface.Controls.ColorWell
use Libraries.Interface.Events.ColorWellListener
ColorWellListener listener
ColorWell well
well:AddColorWellListener(listener)
well:RemoveColorWellListener(listener)

SetAllowsAlpha(boolean allow)

This action sets whether the picker's hex field shows and takes the alpha too, as 8 hex digits such as "#4A5A6E80". By default it shows 6, and the color's alpha is kept as it is.

Parameters

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

Example

use Libraries.Interface.Controls.ColorWell
ColorWell well
well:SetAllowsAlpha(true)

SetColor(Libraries.Game.Graphics.Color newColor)

This action sets the well's color, as a program does: the well shows it and screen readers are told, but listeners aren't. If the picker is open, it shows the color too.

Parameters

Example

use Libraries.Interface.Controls.ColorWell
use Libraries.Game.Graphics.Color
Color color
ColorWell well
well:SetColor(color:Teal())

SetHeight(number newHeight)

This action sets the height of the well, and keeps the square of color centered up and down.

Parameters

  • newHeight number: The new height.

Example

use Libraries.Interface.Controls.ColorWell
ColorWell well
well:SetHeight(32)

SetName(text name)

This action sets the well's name, which screen readers say before its color, such as "Fog color". Unlike other buttons, the well shows its color's hex code instead of its name.

Parameters

  • name text: The name.

Example

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

SetSize(number newWidth, number newHeight)

This action sets the width and height of the well, and keeps the square of color centered up and down.

Parameters

  • newWidth number: The new width.
  • newHeight number: The new height.

Example

use Libraries.Interface.Controls.ColorWell
ColorWell well
well:SetSize(140, 32)

Inherited Actions

20 actions from Libraries.Interface.Controls.Button
257 actions from Libraries.Interface.Controls.Control
60 actions from Libraries.Interface.Item
198 actions from Libraries.Interface.Item2D
3 actions from Libraries.Language.Object