Fix padding

This commit is contained in:
Trevor Slocum 2023-11-25 10:47:41 -08:00
parent 84e89ee44a
commit 79cd61d663
2 changed files with 9 additions and 4 deletions

View file

@ -77,6 +77,7 @@ func NewDemoGame() *game {
}
g.buffer.SetText(strings.TrimSpace(initialText))
g.buffer.SetPadding(7)
g.input.SetHandleKeyboard(true)
g.input.SetSelectedFunc(func() (accept bool) {
@ -86,6 +87,7 @@ func NewDemoGame() *game {
return true
})
g.input.SetPadding(7)
return g
}

View file

@ -617,7 +617,7 @@ func (f *TextField) _handleMouseEvent(cursor image.Point, pressed bool, clicked
}
h := f.r.Dy()
f.offset = -int(float64(f.bufferSize-h-f.lineOffset/2) * pct)
f.offset = -int(float64(f.bufferSize-h-f.lineOffset+f.padding*2) * pct)
f.clampOffset()
f.redraw = true
@ -900,7 +900,7 @@ func (f *TextField) drawContent() (overflow bool) {
for i := firstVisible; i <= lastVisible; i++ {
line := f.bufferWrapped[i]
lineX := f.padding
lineY := f.padding + f.lineOffset + lineHeight*i
lineY := 1 + f.padding + f.lineOffset + lineHeight*i
// Calculate whether the line overflows the visible area.
lineOverflows := lineY < 0 || lineY >= h-(f.padding*2)
@ -947,7 +947,10 @@ func (f *TextField) clampOffset() {
if f.singleLine {
fieldSize = f.r.Dx()
}
minSize := -(f.bufferSize - fieldSize - f.lineOffset/2)
minSize := -(f.bufferSize - fieldSize + f.padding*2)
if !f.singleLine {
minSize += f.lineOffset
}
if minSize > 0 {
minSize = 0
}
@ -1007,7 +1010,7 @@ func (f *TextField) drawImage() {
}
scrollX, scrollY := w-f.scrollWidth, 0
pct := float64(-f.offset) / float64(f.bufferSize-h-f.lineOffset/2)
pct := float64(-f.offset) / float64(f.bufferSize-h-f.lineOffset+f.padding*2)
scrollY += int(float64(h-scrollBarH) * pct)
scrollBarRect := image.Rect(scrollX, scrollY, scrollX+f.scrollWidth, scrollY+scrollBarH)