Description
I have a UI panel for logging onto a server (it's an online game) which has a number of text entry lines. I wanted the user to be able to cycle through them using the TAB key.
In order to do this, I have implemented a list of the relevant text line objects, and applied an itertools cycle to them. When TAB is pressed, it positions this cycle, by cycling until it finds the element which matches manager.focused_element, then shifts focus to the next item, and selects all the text within it.
This required modifying the UITextEntryLine class, in order to add K_TAB to the _process_action_key_event method, merely to prevent the keypress being taken as an input.
This could probably be most neatly handled at the UIManager level, if it's thought that it could add value enough to justify it. Providing a "tab_order" parameter to the text_input_line class (and potentially buttons) could allow this to be implemented, perhaps on a container-wide level.
def tab_cycle(self):
focused_elem = self.manager.focused_element
while focused_elem != next(self.focus_cycle):
continue
focus_elem = next(self.focus_cycle)
self.manager.set_focus_element(focus_elem)
focus_elem.select_range = [0, len(focus_elem.text)]