Custom controls variables
Available variables
Screen size variables
screen_width: width of screen.
screen_height: height of screen.
Control variables
width: width of the control button itself.
height: height of the control button itself.
Position variables
top: top of screen, current is 0.
left: left of screen, current is 0.
right: right of screen, calculated as ${screen_width} - ${width} - ${margin}.
bottom: bottom of screen, calculated as ${screen_height} - ${height} - ${margin}.
Other variables
margin: margin, current is 2dp.
How does it work
Currently, variables are only apply for Dynamic X and Y, which in format ${variable}.
For example
"dynamicX": "${screen_width} - ${width} * 2 + ${margin}"
With these given properties:
- Screen width: 1280
- Button width: 100
- Margin: 2dp, convert into pixels unit: 4px
It will be converted into
"dynamicX": "1280 - 100 * 2 + 4"
Then, the x field (stored in the memory when paste a control json) is being calculated from dynamicX use exp4j.
ControlData controlData = ...
controlData.x = new ExpressionBuilder(controlData.dynamicX).build().evaluate();