SizeUnit
Table of contents
Structure which is used to set the values of various size-related properties such as: "width", "height" etc. Declared as:
type SizeUnit struct {
Type SizeUnitType
Value float64
Function SizeFunc
}
Member | Type | Description |
---|---|---|
Function | SizeFunc |
Interface which is used to calculate SizeUnit value. See SizeFunc for details. When set this value then Type must be set to SizeFunction |
Type | SizeUnitType |
Type of the unit, see below |
Value | float64 |
Value |
where possible values for Type are:
Value | Constant | Description |
---|---|---|
0 |
Auto |
default value. The Value field is ignored |
1 |
SizeInPixel |
the Value field specifies the size in pixels |
2 |
SizeInEM |
the Value field specifies the size in em units. 1em is equal to the base font size, which is set in the browser settings |
3 |
SizeInEX |
the Value field specifies the size in ex units |
4 |
SizeInPercent |
the Value field specifies the size as a percentage of the parent element size |
5 |
SizeInPt |
the Value field specifies the size in pt units (1pt = 1/72") |
6 |
SizeInPc |
the Value field specifies the size in pc units (1pc = 12pt) |
7 |
SizeInInch |
the Value field specifies the size in inches |
8 |
SizeInMM |
the Value field specifies the size in millimeters |
9 |
SizeInCM |
the Value field defines the size in centimeters |
10 |
SizeInFraction |
the Value field specifies the size in parts. Used only for sizing cells of the GridLayout |
11 |
SizeFunction |
the Function field specifies a function for calculating the size. The Value field is ignored |
In resource files SizeUnit
values are represented by number values with specific suffix added, see below:
Suffix | Resulting type of SizeUnit |
---|---|
px | SizeInPixel |
em | SizeInEM |
ex | SizeInEX |
% | SizeInPercent |
pt | SizeInPt |
pc | SizeInPc |
in | SizeInInch |
mm | SizeInMM |
cm | SizeInCM |
fr | SizeInFraction |
and special size "auto"(also "none" and "" mapped to this value)
Also it is possible to use text representation of floating point values and integers which will be converted into SizeUnit
with type set to SizeInPixel
Examples
"100%"
"10em"
"3fr"
"64pt"
"25mm"
"auto"
"1.5"
"2"
rui.Percent(100)
rui.Em(10)
rui.Fr(3)
rui.Pt(64)
rui.Mm(25)
rui.AutoSize()
Create from source
func AutoSize() SizeUnit
Creates SizeUnit
with Auto
type
func Cm[T float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](value T) SizeUnit
Creates SizeUnit
with SizeInCM
type
func Em[T float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](value T) SizeUnit
Creates SizeUnit
with SizeInEM
type
func Ex[T float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](value T) SizeUnit
Creates SizeUnit
with SizeInEX
type
func Fr[T float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](value T) SizeUnit
Creates SizeUnit
with SizeInFraction
type
func Inch[T float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](value T) SizeUnit
Creates SizeUnit
with SizeInInch
type
func Mm[T float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](value T) SizeUnit
Creates SizeUnit
with SizeInMM
type
func Pc[T float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](value T) SizeUnit
Creates SizeUnit
with SizeInPc
type
func Percent[T float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](value T) SizeUnit
Creates SizeUnit
with SizeInPercent
type
func Pt[T float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](value T) SizeUnit
Creates SizeUnit
with SizeInPt
type
func Px[T float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](value T) SizeUnit
Creates SizeUnit
with SizeInPixel
type
Create from resource
View {
width = 100%,
}
View {
width = 20em,
}
View {
width = 20cm,
}
Related global functions
func StringToSizeUnit(value string) (SizeUnit, bool)
Converts the string argument to SizeUnit