Add FillWidth and FillHeight enclosures.

This commit is contained in:
Greg 2019-08-30 13:35:56 -04:00
parent cf56e8c47e
commit dfc3f618c0
3 changed files with 27 additions and 3 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ cmd/cal/cal
cmd/scroll/scroll
cmd/grid/grid
*.apk
memprofile*

View File

@ -20,7 +20,6 @@ import (
)
var (
sel int32
face text.Face
)

28
main.go
View File

@ -204,8 +204,9 @@ type List = WidgetCombinator
type AxisOpt struct{ axis layout.Axis }
func Axis(x layout.Axis) AxisOpt { return AxisOpt{x} }
var Horizontal = AxisOpt{ layout.Horizontal }
var Vertical = AxisOpt{ layout.Vertical }
var Horizontal = AxisOpt{layout.Horizontal}
var Vertical = AxisOpt{layout.Vertical}
type ListOpts struct {
AxisOpt
@ -510,6 +511,29 @@ func Rrect(ops *ui.Ops, width, height, se, sw, nw, ne float32) {
Mallocs("Rrect() end")
}
type fillWidget struct {
axis layout.Axis
}
func FillWidth(ws ...Widget) Widget {
return Enclose(fillWidget{layout.Horizontal}, ws...)
}
func FillHeight(ws ...Widget) Widget {
return Enclose(fillWidget{layout.Vertical}, ws...)
}
func (fw fillWidget) Begin(ctx *Context) {
switch fw.axis {
case layout.Horizontal:
ctx.cs.Width.Min = ctx.cs.Width.Max
case layout.Vertical:
ctx.cs.Height.Min = ctx.cs.Height.Max
}
}
func (fw fillWidget) End(*Context) {
}
type Clickable interface {
Widget
Clicked(*Context) bool