mirror of
https://github.com/br0xen/termbox-util.git
synced 2024-11-22 13:33:15 +00:00
Add 'Justified' mode to input fields
This commit is contained in:
parent
11b03a8d70
commit
f463131c44
@ -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…
Reference in New Issue
Block a user