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
+1 -1
View File
@@ -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
+9
View File
@@ -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
+27 -1
View File
@@ -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
+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")
}
}