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

kvui: Implemented and tested hint autocomplete suggestions #3537

Open
wants to merge 1 commit into
base: kvui_autocomplete_hint
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion data/client.kv
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,14 @@
size_hint_y: None
height: dp(30)
multiline: False
write_tab: False
write_tab: False
<AutocompleteHintDropdownButton>
size_hint_y: None
height: dp(30)
padding: [dp(5), 0]
text_size: self.size
shorten: True
multiline: False
halign: 'left'
valign: 'center'
markup: True
10 changes: 7 additions & 3 deletions kvui.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,14 @@ def apply_selection(self, rv, index, is_selected):
self.selected = is_selected


class AutocompleteHintDropdownButton(Button):
pass


class AutocompleteHintInput(TextInput):
min_chars = NumericProperty(3)

def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)

self.dropdown = DropDown()
Expand All @@ -319,7 +323,7 @@ def on_text(self, instance, value):
ctx: context_type = App.get_running_app().ctx
item_names = ctx.item_names._game_store[ctx.game].values()

def on_press(button: Button):
def on_press(button: AutocompleteHintDropdownButton):
split_text = MarkupLabel(text=button.text).markup
return self.dropdown.select("".join(text_frag for text_frag in split_text
if not text_frag.startswith("[")))
Expand All @@ -332,7 +336,7 @@ def on_press(button: Button):
else:
text = escape_markup(item_name)
text = text[:index] + "[b]" + text[index:index+len(value)]+"[/b]"+text[index+len(value):]
btn = Button(text=text, size_hint_y=None, height=dp(30), markup=True)
btn = AutocompleteHintDropdownButton(text=text)
btn.bind(on_release=on_press)
self.dropdown.add_widget(btn)
if not self.dropdown.attach_to:
Expand Down
Loading