ui/layout: replace Sized struct with simpler Constraint.Exact method

While here, add String methods to ui.Value and ui.Unit.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-10 11:14:28 +02:00
parent 4ec352727e
commit 25af3e3701
2 changed files with 41 additions and 25 deletions
+19
View File
@@ -2,6 +2,8 @@
package ui
import "fmt"
// Value is a value with a unit.
type Value struct {
V float32
@@ -34,3 +36,20 @@ func Dp(v float32) Value {
func Sp(v float32) Value {
return Value{V: v, U: UnitSp}
}
func (v Value) String() string {
return fmt.Sprintf("%g%s", v.V, v.U)
}
func (u Unit) String() string {
switch u {
case UnitPx:
return "px"
case UnitDp:
return "dp"
case UnitSp:
return "sp"
default:
panic("unknown unit")
}
}