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/checkbox.go | 40 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'vendor/maunium.net/go/tview/checkbox.go') diff --git a/vendor/maunium.net/go/tview/checkbox.go b/vendor/maunium.net/go/tview/checkbox.go index 83404b8..ae58720 100644 --- a/vendor/maunium.net/go/tview/checkbox.go +++ b/vendor/maunium.net/go/tview/checkbox.go @@ -17,6 +17,10 @@ type Checkbox struct { // The text to be displayed before the input area. label string + // The screen width of the label area. A value of 0 means use the width of + // the label text. + labelWidth int + // The label color. labelColor tcell.Color @@ -34,6 +38,10 @@ type Checkbox struct { // are done entering text. 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) } // NewCheckbox returns a new input field. @@ -68,6 +76,13 @@ func (c *Checkbox) GetLabel() string { return c.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 (c *Checkbox) SetLabelWidth(width int) *Checkbox { + c.labelWidth = width + return c +} + // SetLabelColor sets the color of the label. func (c *Checkbox) SetLabelColor(color tcell.Color) *Checkbox { c.labelColor = color @@ -87,8 +102,8 @@ func (c *Checkbox) SetFieldTextColor(color tcell.Color) *Checkbox { } // SetFormAttributes sets attributes shared by all form items. -func (c *Checkbox) SetFormAttributes(label string, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { - c.label = label +func (c *Checkbox) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem { + c.labelWidth = labelWidth c.labelColor = labelColor c.backgroundColor = bgColor c.fieldTextColor = fieldTextColor @@ -121,9 +136,10 @@ func (c *Checkbox) SetDoneFunc(handler func(key tcell.Key)) *Checkbox { return c } -// SetFinishedFunc calls SetDoneFunc(). +// SetFinishedFunc sets a callback invoked when the user leaves this form item. func (c *Checkbox) SetFinishedFunc(handler func(key tcell.Key)) FormItem { - return c.SetDoneFunc(handler) + c.finished = handler + return c } // Draw draws this primitive onto the screen. @@ -138,8 +154,17 @@ func (c *Checkbox) Draw(screen tcell.Screen) { } // Draw label. - _, drawnWidth := Print(screen, c.label, x, y, rightLimit-x, AlignLeft, c.labelColor) - x += drawnWidth + if c.labelWidth > 0 { + labelWidth := c.labelWidth + if labelWidth > rightLimit-x { + labelWidth = rightLimit - x + } + Print(screen, c.label, x, y, labelWidth, AlignLeft, c.labelColor) + x += labelWidth + } else { + _, drawnWidth := Print(screen, c.label, x, y, rightLimit-x, AlignLeft, c.labelColor) + x += drawnWidth + } // Draw checkbox. fieldStyle := tcell.StyleDefault.Background(c.fieldBackgroundColor).Foreground(c.fieldTextColor) @@ -170,6 +195,9 @@ func (c *Checkbox) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr if c.done != nil { c.done(key) } + if c.finished != nil { + c.finished(key) + } } }) } -- cgit v1.2.3