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:
Elias Naur
2019-09-30 16:42:12 +02:00
parent 1d3360699e
commit 3784ece6dd
20 changed files with 95 additions and 101 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ For example, to add space above a widget:
gtx.Reset(...)
// Configure a top inset.
inset := layout.Inset{Top: ui.Dp(8), ...}
inset := layout.Inset{Top: unit.Dp(8), ...}
// Use the inset to lay out a widget.
inset.Layout(gtx, func() {
// Lay out widget and determine its size given the constraints.
+15 -5
View File
@@ -4,10 +4,11 @@ package layout
import (
"image"
"time"
"gioui.org/io/event"
"gioui.org/op"
"gioui.org/ui"
"gioui.org/unit"
)
// Constraints represent a set of acceptable ranges for
@@ -52,11 +53,20 @@ type Context struct {
// operation.
Dimensions Dimensions
ui.Config
Config
event.Queue
*op.Ops
}
// Config define the essential properties of
// the environment.
type Config interface {
// Now returns the current animation time.
Now() time.Time
unit.Converter
}
const (
Start Alignment = iota
End
@@ -93,7 +103,7 @@ func (s *Context) Layout(cs Constraints, w Widget) Dimensions {
}
// Reset the context.
func (c *Context) Reset(cfg ui.Config, cs Constraints) {
func (c *Context) Reset(cfg Config, cs Constraints) {
c.Constraints = cs
c.Dimensions = Dimensions{}
c.Config = cfg
@@ -129,7 +139,7 @@ func RigidConstraints(size image.Point) Constraints {
// Inset adds space around a widget.
type Inset struct {
Top, Right, Bottom, Left ui.Value
Top, Right, Bottom, Left unit.Value
}
// Align aligns a widget in the available space.
@@ -171,7 +181,7 @@ func (in Inset) Layout(gtx *Context, w Widget) {
// UniformInset returns an Inset with a single inset applied to all
// edges.
func UniformInset(v ui.Value) Inset {
func UniformInset(v unit.Value) Inset {
return Inset{Top: v, Right: v, Bottom: v, Left: v}
}
+3 -3
View File
@@ -7,7 +7,7 @@ import (
"gioui.org/io/event"
"gioui.org/layout"
"gioui.org/ui"
"gioui.org/unit"
)
type queue struct{}
@@ -26,7 +26,7 @@ func ExampleInset() {
gtx.Reset(cfg, cs)
// Inset all edges by 10.
inset := layout.UniformInset(ui.Dp(10))
inset := layout.UniformInset(unit.Dp(10))
inset.Layout(gtx, func() {
// Lay out a 50x50 sized widget.
layoutWidget(gtx, 50, 50)
@@ -146,7 +146,7 @@ func (config) Now() time.Time {
return time.Now()
}
func (config) Px(v ui.Value) int {
func (config) Px(v unit.Value) int {
return int(v.V + .5)
}
+1 -1
View File
@@ -110,7 +110,7 @@ func (l *List) Dragging() bool {
}
func (l *List) update() {
d := l.scroll.Scroll(l.ctx.Config, l.ctx.Queue, gesture.Axis(l.Axis))
d := l.scroll.Scroll(l.ctx.Config, l.ctx.Queue, l.ctx.Now(), gesture.Axis(l.Axis))
l.scrollDelta = d
l.offset += d
}