• Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Social Media
    •   @Wings3dOfficial
    •   @Wings3dOfficial
    •   Wings3dOfficial
    •   Wings3dOfficial
  • Register
  • Login
  • Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Register
  • Login
Wings 3D Development Forum Wings 3D Programming v
1 2 3 4 Next »
"How to" about context menus

 
  • 0 Vote(s) - 0 Average
"How to" about context menus

micheus
Offline

Forum's Admin and Support | Bug fixer
Posts: 3,681
Threads: 185
Joined: Jun 2012
#2
05-27-2023, 06:01 AM (This post was last modified: 05-27-2023, 06:06 AM by micheus.)
Menu id's and action id's are going to be "packed" when them arrive in command handle function.

So, for our "Pure" sub-menus example we are going to define the command function like this:
PHP Code:
command({my_menu, id_option1}, St0) ->
    %% 
// Make some processing and update St as needed (if so)
    
:
    
St;
command({my_menu, {my_option, opt1}}, St0) ->
    %% 
// Make some processing and update St as needed (if so)
    
:
    
St;
command({my_menu, {my_option, opt2}}, St0) ->
    %% 
// Make some processing and update St as needed (if so)
    
:
    
St;
command(_, St) ->
    
St. 


When our menu items were set with option in the optional 4th parameter its value will be placed in a tuple composed by the packed command id and its value.
We also need to write at least two command function to handle it. The first one is going to handle the value returned by the menu item which will be a boolean value usually seen it named on Wings3D code as Ask. This first function will prepare and show a dialog that will be displayed to the user make the input. After the dialog be processed and ended with an OK then we are going to generate the second command which its pair in the tuple will be a list with the values of the elements we fill on the dialog/form.

So, by using our example for the single option menu, we can have a code like this:
PHP Code:
command({my_option, Ask}, #st{sel=Sel}=St) when is_atom(Ask)  ->
    
if Sel == [] ->
        
wings_u:message(?__(1,"A selection is required"));
    else
        
build_my_option_dialog(St);
    
end;
command({my_option, [{clear,true}]=_Ask}, St) ->
    
St#st{sel=[]};
command(_, St) -> St.

build_my_option_dialog(St) ->
    
Qs = [{hframe,[{?__(1,"Clear Selection"), false, [{key,clear}]}]}],
    
wings_dialog:dialog(Ask, ?__(1,"Handle Selection"), Qs, 
                        
fun(Opts) -> {my_option, Opts}} end). 
For more information about the dialog construction we can check the wings_dialog.erl which has a description of all elements supported(from line 40).


For the check marked options they can look like this fragment bellow, but a more "complex" example can be found in wings_view.erl source code.

To keep the preference updated for our use we need to switch its value in its respective command handle:
PHP Code:
command({my_check_option}, St) ->
    
Value = wings_pref:get_value(my_check_pref, false),
    
wings_pref:set_value(my_check_pref, not Value),
    
St;
  : 
[Image: tw.png] @MicheusVieira [Image: yt.png] @MicheusVieira [Image: da.png] Micheuss [Image: ig.png] micheus4wings3d
* Wings3D Team stands for: Björn and Dan
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Messages In This Thread
"How to" about context menus - by micheus - 05-24-2023, 03:00 PM
Menus: Command handles - by micheus - 05-27-2023, 06:01 AM

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode