op: add package op for operations

Extract operation types from package ui into package op.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-09-30 15:41:15 +02:00
parent eba1b3a95f
commit 8cf35a1f97
27 changed files with 225 additions and 227 deletions
+7 -6
View File
@@ -14,6 +14,7 @@ import (
"gioui.org/io/key"
"gioui.org/io/pointer"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/paint"
"gioui.org/ui"
@@ -33,12 +34,12 @@ type Editor struct {
Submit bool
// Material for drawing the text.
Material ui.MacroOp
Material op.MacroOp
// Hint contains the text displayed to the user when the
// Editor is empty.
Hint string
// Mmaterial is used to draw the hint.
HintMaterial ui.MacroOp
HintMaterial op.MacroOp
oldScale int
blinkStart time.Time
@@ -218,7 +219,7 @@ func (e *Editor) Layout(gtx *layout.Context) {
Width: e.viewWidth(),
Offset: off,
}
var stack ui.StackOp
var stack op.StackOp
stack.Push(gtx.Ops)
// Apply material. Set a default color in case the material is empty.
if e.rr.len() > 0 {
@@ -233,9 +234,9 @@ func (e *Editor) Layout(gtx *layout.Context) {
if !ok {
break
}
var stack ui.StackOp
var stack op.StackOp
stack.Push(gtx.Ops)
ui.TransformOp{}.Offset(lineOff).Add(gtx.Ops)
op.TransformOp{}.Offset(lineOff).Add(gtx.Ops)
e.Face.Path(str).Add(gtx.Ops)
paint.PaintOp{Rect: toRectF(clip).Sub(lineOff)}.Add(gtx.Ops)
stack.Pop()
@@ -267,7 +268,7 @@ func (e *Editor) Layout(gtx *layout.Context) {
}
}
if blinking {
redraw := ui.InvalidateOp{At: nextBlink}
redraw := op.InvalidateOp{At: nextBlink}
redraw.Add(gtx.Ops)
}
}
+4 -4
View File
@@ -8,9 +8,9 @@ import (
"image/color"
"unicode/utf8"
"gioui.org/ui"
"gioui.org/f32"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/paint"
"golang.org/x/image/math/fixed"
@@ -22,7 +22,7 @@ type Label struct {
Face Face
// Material is a macro recording the material to draw the
// text. Use a ColorOp for colored text.
Material ui.MacroOp
Material op.MacroOp
// Alignment specify the text alignment.
Alignment Alignment
// Text is the string to draw.
@@ -118,9 +118,9 @@ func (l Label) Layout(gtx *layout.Context) {
break
}
lclip := toRectF(clip).Sub(off)
var stack ui.StackOp
var stack op.StackOp
stack.Push(gtx.Ops)
ui.TransformOp{}.Offset(off).Add(gtx.Ops)
op.TransformOp{}.Offset(off).Add(gtx.Ops)
l.Face.Path(str).Add(gtx.Ops)
// Set a default color in case the material is empty.
paint.ColorOp{Color: color.RGBA{A: 0xff}}.Add(gtx.Ops)
+2 -2
View File
@@ -6,8 +6,8 @@ import (
"fmt"
"image"
"gioui.org/ui"
"gioui.org/layout"
"gioui.org/op"
"golang.org/x/image/math/fixed"
)
@@ -50,7 +50,7 @@ type Face interface {
// options.
Layout(s string, opts LayoutOptions) *Layout
// Path returns the ClipOp outline of a text recorded in a macro.
Path(s String) ui.MacroOp
Path(s String) op.MacroOp
}
type Alignment uint8