From e48ff5bea4725d39818f24fa76b5ae74971f23a3 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 30 Apr 2018 10:55:37 +0300 Subject: Update dependencies --- vendor/maunium.net/go/tview/inputfield.go | 50 +++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'vendor/maunium.net/go/tview/inputfield.go') diff --git a/vendor/maunium.net/go/tview/inputfield.go b/vendor/maunium.net/go/tview/inputfield.go index c168106..2c92a93 100644 --- a/vendor/maunium.net/go/tview/inputfield.go +++ b/vendor/maunium.net/go/tview/inputfield.go @@ -41,6 +41,10 @@ type InputField struct { // The text color of the placeholder. placeholderTextColor tcell.Color + // The screen width of the label area. A value of 0 means use the width of + // the label text. + labelWidth int + // The screen width of the input area. A value of 0 means extend as much as // possible. fieldWidth int @@ -59,6 +63,10 @@ type InputField struct { // are done entering text. The key which was pressed is provided (tab, // shift-tab, enter, or escape). done func(tcell.Key) + + // A callback function set by the Form class and called when the user leaves + // this form item. + finished func(tcell.Key) } // NewInputField returns a new input field. @@ -97,6 +105,13 @@ func (i *InputField) GetLabel() string { return i.label } +// SetLabelWidth sets the screen width of the label. A value of 0 will cause the +// primitive to use the width of the label string. +func (i *InputField) SetLabelWidth(width int) *InputField { + i.labelWidth = width + return i +} + // SetPlaceholder sets the text to be displayed when the input text is empty. func (i *InputField) SetPlaceholder(text string) *InputField { i.placeholder = text @@ -121,15 +136,15 @@ func (i *InputField) SetFieldTextColor(color tcell.Color) *InputField { return i } -// SetPlaceholderExtColor sets the text color of placeholder text. -func (i *InputField) SetPlaceholderExtColor(color tcell.Color) *InputField { +// SetPlaceholderTextColor sets the text color of placeholder text. +func (i *InputField) SetPlaceholderTextColor(color tcell.Color) *InputField { i.placeholderTextColor = color return i } // SetFormAttributes sets attributes shared by all form items. -func (i *InputField) SetFormAttributes(label string, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { - i.label = label +func (i *InputField) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { + i.labelWidth = labelWidth i.labelColor = labelColor i.backgroundColor = bgColor i.fieldTextColor = fieldTextColor @@ -186,9 +201,10 @@ func (i *InputField) SetDoneFunc(handler func(key tcell.Key)) *InputField { return i } -// SetFinishedFunc calls SetDoneFunc(). +// SetFinishedFunc sets a callback invoked when the user leaves this form item. func (i *InputField) SetFinishedFunc(handler func(key tcell.Key)) FormItem { - return i.SetDoneFunc(handler) + i.finished = handler + return i } // Draw draws this primitive onto the screen. @@ -203,8 +219,17 @@ func (i *InputField) Draw(screen tcell.Screen) { } // Draw label. - _, drawnWidth := Print(screen, i.label, x, y, rightLimit-x, AlignLeft, i.labelColor) - x += drawnWidth + if i.labelWidth > 0 { + labelWidth := i.labelWidth + if labelWidth > rightLimit-x { + labelWidth = rightLimit - x + } + Print(screen, i.label, x, y, labelWidth, AlignLeft, i.labelColor) + x += labelWidth + } else { + _, drawnWidth := Print(screen, i.label, x, y, rightLimit-x, AlignLeft, i.labelColor) + x += drawnWidth + } // Draw input area. fieldWidth := i.fieldWidth @@ -280,7 +305,11 @@ func (i *InputField) setCursor(screen tcell.Screen) { if i.fieldWidth > 0 && fieldWidth > i.fieldWidth-1 { fieldWidth = i.fieldWidth - 1 } - x += StringWidth(i.label) + fieldWidth + if i.labelWidth > 0 { + x += i.labelWidth + fieldWidth + } else { + x += StringWidth(i.label) + fieldWidth + } if x >= rightLimit { x = rightLimit - 1 } @@ -323,6 +352,9 @@ func (i *InputField) InputHandler() func(event *tcell.EventKey, setFocus func(p if i.done != nil { i.done(key) } + if i.finished != nil { + i.finished(key) + } } }) } -- cgit v1.2.3