Style

This is a class, that contains and handles styles for UI elements for different states.

Contents:

States

The possible states for UI element styles. The flag pressed refers to the flag of the UI element, that is raised when it gets clicked. The flag disabled refers to the flag of the UI element, that can be raised to disable said element.

State

pressed

disabled

Normal / Default

false

false

Pressed

true

false

disabled

true or false

true

Properties

Name

Type

Default

normalFG

number

colors.white

normalBG

number

colors.gray

pressedFG

number

colors.white

pressedBG

number

colors.lime

disabledFG

number

colors.gray

disabledBG

number

colors.lightGray

normalFG

Foreground color in default state.

uilib.Style.normalFG = colors.white
  • Type: number

  • Default: colors.white

Note

It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.


normalBG

Background color in default state.

uilib.Style.normalBG = colors.gray
  • Type: number

  • Default: colors.gray

Note

It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.


pressedFG

Foreground color in pressed state.

uilib.Style.pressedFG = colors.white
  • Type: number

  • Default: colors.white

Note

It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.


pressedBG

Background color in pressed state.

uilib.Style.pressedBG = colors.lime
  • Type: number

  • Default: colors.lime

Note

It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.


disabledFG

Foreground color in disabled state.

uilib.Style.disabledFG = colors.gray
  • Type: number

  • Default: colors.gray

Note

It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.


disabledBG

Background color in disabled state.

uilib.Style.disabledBG = colors.lightGray
  • Type: number

  • Default: colors.lightGray

Note

It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.


Functions

new()

Creates a new instance of Style and returns it.

function uilib.Style:new(normalFG, normalBG, pressedFG, pressedBG, disabledFG, disabledBG)
    ...
    return style
end

Arguments:

Name

Type

Default

Description

normalFG

number

colors.white

Foreground color for default state.

normalBG

number

colors.gray

Background color for default state.

pressedFG

number

colors.white

Foreground color for pressed state.

pressedBG

number

colors.lime

Background color for pressed state.

disabledFG

number

colors.gray

Foreground color for disabled state.

disabledBG

number

colors.lightGray

Background color for disabled state.

Returns:

Type

Description

Style

Instance of Style with specified properties.

Example:

local uilib = require("uilib")
local style = uilib.Style:new(colors.red. colors.lightGray)

This would create an instance of Style with colors.red as normalFG and colors.lightGray as normalBG. All other properties would be set to their respective default value.


getColors()

Returns the foreground and background color for the current state of the UI element.

function uilib.Style:getColors(pressed, disabled)
    ...
    return fg, bg
end

Arguments:

Name

Type

Default

Description

pressed

boolean

false

Flag if UI element has been clicked.

disabled

boolean

false

Flag if UI element has been disabled.

Returns:

Type

Description

number

Foreground color for current state of UI element.

number

Background color for current state of UI element.

Example:

local uilib = require("uilib")
local style = uilib.Style:new(colors.red. colors.lightGray)
local fg, bg = style:getColors(false, false)

This would create an instance of Style with colors.red as normalFG and colors.lightGray as normalBG. After that it would get the foregournd and background color for the default state, since pressed and disabled are both false. So fg and bg would contain colors.red and colors.lightGray respectively.