diff --git a/README.md b/README.md index 1b8082f9..0a19baa9 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Gio implements portable immediate mode GUI programs in Go. Gio programs run on all the major platforms: iOS/tvOS, Android, Linux (Wayland), macOS and Windows. -[![GoDoc](https://godoc.org/gioui.org/ui/app?status.svg)](https://godoc.org/gioui.org/ui/app) +[![GoDoc](https://godoc.org/gioui.org/ui?status.svg)](https://godoc.org/gioui.org/ui) ## Quickstart diff --git a/ui/doc.go b/ui/doc.go new file mode 100644 index 00000000..1042c623 --- /dev/null +++ b/ui/doc.go @@ -0,0 +1,9 @@ +/* + +Package ui implements portable desktop and mobile GUI programs. + +See https://gioui.org for instructions to setup dependencies and +run Gio programs. + +*/ +package ui diff --git a/ui/ui.go b/ui/ui.go index db4370c6..579b0e47 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -8,26 +8,52 @@ import ( "gioui.org/ui/f32" ) +// Config contain the context for updating and +// drawing a user interface. type Config struct { + // Device pixels per dp. PxPerDp float32 + // Device pixels per sp. PxPerSp float32 - Now time.Time + // The current time for animation. + Now time.Time } +// Pixels converts a value to unitless device pixels. +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") + } +} + +// Op is implemented by all known drawing and control +// operations. type Op interface { ImplementsOp() } +// OpLayer represents a semantic layer of UI. type OpLayer struct { Op Op } +// OpRedraw requests a redraw at the given time. Use +// the zero value to request an immediate redraw. type OpRedraw struct { At time.Time } +// Ops is the operation for a list of ops. type Ops []Op +// OpTransform transforms an op. type OpTransform struct { Transform Transform Op Op diff --git a/ui/unit.go b/ui/unit.go index 33ba3222..f874fa27 100644 --- a/ui/unit.go +++ b/ui/unit.go @@ -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") - } -}