Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Background ¶
type Background struct{}
Example ¶
package main
import (
"fmt"
"image"
"github.com/nanorele/gio/layout"
"github.com/nanorele/gio/op"
)
func main() {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Constraints{
Max: image.Point{X: 100, Y: 100},
},
}
layout.Background{}.Layout(gtx,
func(gtx layout.Context) layout.Dimensions {
fmt.Printf("Expand: %v\n", gtx.Constraints)
return layoutWidget(gtx, 10, 10)
},
func(gtx layout.Context) layout.Dimensions {
return layoutWidget(gtx, 50, 50)
},
)
}
func layoutWidget(ctx layout.Context, width, height int) layout.Dimensions {
return layout.Dimensions{
Size: image.Point{
X: width,
Y: height,
},
}
}
Output:
func (Background) Layout ¶
func (Background) Layout(gtx Context, background, widget Widget) Dimensions
type Constraints ¶
func Exact ¶
func Exact(size image.Point) Constraints
func (Constraints) AddMin ¶
func (c Constraints) AddMin(delta image.Point) Constraints
func (Constraints) SubMax ¶
func (c Constraints) SubMax(delta image.Point) Constraints
type Context ¶
type Dimensions ¶
type Direction ¶
type Direction uint8
Example ¶
package main
import (
"fmt"
"image"
"github.com/nanorele/gio/layout"
"github.com/nanorele/gio/op"
)
func main() {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Point{X: 100, Y: 100}),
}
dims := layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
dims := layoutWidget(gtx, 50, 50)
fmt.Println(dims.Size)
return dims
})
fmt.Println(dims.Size)
}
func layoutWidget(ctx layout.Context, width, height int) layout.Dimensions {
return layout.Dimensions{
Size: image.Point{
X: width,
Y: height,
},
}
}
Output:
type Flex ¶
Example ¶
package main
import (
"fmt"
"image"
"github.com/nanorele/gio/layout"
"github.com/nanorele/gio/op"
)
func main() {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Point{X: 100, Y: 100}),
}
layout.Flex{WeightSum: 2}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
fmt.Printf("Rigid: %v\n", gtx.Constraints)
return layoutWidget(gtx, 10, 10)
}),
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
fmt.Printf("50%%: %v\n", gtx.Constraints)
return layoutWidget(gtx, 10, 10)
}),
)
}
func layoutWidget(ctx layout.Context, width, height int) layout.Dimensions {
return layout.Dimensions{
Size: image.Point{
X: width,
Y: height,
},
}
}
Output:
type Inset ¶
Example ¶
package main
import (
"fmt"
"image"
"github.com/nanorele/gio/layout"
"github.com/nanorele/gio/op"
)
func main() {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Constraints{
Max: image.Point{X: 100, Y: 100},
},
}
inset := layout.UniformInset(10)
dims := inset.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
dims := layoutWidget(gtx, 50, 50)
fmt.Println(dims.Size)
return dims
})
fmt.Println(dims.Size)
}
func layoutWidget(ctx layout.Context, width, height int) layout.Dimensions {
return layout.Dimensions{
Size: image.Point{
X: width,
Y: height,
},
}
}
Output:
func UniformInset ¶
type List ¶
type List struct {
Axis Axis
ScrollToEnd bool
Alignment Alignment
ScrollAnyAxis bool
Gap int
Position Position
// contains filtered or unexported fields
}
Example ¶
package main
import (
"fmt"
"image"
"github.com/nanorele/gio/layout"
"github.com/nanorele/gio/op"
)
func main() {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Point{X: 100, Y: 100}),
}
const listLen = 1e6
var list layout.List
list.Layout(gtx, listLen, func(gtx layout.Context, i int) layout.Dimensions {
return layoutWidget(gtx, 20, 20)
})
fmt.Println(list.Position.Count)
}
func layoutWidget(ctx layout.Context, width, height int) layout.Dimensions {
return layout.Dimensions{
Size: image.Point{
X: width,
Y: height,
},
}
}
Output:
func (*List) Layout ¶
func (l *List) Layout(gtx Context, len int, w ListElement) Dimensions
func (*List) VisibleRange ¶ added in v1.4.0
VisibleRange applies the current frame's scroll events to the list position and returns the index range [first, first+count) that a subsequent Layout call in the same frame is expected to produce. itemSize is the main-axis size of one element in pixels excluding Gap; pass 0 to derive it from the previous frame's average. With uniform element sizes the range is exact up to one element of slack on each side; with varying sizes it is an estimate. When no size information exists yet (first frame with itemSize 0), it returns the full range.
It lets callers warm up exactly the widgets about to be laid out (event handler prepass, column width measurement) instead of walking the whole model with heuristics based on the previous frame.
type ListElement ¶
type ListElement func(gtx Context, index int) Dimensions
type Stack ¶
type Stack struct {
Alignment Direction
}
Example ¶
package main
import (
"fmt"
"image"
"github.com/nanorele/gio/layout"
"github.com/nanorele/gio/op"
)
func main() {
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Constraints{
Max: image.Point{X: 100, Y: 100},
},
}
layout.Stack{}.Layout(gtx,
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
fmt.Printf("Expand: %v\n", gtx.Constraints)
return layoutWidget(gtx, 10, 10)
}),
layout.Stacked(func(gtx layout.Context) layout.Dimensions {
return layoutWidget(gtx, 50, 50)
}),
)
}
func layoutWidget(ctx layout.Context, width, height int) layout.Dimensions {
return layout.Dimensions{
Size: image.Point{
X: width,
Y: height,
},
}
}
Output:
func (Stack) Layout ¶
func (s Stack) Layout(gtx Context, children ...StackChild) Dimensions
type StackChild ¶
type StackChild struct {
// contains filtered or unexported fields
}
func Expanded ¶
func Expanded(w Widget) StackChild
func Stacked ¶
func Stacked(w Widget) StackChild
type Widget ¶
type Widget func(gtx Context) Dimensions