Skip to content

Style and CSS ​

General ​

Blocks support setting layout parameters via style. Each block has its own set of style parameters.

Set the style for tf block:

python
(tf
    (style
        (fontSize = 32)
        (textColor = 0xFFFFFFFF)
    )
    (text = 'Hello world!!!')
)

Set the style for block block:

python
(block
    (style
        (backgroundColor = 0xffff0000)
        (width = 100px)
        (height = 100px)
    )
)

Set the style for mc block:

python
(mc 'Window_BG'
    (style
        (width=100)
        (height=50)
        ...
    )
)

Styles can be described in a separate definition and passed as a parameter to the block in class property.

Details
python
(def element TestView() layout = true
    (block
        (class BlockStyle)
    )
)
  
(def css BlockStyle()
    (backgroundColor = 0xffff0000)
    (width = 100px)
    (height = 100px)
)

The value for class property can be evaluated in an expression, so you can style blocks based on conditions.

Details
python
(def element TestView() layout = true
    (scope
        (event onClick)
        (var switcher:bool = false)
        (bind switcher "!switcher" init=false watch=false (event "onClick"))
    )
      
    (block
        (bind class "switcher ? 'BlockStyle_1' : 'BlockStyle_2'")
    )
  
    (element ButtonPrimary
        (scope
            (label = 'change style')
        )
        (dispatch onClick on='click')
    )
)
  
(def css BlockStyle_1()
    (backgroundColor = 0xffff0000)
    (width = 100px)
    (height = 100px)
)
  
(def css BlockStyle_2()
    (backgroundColor = 0xff00ff00)
    (width = 120px)
    (height = 130px)
    (alpha = 0.5)
)

If several styles with the same properties are applied to a block, the subsequent ones will overwrite the values ​​of the previous ones. The order of application is important.

Details
python
(block
    (class BlockStyle_1)    
    (class BlockStyle_2)    
)

NOTE

But if you change the style property directly in style and pass css as a parameter with the same property. Then the order of the styles is not important. style block will be executed last.

Details
python
(def element TestView() layout = true
    (block
        (style
            (backgroundColor = 0xffff0000)
            (width = 100px)
            (height = 100px)
        )
        (class BlockStyle_2)
    )
)
  
(def css BlockStyle_2()
    (backgroundColor = 0xff00ff00)
    (width = 120px)
    (height = 130px)
    (alpha = 0.5)
)

Style sheet ​

Block types:

  • Basic blocks: tf, mc, image, text_input;
  • Container blocks (inherited from base block): block (and all aliases hblock, vtile, gtile, reverse, hreverse), list, view_holder, slider, scroll_bar, progress, scrollArea.
PropertyCSS AnalogueSupportAccepted Value
widthwidthAllnumber, %, px
minWidthmin-widthAllnumber, %, px
maxWidthmax-widthAllnumber, %, px
heightheightAllnumber, %, px
minHeightmin-heightAllnumber, %, px
maxHeightmax-heightAllnumber, %, px
positionpositionAllabsolute, flow
leftleftAllnumber, %, px
rightrightAllnumber, %, px
toptopAllnumber, %, px
bottombottomAllnumber, %, px
centeroffset from centerAllnumber, %, px
hcenterhorizontal offset from centerAllnumber, %, px
vcentervertical offset from centerAllnumber, %, px
marginLeftmargin-leftAllnumber, %, px
marginRightmargin-rightAllnumber, %, px
marginTopmargin-topAllnumber, %, px
marginBottommargin-bottomAllnumber, %, px
paddingLeftpadding-leftcontainer blocksnumber, %, px
paddingRightpadding-rightcontainer blocksnumber, %, px
paddingToppadding-topcontainer blocksnumber, %, px
paddingBottompadding-bottomcontainer blocksnumber, %, px
paddingpaddingcontainer blocksnumber, %, px
backgroundColorbackground-colorcontainer blocks0xARGB
backgroundImagebackground-imagecontainer blocksstr, 'url: {url}', 'bitmap: {linkage}', 'symbol: {linkage}'
backgroundSizebackground-size
background-repeat
container blocksfill, crop, cover, repeat, autosize
flowflex-directioncontainer blocksFlow.HORISONTAL, Flow.VERTICAL, Flow.TILE_HORIZONTAL, Flow.TILE_VERTICAL
alignjustify-content
align-items
container blocksleft, right, bottom, top, center, middle
alphaopacityAllnumber from 0 to 1
fontSizefont-sizetfnumber
leadingline spacingtfnumber
letterSpacingletter-spacingtfnumber
fontFamilyfont-familytfstr
textColorcolortf0xRGB
textAligntext-aligntfleft, right, center
multilinewhite-spacetfbool
ubScaleXtransform: scaleX()Allnumber
ubScaleYtransform: scaleY()Allnumber
rotationrotate block if its position is absoluteAll with absolute positionnumber (rotation angle values ​​in degrees)
pivotXzero point on X
used for rotation, scale, absolute position
All with absolute positionnumber, %, px
pivotYzero point on Y
used for rotation, scale, absolute position
All with absolute positionnumber, %, px
scaleXX-axis scale
can be negative, applies to the block and its children
Alldouble
scaleYY-axis scale
can be negative, applies to the block and its children
Alldouble

backgroundSize ​

python
(def element NationFlagsSmall () layout=true
    (style
        (bind backgroundImage "'url:../nation_flags/small/flag_USA.png'" init=false)
        (backgroundSize = "fill")
        (width = 117)
        (height = 72)
    )
)
Details
  • cover - stretch the texture to fit the container while maintaining the texture's proportions so that it fills the entire area, cutting off the texture outside the container.
  • crop - crop the image to fit the container size.
  • fill - stretch the image to fit the container without preserving the proportions.
  • align - position the image in the center of the container, cutting off the texture outside the container.

backgroundRepeatX/backgroundRepeatY ​

python
(block
    (style
        (width = 42) (height = 42)
        (backgroundImage = 'url:../service_kit/icons/icon_warning_red.png')
        (backgroundRepeatX = true)
        (backgroundRepeatY = false)
    )
)

Repeat image horizontally and/or vertically. Disabled by default.

substitute ​

substitute - a textblock method that allows you to replace substrings with images.

python
(tf
    (class $TextDefault19NM)
    (bindcall substitute imageOffset="_frameTextCount"
                        substitutionMap={'[test_icon]' : 'icon_ground_radar_ally' }
                        sourceText='radar: [test_icon] mouse: [KEY_LEFTMOUSE]'
                        postfix='_bg'
                        init=true
    )
)

init=true - required argument

outline ​

Set the outline style for text.

CAUTION

Cannot be used for large amounts of text of varying sizes - the texture with glyphs quickly fills up and will affect performance.

It is not advisable to apply animation with scale to such text - there may be artifacts, etc.

python
(tf
    (class $TextDefault)
    (style
        (outlineColor = 0x08222A)   # outline color
        (outlineAlpha = 0.4)        # outline transparency
        (outlineThickness = 1)      # outline thickness
        (outlineScaled = false)     # whether the scale affect the outline thickness. When animating the text scale, always set it to `false`
    )
     
    (text = 'The quick brown fox jumps over the lazy dog. 1234567890?!-+')
)

scale9grid ​

The set of parameters is identical to background9Slice in unbound1.

python
(def element TestElement() layout=true
    (mc wows_logo
        (style
            (width = "500")
            (height = "500")
            (scale9grid = "rect(30)")
        )
    )
)