mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
@@ -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.
|
||||
|
||||
[](https://godoc.org/gioui.org/ui/app)
|
||||
[](https://godoc.org/gioui.org/ui)
|
||||
|
||||
## Quickstart
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user