From baf88f4b7b0410af7580f1eae9a06f9405c1ae65 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Fri, 15 Nov 2024 21:01:59 -0800 Subject: [PATCH] Fix centering text vertically --- README.md | 2 +- messeji/textfield.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3aa34e3..9a4ab8e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # etk - Ebitengine Tool Kit -[![GoDoc](https://code.rocket9labs.com/tslocum/godoc-static/raw/branch/master/badge.svg)](https://docs.rocket9labs.com/code.rocket9labs.com/tslocum/etk) +[![GoDoc](https://code.rocket9labs.com/tslocum/godoc-static/raw/branch/main/badge.svg)](https://docs.rocket9labs.com/code.rocket9labs.com/tslocum/etk) [![Donate via LiberaPay](https://img.shields.io/liberapay/receives/rocket9labs.com.svg?logo=liberapay)](https://liberapay.com/rocket9labs.com) [Ebitengine](https://github.com/hajimehoshi/ebiten) tool kit for creating graphical user interfaces diff --git a/messeji/textfield.go b/messeji/textfield.go index 4dc20f4..0dbdaa5 100644 --- a/messeji/textfield.go +++ b/messeji/textfield.go @@ -951,6 +951,7 @@ func (f *TextField) drawContent() (overflow bool) { lastVisible = len(f.bufferWrapped) - 1 } } + numVisible := lastVisible - firstVisible // Calculate buffer size (width for single-line fields or height for multi-line fields). if f.singleLine { w, _ := text.Measure(f.bufferWrapped[firstVisible], f.face, float64(f.lineHeight)) @@ -1003,9 +1004,9 @@ func (f *TextField) drawContent() (overflow bool) { // Align vertically. totalHeight := f.lineOffset + lineHeight*(lines) if f.vertical == AlignCenter && totalHeight <= h { - lineY = fieldHeight/2 - totalHeight/2 + f.lineOffset + (lineHeight * (i)) + lineY = fieldHeight/2 - totalHeight/2 + f.lineOffset + (lineHeight * (i)) - 2 } else if f.vertical == AlignEnd && totalHeight <= h { - lineY = (fieldHeight - lineHeight*i) - f.padding + lineY = fieldHeight - lineHeight*(numVisible+1-i) - f.padding } // Draw line.