Skip to content

Commit

Permalink
Added "autocompleteMatchFieldWidth"
Browse files Browse the repository at this point in the history
if autocompleteMatchFieldWidth is set to true the width of the autocomplete list
matches the fieldWidth of the inputfield.
  • Loading branch information
aditya-K2 committed Apr 6, 2023
1 parent e22ce95 commit 04e7c54
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions inputfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
matchFieldWidth bool
}

// NewInputField returns a new input field.
Expand Down Expand Up @@ -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.matchFieldWidth = 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 {
Expand Down Expand Up @@ -542,14 +552,17 @@ func (i *InputField) Draw(screen tcell.Screen) {
i.autocompleteListMutex.Lock()
defer i.autocompleteListMutex.Unlock()
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.matchFieldWidth {
// How much space do we need?
lwidth = 0
for index := 0; index < lheight; index++ {
entry, _ := i.autocompleteList.GetItemText(index)
width := TaggedStringWidth(entry)
if width > lwidth {
lwidth = width
}
}
}

Expand Down

0 comments on commit 04e7c54

Please sign in to comment.