Lumen.Style libraryclient
Part of Lumen
Styles of Lumen elements. The style prop of an element is a table, and this library
resolves it into the form the panels and the layout engine read:
lengths are scaled to the screen resolution with math.scale (set scale = false in the
style to keep them as they are), shorthands are expanded, and colors and fonts may name
values of the active theme.
<view style={{ direction = 'row', gap = 8, padding = { 4, 12 }, background = 'main_dark' }}>
<text style={{ flex = 1, font = 'text_normal', color = 'text' }}>Name</text>
<text style={{ width = '25%', text_align = 'right', color = '#ff8800' }}>42</text>
</view>
The properties are:
- Size:
width,height,min_width,min_height,max_width,max_height. A number is a length, a string such as '50%' is a share of the parent's inner size, 'auto' (or nothing) lets the content decide. - Flex item:
flex(Number how much of the free space of the parent the element takes, 0 by default),margin(a length for all sides,{ vertical, horizontal },{ top, right, bottom, left }or{ top = n, left = n, ... }) along withmargin_top,margin_right,margin_bottomandmargin_left, andalign_self('start', 'center', 'end' or 'stretch', which overrides the parent'salignfor this element). - Flex container (
view,scroll):direction('column' by default or 'row'),justify('start', 'center', 'end', 'space_between', 'space_around' or 'space_evenly'),align('stretch' by default, 'start', 'center' or 'end'),gap(length between the children),wrap(Boolean start a new line when the children do not fit) andpadding(likemargin, withpadding_topand the others). - Looks:
background(Color),border(Color),border_width(1 by default),radius(rounded corners),alpha(0 to 255, the whole panel),cursor(such as 'hand'). - Text (
text,button):font,font_size(derives a copy of the font at that size),color,text_align('left', 'center' or 'right'),vertical_align('top', 'center' or 'bottom'),wrap_text(Boolean wrap long lines, true by default). - Button:
hover_background,active_background,disabled_color. - Position:
xandyplace an element that is mounted into a panel that is not a Lumen container at that spot (the layout engine positions everything else).
A color may be a Color, the name of a color of the active theme (Theme.get_color) or a
hex string ('#rgb', '#rrggbb' or '#rrggbbaa'). A font may be the name of a font of the
active theme (Theme.get_font) or the name of a font created with surface.CreateFont.
Summary
Functions
Functions
Keeps a length between the minimum and the maximum of a resolved style.
Parameters
- value Number
- min Number/Map resolved minimum, or nil
- max Number/Map resolved maximum, or nil
- available Number size that percentages refer to, nil if unknown
Returns
- Number
Resolves a color: a Color, the name of a theme color or a hex string.
Parameters
- value Any
Returns
- Color, or nil if there is no such color
Resolves a font: the name of a theme font or the name of a created font, at a size.
Parameters
- value String
- size Number optional, defaults to
nilsize to derive a copy of the font at, already scaled
Returns
- String name of the font, or nil if none was given
Turns a resolved size into pixels.
Parameters
- size Number/Map a resolved size: a length or
{ percent = n } - available Number the size of the parent that percentages refer to, nil if unknown
Returns
- Number pixels, or nil if the size is auto or a percentage of an unknown size
Resolves a style table into the form the panels and the layout engine read: scaled lengths, expanded boxes, Colors and font names. Defaults fill in what the style does not set.
Parameters
- style Map the style as written, or nil
- defaults Map optional, defaults to
nilthe default style of the element, in the same form asstyle
Returns
- Map the resolved style