haxeui / haxeui-flixel

The Flixel backend of the HaxeUI framework
MIT License
48 stars 15 forks source link

MenuBar Menu items not updating text when changed by code #24

Closed Bloodninj closed 2 years ago

Bloodninj commented 2 years ago

Expected Behavior

When the .text property of a <menu> item on a <menubar>, the text on the item should update in-game.

Current Behavior

Text does not update, instead keeping the value provided from XML. Child <menuitem> elements of a <menu> can be updated via code as expected.

Possible Solution

Steps to Reproduce (for bugs)

  1. Create an XML layout that contains a <menubar> element with at least one child <menu> element
  2. Create a container class from the XML using build macros
  3. Update the .text property of a <menu> element via code

Media

Screenshot from 2022-01-04 13-30-36

Test app / minimal test case

import flixel.FlxState; import haxe.ui.Toolkit; import haxe.ui.containers.VBox; import haxe.ui.containers.menus.Menu; import haxe.ui.containers.menus.MenuBar;

class PlayState extends FlxState { var myMenu:MyMenuBar;

override public function create()
{
    super.create();
    Toolkit.init();
    Toolkit.autoScale = false;
    myMenu = new MyMenuBar();
    add(myMenu);
}

override public function update(elapsed:Float)
{
    super.update(elapsed);
}

}

@:build(haxe.ui.macros.ComponentMacros.build("assets/ui/menuView.xml")) class MyMenuBar extends VBox { public function new() { super(); fileMenu.text = "My text"; fileItem1.text = "Replaced text 1"; fileItem2.text = "Replaced text 2"; fileItem3.text = "Replaced text 3"; } }

* menuView.xml:
```xml
<vbox width="100%">
    <menubar id="menuBar" width="100%">
        <menu id="fileMenu" text="placeholder 1">
            <menuitem id="fileItem1" text="test 1" />
            <menuitem id="fileItem2" text="test 2" />
            <menuitem id="fileItem3" text="test 3" />
        </menu>
        <menu id="editMenu" text="placeholder 2">
            <menuitem id="editItem1" text="test 1" />
            <menuitem id="editItem2" text="test 2" />
            <menuitem id="editItem3" text="test 3" />
        </menu>
    </menubar>
</vbox>

Context

I am attempting to replace the text with translated text for the user's chosen language.

Your Environment