mirror of
https://github.com/br0xen/termbox-util.git
synced 2024-11-22 21:43:14 +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
|
multiline bool
|
||||||
tabSkip bool
|
tabSkip bool
|
||||||
active bool
|
active bool
|
||||||
|
justified bool
|
||||||
|
|
||||||
filter func(*InputField, string, string) string
|
filter func(*InputField, string, string) string
|
||||||
}
|
}
|
||||||
@ -134,6 +135,10 @@ func (c *InputField) SetMultiline(b bool) {
|
|||||||
c.multiline = b
|
c.multiline = b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *InputField) SetJustified(b bool) {
|
||||||
|
c.justified = b
|
||||||
|
}
|
||||||
|
|
||||||
// HandleEvent accepts the termbox event and returns whether it was consumed
|
// HandleEvent accepts the termbox event and returns whether it was consumed
|
||||||
func (c *InputField) HandleEvent(event termbox.Event) bool {
|
func (c *InputField) HandleEvent(event termbox.Event) bool {
|
||||||
prev := c.value
|
prev := c.value
|
||||||
@ -283,7 +288,11 @@ func (c *InputField) Draw() {
|
|||||||
strPt2 = strPt2[:len(strPt2)-1]
|
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 {
|
if c.active {
|
||||||
termbox.SetCell(x, y, cursorRune, c.cursorFg, c.cursorBg)
|
termbox.SetCell(x, y, cursorRune, c.cursorFg, c.cursorBg)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user