Fix Gio card and button layout

This commit is contained in:
2026-04-06 09:08:42 +07:00
parent fd8656ffa0
commit 7268b11e5d

View File

@@ -970,18 +970,8 @@ func (u *ui) layoutButton(gtx layout.Context, btn *widget.Clickable, label strin
func (u *ui) buttonLike(gtx layout.Context, btn *widget.Clickable, label string, bg, fg color.NRGBA, hPad, vPad unit.Dp) layout.Dimensions { func (u *ui) buttonLike(gtx layout.Context, btn *widget.Clickable, label string, bg, fg color.NRGBA, hPad, vPad unit.Dp) layout.Dimensions {
return btn.Layout(gtx, func(gtx layout.Context) layout.Dimensions { return btn.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
min := image.Pt(gtx.Dp(unit.Dp(96)), gtx.Dp(unit.Dp(40))) macro := op.Record(gtx.Ops)
if gtx.Constraints.Min.X < min.X { dims := layout.Inset{
gtx.Constraints.Min.X = min.X
}
if gtx.Constraints.Min.Y < min.Y {
gtx.Constraints.Min.Y = min.Y
}
rr := gtx.Dp(unit.Dp(14))
defer clip.RRect{Rect: image.Rectangle{Max: gtx.Constraints.Min}, NW: rr, NE: rr, SW: rr, SE: rr}.Push(gtx.Ops).Pop()
paint.Fill(gtx.Ops, bg)
return layout.Inset{
Top: vPad, Top: vPad,
Bottom: vPad, Bottom: vPad,
Left: hPad, Left: hPad,
@@ -994,20 +984,34 @@ func (u *ui) buttonLike(gtx layout.Context, btn *widget.Clickable, label string,
return lbl.Layout(gtx) return lbl.Layout(gtx)
}) })
}) })
call := macro.Stop()
minSize := image.Pt(gtx.Dp(unit.Dp(96)), gtx.Dp(unit.Dp(40)))
if dims.Size.X < minSize.X {
dims.Size.X = minSize.X
}
if dims.Size.Y < minSize.Y {
dims.Size.Y = minSize.Y
}
rr := gtx.Dp(unit.Dp(14))
defer clip.RRect{Rect: image.Rectangle{Max: dims.Size}, NW: rr, NE: rr, SW: rr, SE: rr}.Push(gtx.Ops).Pop()
paint.Fill(gtx.Ops, bg)
call.Add(gtx.Ops)
return dims
}) })
} }
func (u *ui) card(gtx layout.Context, bg color.NRGBA, content layout.Widget) layout.Dimensions { func (u *ui) card(gtx layout.Context, bg color.NRGBA, content layout.Widget) layout.Dimensions {
return layout.Stack{}.Layout( macro := op.Record(gtx.Ops)
gtx, dims := content(gtx)
layout.Expanded(func(gtx layout.Context) layout.Dimensions { call := macro.Stop()
rr := gtx.Dp(unit.Dp(20))
defer clip.RRect{Rect: image.Rectangle{Max: gtx.Constraints.Max}, NW: rr, NE: rr, SW: rr, SE: rr}.Push(gtx.Ops).Pop() rr := gtx.Dp(unit.Dp(20))
paint.Fill(gtx.Ops, bg) defer clip.RRect{Rect: image.Rectangle{Max: dims.Size}, NW: rr, NE: rr, SW: rr, SE: rr}.Push(gtx.Ops).Pop()
return layout.Dimensions{Size: gtx.Constraints.Max} paint.Fill(gtx.Ops, bg)
}), call.Add(gtx.Ops)
layout.Stacked(content), return dims
)
} }
func fill(gtx layout.Context, c color.NRGBA) { func fill(gtx layout.Context, c color.NRGBA) {