~pierrec/giox

2c5ee028295c046e95c45a7f776b0fb6177759ad — pierre 2 months ago 48c9bba
layoutx: added Rigids and Flexes

Signed-off-by: pierre <pierre.curto@gmail.com>
1 files changed, 39 insertions(+), 0 deletions(-)

A layoutx/flex.go
A layoutx/flex.go => layoutx/flex.go +39 -0
@@ 0,0 1,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...)
}