ColorSwatch

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

A ColorSwatch is a radio button drawn as a square of one color, for choosing that color in a ColorPicker. Its name is the color's hex code and name, such as "#FF0000, red", which is what screen readers say for it. A ColorPicker puts its swatches in one ButtonGroup, so the arrow keys move among them and choose, as in any group of radio buttons. A selected swatch has a thick edge in a color that stands out from it; the selected swatch of a focused group has its edge in the focus color.

Example Code

use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Interface.Controls.ColorSwatch
use Libraries.Interface.Controls.ButtonGroup

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        Color color
        ButtonGroup group
        ColorSwatch red
        red:SetColor(color:Red())
        group:AddToGrouping(red)
        group:Add(red)
        Add(group)
    end
end

Actions

GetColor()

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

Returns

Libraries.Game.Graphics.Color: The color.

Example

use Libraries.Interface.Controls.ColorSwatch
use Libraries.Game.Graphics.Color
ColorSwatch swatch
Color color = swatch:GetColor()

GetColorPicker()

This action returns the color picker told when this swatch is chosen, or undefined.

Returns

Libraries.Interface.Controls.ColorPicker: The picker.

Example

use Libraries.Interface.Controls.ColorSwatch
use Libraries.Interface.Controls.ColorPicker
ColorSwatch swatch
ColorPicker picker = swatch:GetColorPicker()

LoadGraphics(Libraries.Interface.Layouts.LayoutProperties properties)

This action loads the radio button's graphics, then hides its circle and label and draws the square of color in their place. The game engine calls this as needed, so most users won't need to call it directly.

Parameters

Example

use Libraries.Interface.Controls.ColorSwatch
ColorSwatch swatch
swatch:LoadGraphics(swatch:GetDefaultLayoutProperties())

OnToggleOn()

This action is called each time the swatch is selected: the picker, if there is one, takes the swatch's color.

Example

use Libraries.Interface.Controls.ColorSwatch
ColorSwatch swatch
swatch:OnToggleOn()

RefreshChoiceFocus()

This action redraws the swatch's edge to match whether it is selected and whether it shows the focus.

Example

use Libraries.Interface.Controls.ColorSwatch
ColorSwatch swatch
swatch:RefreshChoiceFocus()

SetColor(Libraries.Game.Graphics.Color color)

This action sets the swatch's color. Its name becomes the color's hex code and name, such as "#FF0000, red".

Parameters

Example

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

SetColorPicker(Libraries.Interface.Controls.ColorPicker newPicker)

This action sets the color picker told when this swatch is chosen, or undefined for none. ColorPicker calls it for its swatches.

Parameters

Example

use Libraries.Interface.Controls.ColorSwatch
use Libraries.Interface.Controls.ColorPicker
ColorPicker picker
ColorSwatch swatch
swatch:SetColorPicker(picker)

SetToggleState(boolean toggleState)

This action sets whether the swatch is selected, as RadioButton's does, and redraws its edge. While the picker holds back the choice that a group makes on its own when it gains the focus, a swatch isn't selected that way, so tabbing to the swatches doesn't change the color.

Parameters

  • toggleState boolean: True to select the swatch.

Example

use Libraries.Interface.Controls.ColorSwatch
ColorSwatch swatch
swatch:SetToggleState(true)

Inherited Actions

21 actions from Libraries.Interface.Controls.Button
251 actions from Libraries.Interface.Controls.Control
12 actions from Libraries.Interface.Controls.RadioButton
11 actions from Libraries.Interface.Controls.ToggleButton
57 actions from Libraries.Interface.Item
198 actions from Libraries.Interface.Item2D
3 actions from Libraries.Language.Object