armory3d / zui

Immediate Mode User Interface
zlib License
314 stars 62 forks source link

ui.begin(g) --> TypeError: Cannot read property 'begin' of null #127

Closed Lykdraft closed 4 years ago

Lykdraft commented 4 years ago

Hey there, I am not sure if this is a Kha or Zui problem. Maybe you can help.

I tried all kinds of variations. I can't call ui.begin(g). Screen is black and Debug goes crazy.

Main:

 class Main {
    public static function main() : Void {
        System.start({title:"Project", width:1024, height:768}, initialized);
    }

    private static function initialized(window : Window) : Void {
       Assets.loadEverything(function(){
            var game = new Project();

            System.notifyOnFrames(
                function(fbs : Array<Framebuffer>) {
                game.render(fbs[0]);
                }
            );
            Scheduler.addTimeTask(game.update, 0, 1 / 60);
        });
    }
}

Project:

class Project {

    public var ui:Zui;

    public function new (){
        var ui = new Zui({ font: Assets.fonts.AndaleMono });
    }

    public function update():Void{
    }

    public function render (framebuffer:Framebuffer):Void{

        var g = framebuffer.g2;
        g.begin();
        g.drawRect(40,40,40,40,6);
        g.end();

        gui(g);
    }

    public function gui (graphics:Graphics){
        ui.begin(graphics);

        if (ui.window(Id.handle(),10,10,240,600)){
            if (ui.panel(Id.handle( {selected: true}),'panel',false,true)){
                ui.text('some text');
                ui.textInput(Id.handle( {text:'text input here'} ), 'textIn' );
                ui.check(Id.handle(), 'checkbox');
                ui.slider(Id.handle({value: 0.3}),'slider', 0, 2);
                Ext.colorPicker(ui, Id.handle());
            }
        }

        ui.end();
    }
}

Debug Console:

TypeError: Cannot read property 'begin' of null
SystemImpl.hx:60
    at Project.gui (/Volumes/HDD2/Luetze/Haxe/KHA/Kha Zui/Sources/Project.hx:45:2)
    at Project.render (/Volumes/HDD2/Luetze/Haxe/KHA/Kha Zui/Sources/Project.hx:39:3)
    at /Volumes/HDD2/Luetze/Haxe/KHA/Kha Zui/Sources/Main.hx:22:17
    at Function.kha_System.render (/usr/local/lib/haxe/lib/kha/git/Sources/kha/System.hx:196:4)
    at animate (/usr/local/lib/haxe/lib/kha/git/Backends/HTML5/kha/SystemImpl.hx:449:5)

Any ideas?

Thanks & best, tL.

Lykdraft commented 4 years ago

I think I got it, sorry 'bout that...

Lykdraft commented 4 years ago

Weeeell, no I don't. Can make it work in one file, can't make it work in two files. If you have an idea, please shoot...

luboslenco commented 4 years ago

Hi, sorry but that's not enough info for me to tell what is wrong. Please try playing with the examples first at https://github.com/armory3d/zui/tree/master/examples, that should help.

Lykdraft commented 4 years ago

Thank you. I've got eveything rolling now.