e3ae277841ca9f4d3f65886a5264613ac271164a — Elias Naur a month ago b3e8f59
ui/layout: add List example

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 34 insertions(+), 0 deletions(-)

M ui/layout/layout_test.go
M ui/layout/layout_test.go => ui/layout/layout_test.go +34 -0
@@ 6,11 6,15 @@ "time"
  
  	"gioui.org/ui"
+ 	"gioui.org/ui/input"
  	"gioui.org/ui/layout"
  )
  
+ type queue struct{}
+ 
  type config struct{}
  
+ var q queue
  var cfg = new(config)
  
  func ExampleInset() {


@@ 110,6 114,32 @@ // Expand: {{50 50} {50 50}}
  }
  
+ func ExampleList() {
+ 	ops := new(ui.Ops)
+ 
+ 	cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
+ 
+ 	// The list is 1e6 elements, but only 5 fit the constraints.
+ 	const listLen = 1e6
+ 
+ 	var list layout.List
+ 	list.Init(cfg, q, ops, cs, listLen)
+ 	count := 0
+ 	for ; list.More(); list.Next() {
+ 		dims := layoutWidget(20, 20, list.Constraints())
+ 		list.End(dims)
+ 		count++
+ 	}
+ 
+ 	fmt.Println(count)
+ 
+ 	dims := list.Layout()
+ 	_ = dims
+ 
+ 	// Output:
+ 	// 5
+ }
+ 
  func layoutWidget(width, height int, cs layout.Constraints) layout.Dimens {
  	return layout.Dimens{
  		Size: image.Point{


@@ 126,3 156,7 @@ func (config) Px(v ui.Value) int {
  	return int(v.V + .5)
  }
+ 
+ func (queue) Next(k input.Key) (input.Event, bool) {
+ 	return nil, false
+ }