mirror of
https://github.com/br0xen/termbox-util.git
synced 2024-11-22 13:33:15 +00:00
Still working on input field overflow
This commit is contained in:
parent
9f978a3ec0
commit
99a0a449a1
@ -156,31 +156,27 @@ func (i *InputField) Draw() {
|
|||||||
} else {
|
} else {
|
||||||
strPt1, strPt2, cursorRune = "", "", ' '
|
strPt1, strPt2, cursorRune = "", "", ' '
|
||||||
}
|
}
|
||||||
|
// strPt1, strPt2 = all of the text before, after the cursor
|
||||||
|
// cursorRune is the rune on the cursor
|
||||||
// Check if the value is longer than the width
|
// Check if the value is longer than the width
|
||||||
if len(i.value) > i.width {
|
maxWidth := i.width
|
||||||
if i.wrap {
|
if i.bordered {
|
||||||
// If we're wrapping the text, figure out how that goes
|
maxWidth -= 2
|
||||||
} else {
|
}
|
||||||
// Not wrapping, so figure out what we need to trim
|
cursorRune2 := cursorRune
|
||||||
// We have i.width/2 space for each strPt
|
if len(i.value) > maxWidth {
|
||||||
if len(strPt1) > i.width/2 {
|
var chopLeft bool
|
||||||
if len(strPt2) > i.width/2 {
|
for len(strPt1)+len(strPt2)+1 > maxWidth {
|
||||||
// Both sides are too long, center the cursor
|
if chopLeft && len(strPt1) > 0 {
|
||||||
} else {
|
strPt1 = strPt1[1:]
|
||||||
// Just side 1 is too long, figure out how much we can show
|
} else if !chopLeft && len(strPt2) > 0 {
|
||||||
tmp := i.width - 1
|
strPt2 = strPt2[:len(strPt2)-1]
|
||||||
tmp -= len(strPt2)
|
|
||||||
strPt1 = strPt1[tmp:]
|
|
||||||
}
|
|
||||||
} else if len(strPt2) > i.width/2 {
|
|
||||||
// Just side 2 is too long, figure out how much we can show
|
|
||||||
tmp := i.width - 1
|
|
||||||
tmp -= len(strPt1)
|
|
||||||
strPt2 = strPt2[:tmp]
|
|
||||||
}
|
}
|
||||||
|
chopLeft = !chopLeft
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x, y := DrawStringAtPoint(strPt1, i.x+1, i.y+1, i.fg, i.bg)
|
x, y := DrawStringAtPoint(strPt1, i.x+1, i.y+1, i.fg, i.bg)
|
||||||
termbox.SetCell(x, y, cursorRune, i.bg, i.fg)
|
termbox.SetCell(x, y, cursorRune2, i.bg, i.fg)
|
||||||
DrawStringAtPoint(strPt2, x+1, y, i.fg, i.bg)
|
DrawStringAtPoint(strPt2, x+1, y, i.fg, i.bg)
|
||||||
|
termbox.SetCell(x, y+1, cursorRune, i.bg, i.fg)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user