Dim
public class Dim
Describes a dimension which can be an absolute value, a percentage, fill, or a reference to a dimension of another view
To create a Dim
object, you can choose from one of the following options:
Dim.sized(n)
creates an absolute dimension of size nDim.percent(n)
creates a dimension that reprensents the n% of the containerDim.fill(margin)
creates a dimension that fills to the end of the container dimension, leaving the specified margin on the sideDim.width(view)
andDim.heigh(view)
are used to reference the computed width or height of another view.
Dim objects can be combined using the addition and substraction operators to create various rules, like for example:
password.width = Dim.width(login) - Dim(4)
-
Creates a percentage Pos object, the percentage is based on the dimension of the container This initializes a
TextField
that is centered horizontally, is 50% of the way down, is 30% the height, and is 80% the width of theit added to. var textView = TextView () textView.x = Pos.center (), textView.y = Pos.percent (50) textView.width = Dim.percent (80) textView.height = Dim.percent (30)
Declaration
Swift
public static func percent(n: Float) -> Dim
Parameters
n
A value between 0 and 100 representing the percentage.
remain
If
true
the Percent is computed based on the remaining space after the X/Y anchor positions. otherwise it is computed on the whole original space. -
Creates a dimension that fills until the end, leaving the specified margin at the end
Declaration
Swift
public static func fill(_ margin: Int = 0) -> Dim
Parameters
margin
optional, the margin to leave at the end
Return Value
a new dimension that can fill the dimension leaving the specified martin
-
Creates an Absolute
Dim
from the specified integer value.Declaration
Swift
public static func sized(_ n: Int) -> Dim
Parameters
n
the size to allocate
Return Value
a new dimension that is set to the absolute size
n
-
Produces a dimension that adds the two specified dimensions together
Declaration
Swift
public static func + (lhs: Dim, rhs: Dim) -> Dim
-
Produces a dimension that subtracts the second dimension value from the first
Declaration
Swift
public static func - (lhs: Dim, rhs: Dim) -> Dim
-
Produces a dimension that adds the two specified dimensions together
Declaration
Swift
public static func + (lhs: Dim, rhs: Int) -> Dim
-
Produces a dimension that subtracts the second dimension value from the first
Declaration
Swift
public static func - (lhs: Dim, rhs: Int) -> Dim
-
Creates a dimension that represents the width of the referenced view.
There should be no cycles in the references, if there is a cycle, the layout system will throw an error
- Paramter view: the view from which the width will be computed
Declaration
Swift
public static func width(view: View) -> Dim
-
Creates a dimension that represents the height of the referenced view.
There should be no cycles in the references, if there is a cycle, the layout system will throw an error
- Paramter view: the view from which the width will be computed
Declaration
Swift
public static func height(view: View) -> Dim