From 1ada6e5074789789367f27a4b135f280598f851e Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Fri, 7 Apr 2023 04:03:14 +0530 Subject: [PATCH] Added `autocompleteMatchFieldWidth` if `autocompleteMatchFieldWidth` is set to true the width of the autocomplete list matches the `fieldWidth` of the input field. --- inputfield.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/inputfield.go b/inputfield.go index 75e180b8..7b4c5cb7 100644 --- a/inputfield.go +++ b/inputfield.go @@ -127,6 +127,10 @@ type InputField struct { fieldX int // The x-coordinate of the input field as determined during the last call to Draw(). offset int // The number of bytes of the text string skipped ahead while drawing. + + // If this field is set to true then the Autocomplete List has the same width + // as the fieldWidth + autocompleteMatchFieldWidth bool } // NewInputField returns a new input field. @@ -289,6 +293,12 @@ func (i *InputField) SetDisabled(disabled bool) FormItem { return i } +// SetAutocompleteMatchFieldWidth sets whether or not the AutoComplete List +// should have a width equal to the fieldWidth +func (i *InputField) SetAutocompleteMatchFieldWidth(match bool) { + i.autocompleteMatchFieldWidth = match +} + // SetMaskCharacter sets a character that masks user input on a screen. A value // of 0 disables masking. func (i *InputField) SetMaskCharacter(mask rune) *InputField { @@ -544,12 +554,15 @@ func (i *InputField) Draw(screen tcell.Screen) { if i.autocompleteList != nil { // How much space do we need? lheight := i.autocompleteList.GetItemCount() - lwidth := 0 - for index := 0; index < lheight; index++ { - entry, _ := i.autocompleteList.GetItemText(index) - width := TaggedStringWidth(entry) - if width > lwidth { - lwidth = width + lwidth := i.fieldWidth + if !i.autocompleteMatchFieldWidth { + lwidth = 0 + for index := 0; index < lheight; index++ { + entry, _ := i.autocompleteList.GetItemText(index) + width := TaggedStringWidth(entry) + if width > lwidth { + lwidth = width + } } }