live update
ukos
I'm having a panel with a setvar input field. I would like to process the input directly as it is typed.
Currently the only way for getting the event is pressing [Enter] or leaving the field with a mouse click action.
I'm trying to get a live update as the user types in sth. JSON in java or onChange() in VBA would probably be the pendant.
Window Panel() : Panel
NewPanel /W=(150,77,454,190) as "Panel"
String/G temp
SetVariable setvar,pos={61.00,19.00},size={176.00,15.00},proc=SetVarProc
SetVariable setvar,limits={-inf,inf,0},value= temp,live= 1
EndMacro
Function SetVarProc(sva) : SetVariableControl
STRUCT WMSetVariableAction &sva
switch( sva.eventCode )
case 1: // mouse up
case 2: // Enter key
case 3: // Live update
Variable dval = sva.dval
String sval = sva.sval
print sval, dval
break
case -1: // control being killed
break
endswitch
return 0
End
NewPanel /W=(150,77,454,190) as "Panel"
String/G temp
SetVariable setvar,pos={61.00,19.00},size={176.00,15.00},proc=SetVarProc
SetVariable setvar,limits={-inf,inf,0},value= temp,live= 1
EndMacro
Function SetVarProc(sva) : SetVariableControl
STRUCT WMSetVariableAction &sva
switch( sva.eventCode )
case 1: // mouse up
case 2: // Enter key
case 3: // Live update
Variable dval = sva.dval
String sval = sva.sval
print sval, dval
break
case -1: // control being killed
break
endswitch
return 0
End
What are you trying to achieve?
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
January 14, 2016 at 04:54 pm - Permalink
I try to update search results in a list on-the-fly via an "search"-input field.
Would be great to have it show the results while typing.
Hitting the Enter button is probably enough as a solution. The drawbag of hitting enter is that the box looses the fokus and you have to click in the field again.
January 15, 2016 at 06:57 am - Permalink
SetVariable ctrlName, activate
command option. This will highlight the setvar box again. Unfortunately, it also selects the whole text, so you cannot just continue typing. But a 'type' -> 'enter'(or up/down arrow in live update) -> 'right arrow' -> 'type' cycle might be faster than reactivating the control via click / tab. If you use up/down arrows for updating your search you could assign the enter key to terminate the input.January 19, 2016 at 10:23 pm - Permalink
I came across this while trying to accomplish the same thing recently- using a SetVariable string input as a live search that controls a drop down menu which updates on each keystroke. For anyone's future reference, you can hack your way into this behavior (it's not pretty but it ends up working and actually looks decent). It goes like this:
Upon clicking the SetVariable, immediately send focus back to the main panel and set a window hook that will detect mouse movements and keystrokes.
By using a window hook, each keystroke can be sent to the SetVariable to display, while also updating a menu. Don't use a normal popupmenu or even a contextual menu though, since it receives focus and will disrupt keystrokes. You have to fake the menu by printing out the list of menu items manually using DrawText. For it to look decent, I first display a group box sized according to the number of menu items, and print the items on top of it. It looks enough like a real menu for me. For mine, I also hook backspace/delete to gain that functionality over the string input.
For selecting something from the menu:
Using mouse move events in the hook function, you can detect the mouse location relative to the text (where each item has a known location) to record the user's menu selection on mouse down events. The selection can be shown live as a colored text item in the 'menu'. Alternatively, detect arrow keystrokes to toggle the selection up and down. On mouse down or a 'return/enter' keystroke, return the selected item from the fake menu, kill the window hook, and delete the text with DrawAction.
I'm pretty happy with how mine turned out, it lets me live search through probably a hundred different user-defined functions in my GUI very quickly without having to navigate through a popup menu with a bunch of submenus, and doesn't have very noticeable lag.
October 24, 2022 at 04:00 pm - Permalink
see also here, where I used a notebook subwindow instead of a setvariable.
October 24, 2022 at 11:43 pm - Permalink