ui: add Config.Sp and Config.Dp convenience methods

And rename Pixels to Val.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-05-16 19:32:47 +02:00
parent acf345a0f8
commit 00cb158247
7 changed files with 26 additions and 16 deletions
+12 -2
View File
@@ -22,8 +22,18 @@ type Config struct {
Now time.Time
}
// Pixels converts a value to unitless device pixels.
func (c *Config) Pixels(v Value) float32 {
// Dp converts a value in dp units to pixels.
func (c *Config) Dp(dp float32) float32 {
return c.PxPerDp * dp
}
// Sp converts a value in sp units to pixels.
func (c *Config) Sp(sp float32) float32 {
return c.PxPerSp * sp
}
// Val converts a value to pixels.
func (c *Config) Val(v Value) float32 {
switch v.U {
case UnitPx:
return v.V