From c178ade3237f73929fd46cac1dba74e48595d7fd Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 3 Feb 2020 23:37:46 +0100 Subject: [PATCH] widget: remove Editor field carWidth The caret width can be computed in the only method that needs it, PaintCaret. Signed-off-by: Elias Naur --- widget/editor.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/widget/editor.go b/widget/editor.go index 7787bba3..4d5505f7 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -45,7 +45,6 @@ type Editor struct { lines []text.Line shapes []line dims layout.Dimensions - carWidth fixed.Int26_6 requestFocus bool caretOn bool caretScroll bool @@ -230,7 +229,6 @@ func (e *Editor) Layout(gtx *layout.Context, sh text.Shaper, font text.Font, siz func (e *Editor) layout(gtx *layout.Context, sh text.Shaper) { cs := gtx.Constraints - e.carWidth = fixed.I(gtx.Px(unit.Dp(1))) maxWidth := cs.Width.Max if e.SingleLine { @@ -323,15 +321,16 @@ func (e *Editor) PaintCaret(gtx *layout.Context) { if !e.caretOn { return } + carWidth := fixed.I(gtx.Px(unit.Dp(1))) carLine, _, carX, carY := e.layoutCaret() var stack op.StackOp stack.Push(gtx.Ops) - carX -= e.carWidth / 2 + carX -= carWidth / 2 carAsc, carDesc := -e.lines[carLine].Bounds.Min.Y, e.lines[carLine].Bounds.Max.Y carRect := image.Rectangle{ Min: image.Point{X: carX.Ceil(), Y: carY - carAsc.Ceil()}, - Max: image.Point{X: carX.Ceil() + e.carWidth.Ceil(), Y: carY + carDesc.Ceil()}, + Max: image.Point{X: carX.Ceil() + carWidth.Ceil(), Y: carY + carDesc.Ceil()}, } carRect = carRect.Add(image.Point{ X: -e.scrollOff.X, @@ -339,7 +338,7 @@ func (e *Editor) PaintCaret(gtx *layout.Context) { }) clip := textPadding(e.lines) // Account for caret width to each side. - whalf := (e.carWidth / 2).Ceil() + whalf := (carWidth / 2).Ceil() if clip.Max.X < whalf { clip.Max.X = whalf }