How to use a menu in hxWidgets

Hello, I started learning Haxe & HaxeUI a couple of weeks ago. I’m trying to port my little apps written in Python in Haxe but I’m experiencing some problems using the menu entries of the app menu. I’m writing an app using hxWidgets and everything works fine apart the menu management. In main-view.xml I put this portion of code:

<menubar id="mainMenu" width="100%" >
        <menu id="menuFile" text="File" >
            <menuitem id="menuRun" text="Run" />
            <menuitem id="menuQuit" text="Quit" />
        </menu>
</menubar>

Then I tried this piece of code found on this site, adding another check by myself:

        var menuBars = this.findComponents(MenuBar);
        trace("MenuBars:", menuBars.length);
        for (m in menuBars) {
            trace(" ---> " + m.id);
        }
        var menus = this.findComponents(Menu);
        trace("Menus:", menus.length);
        for (m in menus) {
            trace(" ---> " + m.id);
        }
        var menuItems = this.findComponents(MenuItem);
        trace("MenuItems:", menuItems.length);
        for (m in menuItems) {
            trace(" ---> " + m.id);
        }
        var menuRun = cast(findComponent("menuRun", MenuItem), MenuItem);
        trace(menuRun.text);

This is the output:

src/MainView.hx:34: MenuBars:,1
src/MainView.hx:36:  ---> mainMenu
src/MainView.hx:39: Menus:,1
src/MainView.hx:41:  ---> menuFile
src/MainView.hx:44: MenuItems:,2
src/MainView.hx:46:  ---> menuRun
src/MainView.hx:46:  ---> menuQuit
src/MainView.hx:50: Run

It seems out of doubt that the menu items are seen. But from now on I don’t know how to bind a function to catch an event. Sincererly, I don’t know which event to catch, too, because the documentations seems to be a little incomplete, IMHO… I tried the two solutions below but I didn’t get anything:

        menuRun.registerEvent(MenuEvent.MENU_SELECTED, function(me:MenuEvent) {
            trace(me.menuItem.id);
        });
        menuRun.onChange = function(e) {
            trace('hello');
        }

Any suggestions? Thanks.

None has suggestions?

Hi, fellow hxwidgets user!
you shouldn’t register the event on the menubar

// was menuRun should be mainMenu
mainMenu.registerEvent(MenuEvent.MENU_SELECTED, function(me:MenuEvent) {
            trace(me.menuItem.id);
        });

but on mainMenu…

Look at this example

https://haxeui.org/builder/?a05936d2

( Click on view/Project to see all the files)

PS: it easier to get help on haxe discord ( there’s a haxeui channel) as the forum is not often checked… ofc if you have no discord better to post here ( and better for search engines too!)

Thank you my friend! That worked like a charme!
You saved my head! You can’t imagine how many times I slammed it into the wall :face_with_head_bandage:
Problem solved.

PS: HaxeUI seems a good framework to build desktop apps, for now.

You’re welcome :slight_smile:

PS: HaxeUI seems a good framework to build desktop apps, for now.

Yeah really nice… Of course you can’t do as much with hxwidgets as other backends but I like it, it’s so nice having a real desktop app.