Skip to content

Commit 7b51a67

Browse files
committed
border: fix leak of border styles. In paint, any time we set StrokeStyle to something other than the actual styled values, we need to save and restore original! added test.
1 parent f9e6019 commit 7b51a67

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

core/render_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ func TestRenderParentBorderRadiusHorizontalToolbar(t *testing.T) {
7979
b.AssertRender(t, "render/parent-border-radius-horizontal-toolbar")
8080
}
8181

82+
func TestRenderBorderLeak(t *testing.T) {
83+
b := NewBody()
84+
NewFrame(b).Styler(func(s *styles.Style) {
85+
s.Min.Set(units.Em(5))
86+
s.Border.Width.Set(units.Dp(4))
87+
s.Border.Color.Set(colors.Scheme.Outline)
88+
})
89+
NewFrame(b).Styler(func(s *styles.Style) {
90+
s.Min.Set(units.Em(5))
91+
s.Border.Style.Set(styles.BorderDotted)
92+
s.Border.Width.Set(units.Dp(4))
93+
s.Border.Color.Set(colors.Scheme.Error.Base)
94+
})
95+
NewFrame(b).Styler(func(s *styles.Style) {
96+
s.Min.Set(units.Em(5))
97+
s.Border.Width.Set(units.Dp(4))
98+
s.Border.Color.Set(colors.Scheme.Outline)
99+
})
100+
b.AssertRender(t, "render/border-leak")
101+
}
102+
82103
// For https://github.com/cogentcore/core/issues/810
83104
func TestRenderButtonAlignment(t *testing.T) {
84105
b := NewBody()

paint/paint.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,12 @@ func (pc *Context) DrawPolygonPxToDots(points []math32.Vector2) {
519519
// DrawBorder is a higher-level function that draws, strokes, and fills
520520
// an potentially rounded border box with the given position, size, and border styles.
521521
func (pc *Context) DrawBorder(x, y, w, h float32, bs styles.Border) {
522+
origStroke := pc.StrokeStyle
523+
origFill := pc.FillStyle
524+
defer func() {
525+
pc.StrokeStyle = origStroke
526+
pc.FillStyle = origFill
527+
}()
522528
r := bs.Radius.Dots()
523529
if styles.SidesAreSame(bs.Style) && styles.SidesAreSame(bs.Color) && styles.SidesAreSame(bs.Width.Dots().Sides) {
524530
// set the color if it is not nil and the stroke style

0 commit comments

Comments
 (0)