forked from joejulian/gio
widget/material: fix list scrollbar display
This commit fixes a visual misalignment in scrollbars resulting from subtle differences in the semantics of layout.Stack and layout.Background. layout.Stack will position expanded children according to their minimum constraint regardless of their returned size, whereas layout.Background uses their returned size. This means that layout.Expanded widgets returning zero dimensions are positioned correctly, but they break when converted to use layout.Background. This commit fixes the problem by returning correct dimensions from the scrollbar track. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -165,9 +165,6 @@ func (s ScrollbarStyle) layout(gtx layout.Context, axis layout.Axis, viewportSta
|
||||
if axis == layout.Horizontal {
|
||||
inset.Top, inset.Bottom, inset.Left, inset.Right = inset.Left, inset.Right, inset.Top, inset.Bottom
|
||||
}
|
||||
// Capture the outer constraints because layout.Stack will reset
|
||||
// the minimum to zero.
|
||||
outerConstraints := gtx.Constraints
|
||||
|
||||
return layout.Background{}.Layout(gtx,
|
||||
func(gtx layout.Context) layout.Dimensions {
|
||||
@@ -186,10 +183,9 @@ func (s ScrollbarStyle) layout(gtx layout.Context, axis layout.Axis, viewportSta
|
||||
s.Scrollbar.AddTrack(gtx.Ops)
|
||||
|
||||
paint.FillShape(gtx.Ops, s.Track.Color, clip.Rect(area).Op())
|
||||
return layout.Dimensions{}
|
||||
return layout.Dimensions{Size: gtx.Constraints.Min}
|
||||
},
|
||||
func(gtx layout.Context) layout.Dimensions {
|
||||
gtx.Constraints = outerConstraints
|
||||
return inset.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||
// Use axis-independent constraints.
|
||||
gtx.Constraints.Min = axis.Convert(gtx.Constraints.Min)
|
||||
|
||||
Reference in New Issue
Block a user