Scroll Panel

To enable vertical scrolling of all controls in a panel with the mouse wheel, as if there was a scroll bar, put this in a procedure file:

Function ScrollHook(info)
    Struct WMWinHookStruct &info
   
    if(info.eventCode == 22)
        string controls = ControlNameList(info.winName)
        variable i
        for(i=0;i<itemsinlist(controls);i+=1)
            string control = stringfromlist(i,controls)
            ModifyControl $control pos+={0,info.wheelDy}
        endfor
    endif
End


Then activate a given panel with this:

SetWindow my_panel hook(scroll)=ScrollHook


I offer this refinement to Rick's cool code snippet:

Function PanelScrollHook(info)
    Struct WMWinHookStruct &info
 
    strswitch( info.eventName )
        case "mouseWheel":
            // If the mouse wheel is above a subwindow, info.name won't be the top level window
            // This test allows the scroll wheel to work normally when over a table subwindow.
            Variable mouseIsOverSubWindow= ItemsInList(info.WinName,"#") > 1
            if( !mouseIsOverSubWindow )
                String controls = ControlNameList(info.winName)
                Variable shiftKeyIsDown = info.eventMod & 0x2
                if( shiftKeyIsDown )
                    Variable dx
                    #ifdef MACINTOSH
                        dx= info.wheelDx
                    #else
                        dx= info.wheelDy
                    #endif
                    ModifyControlList controls, win=$info.winName, pos+={dx,0}  // left/right
                else
                    ModifyControlList controls, win=$info.winName, pos+={0,info.wheelDy}    // up/down
                endif
            endif
            break
    endswitch
    return 0    // process all events normally
End


It's not perfect, however: if the mouse is over a control that uses the mouse wheel, that action happens, too, so the control's value changes AND the controls all move.

Better would be to detect whether the mouse if over a control, and only if not, THEN move the controls.

Or perhaps just use a slider or a listbox full of controls.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More