diff --git a/termbox_inputfield.go b/termbox_inputfield.go index 0c5d439..9e1f6c0 100644 --- a/termbox_inputfield.go +++ b/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 {