~pierrec/giox

ref: 2c5ee028295c046e95c45a7f776b0fb6177759ad giox/layoutx/flex.go -rw-r--r-- 1.0 KiB
2c5ee028pierre layoutx: added Rigids and Flexes 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package layoutx

import "gioui.org/layout"

// Flexes provide the same functionality as layout.Flex but
// only for layout.Flex children.
type Flexes struct {
	layout.Flex
	children []layout.FlexChild
}

func (f *Flexes) Layout(gtx layout.Context, n int, el layout.ListElement) layout.Dimensions {
	f.children = append(f.children[:0], make([]layout.FlexChild, n)...)
	for i := range f.children {
		i := i
		f.children[i] = layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
			return el(gtx, i)
		})
	}
	return f.Flex.Layout(gtx, f.children...)
}

// Rigids provide the same functionality as layout.Flex but
// only for layout.Rigid children.
type Rigids struct {
	layout.Flex
	children []layout.FlexChild
}

func (f *Rigids) Layout(gtx layout.Context, n int, el layout.ListElement) layout.Dimensions {
	f.children = append(f.children[:0], make([]layout.FlexChild, n)...)
	for i := range f.children {
		i := i
		f.children[i] = layout.Rigid(func(gtx layout.Context) layout.Dimensions {
			return el(gtx, i)
		})
	}
	return f.Flex.Layout(gtx, f.children...)
}