Fix centering text vertically
This commit is contained in:
parent
746cdb2994
commit
baf88f4b7b
2 changed files with 4 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue