Skip to content

ContextMenu

Eric edited this page Nov 18, 2022 · 3 revisions

ContextMenu is a simple context menu based on DynamicList. To use this component, set disable_context:true in your app options.

Here we create a context menu and then add it as a node to the current stage

 const cmenu = new OGX.ContextMenu({
       x:100,
       y:100,
       callback:myCallback,
       list:[{label:'Insert Item'}, {label:'Remove Selected Item'}]
 });
 app.getStage().add(cmenu);

Complete code creating from a View and instancing on active Stage on right click

 myview.el.on(myview.touch.down, function(__e){
       if(myview.touch.isRightClick(__e)){
           __e.preventDefault();
           __e.stopImmediatePropagation();
           __e = myview.event(__e);
           if(app.cfind('ContextMenu', 'context')){
               app.remove('ContextMenu', 'context');
           }                   
           var l = [{label:'Add Class', action:'add', type:'class'}, {label:'Add Event', action:'add', type:'event'}];                             
           app.getStage().create('ContextMenu', {
               id:'context',
               x:__e.pageX,
               y:__e.pageY,
               callback:onContextSelect,
               list:l
           });
           return false;
       }
   });        

   function onContextSelect(__item){ ... }   
Clone this wiki locally