Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added autocompleteMatchFieldWidth #835

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 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
autocompleteMatchFieldWidth 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.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 {
Expand Down Expand Up @@ -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 := 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
}
}
}

Expand Down