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/dropdown.go | 40 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'vendor/maunium.net/go/tview/dropdown.go') diff --git a/vendor/maunium.net/go/tview/dropdown.go b/vendor/maunium.net/go/tview/dropdown.go index 981d1bd..515f978 100644 --- a/vendor/maunium.net/go/tview/dropdown.go +++ b/vendor/maunium.net/go/tview/dropdown.go @@ -51,6 +51,10 @@ type DropDown struct { // The color for prefixes. prefixTextColor 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 DropDown struct { // are done selecting options. The key which was pressed is provided (tab, // shift-tab, 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) } // NewDropDown returns a new drop-down. @@ -113,6 +121,13 @@ func (d *DropDown) GetLabel() string { return d.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 (d *DropDown) SetLabelWidth(width int) *DropDown { + d.labelWidth = width + return d +} + // SetLabelColor sets the color of the label. func (d *DropDown) SetLabelColor(color tcell.Color) *DropDown { d.labelColor = color @@ -140,8 +155,8 @@ func (d *DropDown) SetPrefixTextColor(color tcell.Color) *DropDown { } // SetFormAttributes sets attributes shared by all form items. -func (d *DropDown) SetFormAttributes(label string, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { - d.label = label +func (d *DropDown) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { + d.labelWidth = labelWidth d.labelColor = labelColor d.backgroundColor = bgColor d.fieldTextColor = fieldTextColor @@ -210,9 +225,10 @@ func (d *DropDown) SetDoneFunc(handler func(key tcell.Key)) *DropDown { return d } -// SetFinishedFunc calls SetDoneFunc(). +// SetFinishedFunc sets a callback invoked when the user leaves this form item. func (d *DropDown) SetFinishedFunc(handler func(key tcell.Key)) FormItem { - return d.SetDoneFunc(handler) + d.finished = handler + return d } // Draw draws this primitive onto the screen. @@ -227,8 +243,17 @@ func (d *DropDown) Draw(screen tcell.Screen) { } // Draw label. - _, drawnWidth := Print(screen, d.label, x, y, rightLimit-x, AlignLeft, d.labelColor) - x += drawnWidth + if d.labelWidth > 0 { + labelWidth := d.labelWidth + if labelWidth > rightLimit-x { + labelWidth = rightLimit - x + } + Print(screen, d.label, x, y, labelWidth, AlignLeft, d.labelColor) + x += labelWidth + } else { + _, drawnWidth := Print(screen, d.label, x, y, rightLimit-x, AlignLeft, d.labelColor) + x += drawnWidth + } // What's the longest option text? maxWidth := 0 @@ -359,6 +384,9 @@ func (d *DropDown) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr if d.done != nil { d.done(key) } + if d.finished != nil { + d.finished(key) + } } }) } -- cgit v1.2.3