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 |
|
|
Pressed |
|
|
disabled |
|
|
Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
Foreground color for default state. |
normalBG |
|
|
Background color for default state. |
pressedFG |
|
|
Foreground color for pressed state. |
pressedBG |
|
|
Background color for pressed state. |
disabledFG |
|
|
Foreground color for disabled state. |
disabledBG |
|
|
Background color for disabled state. |
Returns:
Type |
Description |
---|---|
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 |
|
|
Flag if UI element has been clicked. |
disabled |
|
|
Flag if UI element has been disabled. |
Returns:
Type |
Description |
---|---|
|
Foreground color for current state of UI element. |
|
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.