ui: add doc.go

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-03-31 14:45:26 +02:00
parent 354976bb01
commit 8b2f6dbf13
4 changed files with 45 additions and 15 deletions
+8 -13
View File
@@ -2,16 +2,24 @@
package ui
// Value is a value with a unit.
type Value struct {
V float32
U Unit
}
// Unit represents a unit for a Value.
type Unit uint8
const (
// UnitPx represent device pixels in the resolution of
// the underlying display.
UnitPx Unit = iota
// UnitDp represents device independent pixels. 1 dp will
// have the same apparent size across platforms and
// display resolutions.
UnitDp
// UnitSp is like UnitDp but for font sizes.
UnitSp
)
@@ -26,16 +34,3 @@ func Dp(v float32) Value {
func Sp(v float32) Value {
return Value{V: v, U: UnitSp}
}
func (c *Config) Pixels(v Value) float32 {
switch v.U {
case UnitPx:
return v.V
case UnitDp:
return c.PxPerDp * v.V
case UnitSp:
return c.PxPerSp * v.V
default:
panic("unknown unit")
}
}