I
think this is what you were aiming for, we'll see.
First problem is multiple inputs on one screen. You can only ever edit one at a time, so we need some kind of focus control - in this case the
active var. We also modulus this when using it to ensure we loop around the inputs in both directions. This is a really basic hacky version, but for this simple case in a screen containing nothing else it works well enough, just a heads up that you may need to revisit it depending on how you use it. Those key definitions should probably be in a proper keymap too, but we'll leave it there for now. :P
The words we're not currently editing, we may wish to click so we can edit them, so we use a button with similar styling to the frame we put out active input into. This minimises the visual difference while still keeping apparent which is currently being edited.
Finally we abuse the fact that the
DictInputValue is just implicitly using the
__getitem__/
__setitem__ methods on the var we hand it, so it doesn't matter that what we're really giving it is a list, so long as the index is valid. It also results in the data being updated in place since we're giving it a reference to the list in the original data structure (rather than a copy), so there's no worry about needing to return the updated values.
End result is a vertical list of values that may be edited, and tab/shift+tab can be used to navigate up and down the list, as well as clicking the specific item you wish to edit. The Enter or NumpadEnter keys will progress forward from the screen and display the contents of the newly updated data structure.
Code: Select all
screen codepoem():
default active = 1
frame:
align 1., 0.
for k, v in currentpoem.items():
vbox:
label k
text "-----"
for i in xrange(len(v)):
if i == active % len(v):
frame:
background '#fff6'
padding 2, 2
xysize 100, 20
input:
value DictInputValue(v, i)
else:
button:
action SetScreenVariable('active', i)
hover_background '#fff3'
padding 2, 2
xysize 100, 20
text v[i]
key 'K_TAB' action SetScreenVariable('active', active + 1)
key 'repeat_K_TAB' action SetScreenVariable('active', active + 1)
key 'shift_K_TAB' action SetScreenVariable('active', active - 1)
key 'repeat_shift_K_TAB' action SetScreenVariable('active', active - 1)
key 'input_enter' action Return()
default currentpoem = {"Szabo": ["The", "live", "that", "I", "have", "is", "all", "that", "I", "have"]}
label start:
call screen codepoem()
"Testing [currentpoem!q]"
return