How do I show the menu button on main menu by codes?

117 Views Asked by At

I have a main menu with 2 menu buttons - settingBtn and featurBtn. vbf is the main form.

I try to click the settingBtn button in main menu, open the setting Form, do something, click the featureBtn in main menu, and open the featureForm by codes.

    vbf.getToolbar().openSideMenu();
    timer = UITimer.timer(200, true, ()->{
        if (vbf.getToolbar().isSideMenuShowing()){
            Component cp = vc.settingBtn;
            System.out.println(cp.getParent().getClass().getName());                
            Dialog dlg = new Dialog("settingBtn Clicked");
            dlg.showPopupDialog(cp);
            vbf.getToolbar().closeSideMenu();
            timer.cancel();
    
        }
    });
    vbf.getToolbar().openSideMenu();
    cmp = vc.featureBtn;
    Dialog dlg = new Dialog("featureBtn Clicked");
    dlg.showPopupDialog(cp);
    vbf.getToolbar().closeSideMenu(); 

The program has issues:

  1. dlg.ShowDialog(cp) won't show at the position of the buttons if the buttons are in the main menu. It always show at the left-top of main menu.
  2. The process keeps opening and closing the menu many times. I can't put all the code in UITimer. Because a UI timer is only for one time opening sidemenu.

Component Hierarchy in the inspector

enter image description here

1

There are 1 best solutions below

20
Shai Almog On

The openSideMenu() call is asynchronous since there's an animation involved. You started that animation yet disposed the menu before it had the chance to show up.

Unfortunately, at the moment there's no way to get an event when the side menu actually shows up. However, I added the following call to Toolbar: boolean isSideMenuShowing() as part of this commit.

You can use a timer and wait for this method to return true at which point you can continue with the logic of the walk through tour. This commit should become a part of the release on January 12th 2024.

E.g.:

Form hi = new Form("Hi World");
hi.getToolbar().addMaterialCommandToSideMenu("Hello", FontImage.MATERIAL_AIR, e -> {});
hi.show();
UITimer.timer(1000, true, () -> {
    Log.p("Side menu: " + hi.getToolbar().isSideMenuShowing());
});