haxeui / haxeui-heaps

MIT License
31 stars 12 forks source link

Don't use INDEX_OFFSET in _children. #22

Closed back2dos closed 3 years ago

back2dos commented 3 years ago

The way I'm reading things, the INDEX_OFFSET is meant for h2d's indices.

The offset causes a bug when removing elements by index. Minimal example:

var app = new HaxeUIApp();

app.ready(function() {
    var root = new Component();
    Screen.instance.addComponent(root);
    var button = new Button();
    button.text = 'Zombie';
    root.addComponent(button);
    button.onClick = _ -> {
        root.removeComponentAt(0);
    }
    app.start();
});

Clicking on the button will not remove it.

Interestingly, removing the button immediately after adding it causes the button not to render, even though root.numChildren yields 2, which indicates it is still in the h2d display list (but maybe empty components bail out of rendering or something?).

ianharrigan commented 3 years ago

Thanks Juraj... for some reason when i read the code i assumed "_children" was the child array of heaps, not haxeui - so as you point out, that index doesnt make sense.

Thanks again, Ian

EDIT: i think the other issue you mention was another (pretty huge) issue with the fact that nothing ever go disposed of in haxeui-heaps... helluva oversight! That should also be fixed: https://github.com/haxeui/haxeui-heaps/commit/760b5a8beeb9cdbc961c96fd04e5d78a01818cb4