53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package layout
|
|
|
|
import (
|
|
"image"
|
|
|
|
"gioui.org/layout"
|
|
"gioui.org/op"
|
|
"gioui.org/unit"
|
|
)
|
|
|
|
func IntrinsicCompactCard(gtx layout.Context, w layout.Widget, card func(layout.Context, layout.Widget) layout.Dimensions) layout.Dimensions {
|
|
measureGTX := gtx
|
|
measureGTX.Constraints.Min = image.Point{}
|
|
measureGTX.Constraints.Max.X = gtx.Constraints.Max.X
|
|
macro := op.Record(gtx.Ops)
|
|
contentDims := w(measureGTX)
|
|
_ = macro.Stop()
|
|
width := contentDims.Size.X + gtx.Dp(unit.Dp(20))
|
|
maxWidth := gtx.Constraints.Max.X
|
|
if maxWidth > 0 && width > maxWidth {
|
|
width = maxWidth
|
|
}
|
|
if width > 0 {
|
|
gtx.Constraints.Min.X = width
|
|
gtx.Constraints.Max.X = width
|
|
}
|
|
return card(gtx, w)
|
|
}
|
|
|
|
func MenuActionWidth(gtx layout.Context, rows []layout.Widget) int {
|
|
width := 0
|
|
for _, row := range rows {
|
|
measureGTX := gtx
|
|
measureGTX.Constraints.Min = image.Point{}
|
|
macro := op.Record(gtx.Ops)
|
|
dims := row(measureGTX)
|
|
_ = macro.Stop()
|
|
if dims.Size.X > width {
|
|
width = dims.Size.X
|
|
}
|
|
}
|
|
return width
|
|
}
|
|
|
|
func RightAlignedAction(gtx layout.Context, width int, child layout.Widget) layout.Dimensions {
|
|
if width <= 0 {
|
|
return child(gtx)
|
|
}
|
|
gtx.Constraints.Min.X = width
|
|
gtx.Constraints.Max.X = width
|
|
return layout.E.Layout(gtx, child)
|
|
}
|