From 8ed1352fd4e18b6af071f949bd4d8ab00f05322f Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 24 Aug 2023 17:15:34 -0400 Subject: [PATCH] Fixed non-cannonized rectangles being drawn --- canvas/canvas.go | 1 + go.mod | 2 +- go.sum | 4 ++-- textbox.go | 22 +++++++++++----------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/canvas/canvas.go b/canvas/canvas.go index 8de4e50..ed276d9 100644 --- a/canvas/canvas.go +++ b/canvas/canvas.go @@ -77,6 +77,7 @@ type pen struct { } func (this *pen) Rectangle (bounds image.Rectangle) { + bounds = bounds.Canon() if this.weight == 0 { if this.fill.A > 0 { this.fillRectangle(this.fill, bounds) diff --git a/go.mod b/go.mod index 3add147..6d4b4c0 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.tebibyte.media/tomo/x go 1.20 require ( - git.tebibyte.media/tomo/tomo v0.26.0 + git.tebibyte.media/tomo/tomo v0.26.1 git.tebibyte.media/tomo/typeset v0.5.2 git.tebibyte.media/tomo/xgbkb v1.0.1 github.com/jezek/xgb v1.1.0 diff --git a/go.sum b/go.sum index f219f48..d63ade2 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q= -git.tebibyte.media/tomo/tomo v0.26.0 h1:JjOb3ZEsGfpkNBe2nVAfZYw/VrDDPqODH/ANZiG4czU= -git.tebibyte.media/tomo/tomo v0.26.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps= +git.tebibyte.media/tomo/tomo v0.26.1 h1:V5ciRuixMYb79aAawgquFEfJ1icyEmMKBKFPWwi94NE= +git.tebibyte.media/tomo/tomo v0.26.1/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps= git.tebibyte.media/tomo/typeset v0.5.2 h1:qHxN62/VDnrAouOuzxLmLleQNwAebshrfVYvtoOnAG4= git.tebibyte.media/tomo/typeset v0.5.2/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g= git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE= diff --git a/textbox.go b/textbox.go index 00f2f13..b98a1c4 100644 --- a/textbox.go +++ b/textbox.go @@ -13,7 +13,7 @@ import "git.tebibyte.media/tomo/tomo/canvas" type textBox struct { *box - + hOverflow, vOverflow bool contentBounds image.Rectangle scroll image.Point @@ -29,9 +29,9 @@ type textBox struct { selectStart int dot text.Dot dotColor color.Color - + drawer typeset.Drawer - + on struct { contentBoundsChange event.FuncBroadcaster dotChange event.FuncBroadcaster @@ -137,7 +137,7 @@ func (this *textBox) SetAlign (x, y tomo.Align) { case tomo.AlignEnd: this.drawer.SetAlign(typeset.AlignRight) case tomo.AlignEven: this.drawer.SetAlign(typeset.AlignJustify) } - + this.invalidateDraw() } @@ -170,7 +170,6 @@ func (this *textBox) drawDot (can canvas.Canvas) { pen := can.Pen() pen.Fill(color.Transparent) pen.Stroke(this.textColor) - pen.StrokeWeight(1) bounds := this.InnerBounds() metrics := this.face.Metrics() @@ -180,11 +179,12 @@ func (this *textBox) drawDot (can canvas.Canvas) { height := this.drawer.LineHeight().Round() ascent := fixed.Point26_6 { Y: metrics.Descent } descent := fixed.Point26_6 { Y: metrics.Ascent } - + switch { case dot.Empty(): + pen.StrokeWeight(1) pen.Path(roundPt(start.Add(ascent)), roundPt(start.Sub(descent))) - + case start.Y == end.Y: pen.Fill(this.dotColor) pen.StrokeWeight(0) @@ -192,11 +192,11 @@ func (this *textBox) drawDot (can canvas.Canvas) { Min: roundPt(start.Add(ascent)), Max: roundPt(end.Sub(descent)), }) - + default: pen.Fill(this.dotColor) pen.StrokeWeight(0) - + rect := image.Rectangle { Min: roundPt(start.Add(ascent)), Max: roundPt(start.Sub(descent)), @@ -292,9 +292,9 @@ func (this *textBox) doLayout () { innerBounds := this.InnerBounds() this.drawer.SetMaxWidth(innerBounds.Dx()) this.drawer.SetMaxHeight(innerBounds.Dy()) - + this.contentBounds = this.normalizedLayoutBoundsSpace().Sub(this.scroll) - + if previousContentBounds != this.contentBounds { this.on.contentBoundsChange.Broadcast() }