Browse Source

Add 'Justified' mode to input fields

master
Brian Buller 2 years ago
parent
commit
f463131c44
  1. 11
      termbox_inputfield.go

11
termbox_inputfield.go

@ -21,6 +21,7 @@ type InputField struct {
multiline bool
tabSkip bool
active bool
justified bool
filter func(*InputField, string, string) string
}
@ -134,6 +135,10 @@ func (c *InputField) SetMultiline(b bool) {
c.multiline = b
}
func (c *InputField) SetJustified(b bool) {
c.justified = b
}
// HandleEvent accepts the termbox event and returns whether it was consumed
func (c *InputField) HandleEvent(event termbox.Event) bool {
prev := c.value
@ -283,7 +288,11 @@ func (c *InputField) Draw() {
strPt2 = strPt2[:len(strPt2)-1]
}
}
x, y = DrawStringAtPoint(strPt1, c.x+len(c.title), c.y, useFg, useBg)
stX := c.x + len(c.title)
if c.justified {
stX = c.x + c.width - len(strPt1) - len(strPt2) - 1
}
x, y = DrawStringAtPoint(strPt1, stX, c.y, useFg, useBg)
if c.active {
termbox.SetCell(x, y, cursorRune, c.cursorFg, c.cursorBg)
} else {

Loading…
Cancel
Save