mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
all: rename package ui to unit
Package ui is now only about units except for the Config.Now method. Remove Now and rename Config to Converter. Add layout.Config to replace the old ui.Config. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+7
-7
@@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/unit"
|
||||
)
|
||||
|
||||
// An UpdateEvent is generated when a Window's Update
|
||||
@@ -39,7 +39,7 @@ type DestroyEvent struct {
|
||||
// system decoration such as translucent
|
||||
// system bars and software keyboards.
|
||||
type Insets struct {
|
||||
Top, Bottom, Left, Right ui.Value
|
||||
Top, Bottom, Left, Right unit.Value
|
||||
}
|
||||
|
||||
// A StageEvent is generated whenever the stage of a
|
||||
@@ -146,7 +146,7 @@ func Main() {
|
||||
main()
|
||||
}
|
||||
|
||||
// Config implements the ui.Config interface.
|
||||
// Config implements the layout.Config interface.
|
||||
type Config struct {
|
||||
// Device pixels per dp.
|
||||
pxPerDp float32
|
||||
@@ -159,14 +159,14 @@ func (c *Config) Now() time.Time {
|
||||
return c.now
|
||||
}
|
||||
|
||||
func (c *Config) Px(v ui.Value) int {
|
||||
func (c *Config) Px(v unit.Value) int {
|
||||
var r float32
|
||||
switch v.U {
|
||||
case ui.UnitPx:
|
||||
case unit.UnitPx:
|
||||
r = v.V
|
||||
case ui.UnitDp:
|
||||
case unit.UnitDp:
|
||||
r = c.pxPerDp * v.V
|
||||
case ui.UnitSp:
|
||||
case unit.UnitSp:
|
||||
r = c.pxPerSp * v.V
|
||||
default:
|
||||
panic("unknown unit")
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ contents and state.
|
||||
|
||||
For example:
|
||||
|
||||
import "gioui.org/ui"
|
||||
import "gioui.org/unit"
|
||||
|
||||
w := app.NewWindow()
|
||||
for e := range w.Events() {
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import (
|
||||
"gioui.org/f32"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/ui"
|
||||
"gioui.org/unit"
|
||||
)
|
||||
|
||||
type window struct {
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ import (
|
||||
"gioui.org/f32"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/ui"
|
||||
"gioui.org/unit"
|
||||
)
|
||||
|
||||
type window struct {
|
||||
|
||||
+1
-2
@@ -583,8 +583,7 @@ func (w *window) flushFling() {
|
||||
w.fling.yExtrapolation = fling.Extrapolation{}
|
||||
vel := float32(math.Sqrt(float64(estx.Velocity*estx.Velocity + esty.Velocity*esty.Velocity)))
|
||||
_, _, c := w.config()
|
||||
c.now = time.Now()
|
||||
if !w.fling.anim.Start(&c, vel) {
|
||||
if !w.fling.anim.Start(&c, time.Now(), vel) {
|
||||
return
|
||||
}
|
||||
invDist := 1 / vel
|
||||
|
||||
+6
-6
@@ -13,7 +13,7 @@ import (
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/profile"
|
||||
"gioui.org/op"
|
||||
"gioui.org/ui"
|
||||
"gioui.org/unit"
|
||||
)
|
||||
|
||||
// WindowOption configures a Window.
|
||||
@@ -22,7 +22,7 @@ type WindowOption struct {
|
||||
}
|
||||
|
||||
type windowOptions struct {
|
||||
Width, Height ui.Value
|
||||
Width, Height unit.Value
|
||||
Title string
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ var ackEvent event.Event
|
||||
// BUG: Calling NewWindow more than once is not yet supported.
|
||||
func NewWindow(options ...WindowOption) *Window {
|
||||
opts := &windowOptions{
|
||||
Width: ui.Dp(800),
|
||||
Height: ui.Dp(600),
|
||||
Width: unit.Dp(800),
|
||||
Height: unit.Dp(600),
|
||||
Title: "Gio",
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ func WithTitle(t string) WindowOption {
|
||||
}
|
||||
|
||||
// WithWidth returns an option that sets the window width.
|
||||
func WithWidth(w ui.Value) WindowOption {
|
||||
func WithWidth(w unit.Value) WindowOption {
|
||||
if w.V <= 0 {
|
||||
panic("width must be larger than or equal to 0")
|
||||
}
|
||||
@@ -351,7 +351,7 @@ func WithWidth(w ui.Value) WindowOption {
|
||||
}
|
||||
|
||||
// WithHeight returns an option that sets the window height.
|
||||
func WithHeight(h ui.Value) WindowOption {
|
||||
func WithHeight(h unit.Value) WindowOption {
|
||||
if h.V <= 0 {
|
||||
panic("height must be larger than or equal to 0")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user