mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 10:25:37 +00:00
ui/paint: expand documentation and add package description
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package paint provides operations for 2D graphics.
|
||||||
|
|
||||||
|
The PaintOp operation draws the current material into a rectangular
|
||||||
|
area, taking the current clip path and transformation into account.
|
||||||
|
|
||||||
|
The material is set by either a ColorOp for a constant color, or
|
||||||
|
ImageOp for an image.
|
||||||
|
|
||||||
|
The ClipOp operation sets the clip path. Drawing outside the clip
|
||||||
|
path is ignored. A path is a closed shape of lines or curves.
|
||||||
|
*/
|
||||||
|
package paint
|
||||||
+10
-3
@@ -13,15 +13,22 @@ import (
|
|||||||
"gioui.org/ui/internal/opconst"
|
"gioui.org/ui/internal/opconst"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ImageOp sets the material to a section of an
|
||||||
|
// image.
|
||||||
type ImageOp struct {
|
type ImageOp struct {
|
||||||
Src image.Image
|
// Src is the image.
|
||||||
|
Src image.Image
|
||||||
|
// Rect defines the section of Src to use.
|
||||||
Rect image.Rectangle
|
Rect image.Rectangle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ColorOp sets the material to a constant color.
|
||||||
type ColorOp struct {
|
type ColorOp struct {
|
||||||
Color color.RGBA
|
Color color.RGBA
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PaintOp draws the current material, respecting the
|
||||||
|
// clip path and transformation.
|
||||||
type PaintOp struct {
|
type PaintOp struct {
|
||||||
Rect f32.Rectangle
|
Rect f32.Rectangle
|
||||||
}
|
}
|
||||||
@@ -58,8 +65,8 @@ func (d PaintOp) Add(o *ui.Ops) {
|
|||||||
o.Write(data)
|
o.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RectClip returns a ClipOp op corresponding to
|
// RectClip returns a ClipOp corresponding to a pixel aligned
|
||||||
// a pixel aligned rectangular area.
|
// rectangular area.
|
||||||
func RectClip(r image.Rectangle) ClipOp {
|
func RectClip(r image.Rectangle) ClipOp {
|
||||||
return ClipOp{bounds: toRectF(r)}
|
return ClipOp{bounds: toRectF(r)}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -13,6 +13,11 @@ import (
|
|||||||
"gioui.org/ui/internal/path"
|
"gioui.org/ui/internal/path"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// PathBuilder builds and adds a general ClipOp clip path
|
||||||
|
// from lines and curves.
|
||||||
|
// PathBuilder generates no garbage and can be used for
|
||||||
|
// dynamic paths; path data is stored directly in the Ops
|
||||||
|
// list supplied to Init.
|
||||||
type PathBuilder struct {
|
type PathBuilder struct {
|
||||||
ops *ui.Ops
|
ops *ui.Ops
|
||||||
firstVert int
|
firstVert int
|
||||||
@@ -23,8 +28,7 @@ type PathBuilder struct {
|
|||||||
hasBounds bool
|
hasBounds bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClipOp structure must match opClip in package ui/internal/gpu.
|
// ClipOp sets the current clip path.
|
||||||
|
|
||||||
type ClipOp struct {
|
type ClipOp struct {
|
||||||
bounds f32.Rectangle
|
bounds f32.Rectangle
|
||||||
}
|
}
|
||||||
@@ -40,6 +44,8 @@ func (p ClipOp) Add(o *ui.Ops) {
|
|||||||
o.Write(data)
|
o.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init the builder and specify the operations list for
|
||||||
|
// storing the path data and final ClipOp.
|
||||||
func (p *PathBuilder) Init(ops *ui.Ops) {
|
func (p *PathBuilder) Init(ops *ui.Ops) {
|
||||||
p.ops = ops
|
p.ops = ops
|
||||||
}
|
}
|
||||||
@@ -276,6 +282,8 @@ func (p *PathBuilder) simpleQuadTo(ctrl, to f32.Point) {
|
|||||||
p.pen = to
|
p.pen = to
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// End the path and add the resulting ClipOp to
|
||||||
|
// the operation list passed to Init.
|
||||||
func (p *PathBuilder) End() {
|
func (p *PathBuilder) End() {
|
||||||
p.end()
|
p.end()
|
||||||
ClipOp{
|
ClipOp{
|
||||||
|
|||||||
Reference in New Issue
Block a user