mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
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:
+19
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user