mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
@@ -3,7 +3,7 @@
|
|||||||
Gio implements portable immediate mode GUI programs in Go. Gio programs run on all the major platforms:
|
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.
|
iOS/tvOS, Android, Linux (Wayland), macOS and Windows.
|
||||||
|
|
||||||
[](https://godoc.org/gioui.org/ui/app)
|
[](https://godoc.org/gioui.org/ui)
|
||||||
|
|
||||||
## Quickstart
|
## 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"
|
"gioui.org/ui/f32"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Config contain the context for updating and
|
||||||
|
// drawing a user interface.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
// Device pixels per dp.
|
||||||
PxPerDp float32
|
PxPerDp float32
|
||||||
|
// Device pixels per sp.
|
||||||
PxPerSp float32
|
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 {
|
type Op interface {
|
||||||
ImplementsOp()
|
ImplementsOp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OpLayer represents a semantic layer of UI.
|
||||||
type OpLayer struct {
|
type OpLayer struct {
|
||||||
Op Op
|
Op Op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OpRedraw requests a redraw at the given time. Use
|
||||||
|
// the zero value to request an immediate redraw.
|
||||||
type OpRedraw struct {
|
type OpRedraw struct {
|
||||||
At time.Time
|
At time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ops is the operation for a list of ops.
|
||||||
type Ops []Op
|
type Ops []Op
|
||||||
|
|
||||||
|
// OpTransform transforms an op.
|
||||||
type OpTransform struct {
|
type OpTransform struct {
|
||||||
Transform Transform
|
Transform Transform
|
||||||
Op Op
|
Op Op
|
||||||
|
|||||||
+8
-13
@@ -2,16 +2,24 @@
|
|||||||
|
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
|
// Value is a value with a unit.
|
||||||
type Value struct {
|
type Value struct {
|
||||||
V float32
|
V float32
|
||||||
U Unit
|
U Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unit represents a unit for a Value.
|
||||||
type Unit uint8
|
type Unit uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// UnitPx represent device pixels in the resolution of
|
||||||
|
// the underlying display.
|
||||||
UnitPx Unit = iota
|
UnitPx Unit = iota
|
||||||
|
// UnitDp represents device independent pixels. 1 dp will
|
||||||
|
// have the same apparent size across platforms and
|
||||||
|
// display resolutions.
|
||||||
UnitDp
|
UnitDp
|
||||||
|
// UnitSp is like UnitDp but for font sizes.
|
||||||
UnitSp
|
UnitSp
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,16 +34,3 @@ func Dp(v float32) Value {
|
|||||||
func Sp(v float32) Value {
|
func Sp(v float32) Value {
|
||||||
return Value{V: v, U: UnitSp}
|
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