From 29b1b054412f26afe1900582a03a9e5c9c5597ab Mon Sep 17 00:00:00 2001 From: shmyga Date: Sat, 18 Jul 2015 00:02:21 +0300 Subject: [PATCH] view example update --- samples/01-view/src/ViewExample.hx | 7 ++++++- src/main/haxework/gui/Root.hx | 4 ++++ src/main/haxework/gui/build/Builder.hx | 6 +++--- src/main/haxework/gui/build/BuilderUtil.hx | 10 ++++++++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/samples/01-view/src/ViewExample.hx b/samples/01-view/src/ViewExample.hx index 55b5280..990f9b6 100755 --- a/samples/01-view/src/ViewExample.hx +++ b/samples/01-view/src/ViewExample.hx @@ -15,7 +15,12 @@ class ViewExample { } public function new() { - new Root(new FormView({listener:this})); + var form = new FormView({listener:this}); + Root.bind(form); + trace(form.panel); + trace(form.button1); + trace(form.button2); + trace(form.button3); } public function onPress(view:ButtonView):Void { diff --git a/src/main/haxework/gui/Root.hx b/src/main/haxework/gui/Root.hx index 8678d99..ce70d6f 100755 --- a/src/main/haxework/gui/Root.hx +++ b/src/main/haxework/gui/Root.hx @@ -10,6 +10,10 @@ import flash.display.Sprite; class Root { + public static function bind(view:IView, autoSize:Bool = true) { + new Root(view, autoSize); + } + public static var instance(default, null):Root; public var view(default, null):IView; diff --git a/src/main/haxework/gui/build/Builder.hx b/src/main/haxework/gui/build/Builder.hx index 52c34bc..f6d6fc6 100755 --- a/src/main/haxework/gui/build/Builder.hx +++ b/src/main/haxework/gui/build/Builder.hx @@ -25,12 +25,12 @@ class Builder { templateFile = Context.resolvePath(templatePath[0]); templateKey = templatePath[1]; - template = BuilderUtil.loadFile(templateFile); + template = BuilderUtil.loadJsonFile(templateFile); if (templateKey != null) template = Reflect.field(template, templateKey); if (templateMeta[1] != null) { styleFile = Context.resolvePath(templateMeta[1]); - style = BuilderUtil.loadFile(styleFile); + style = BuilderUtil.loadJsonFile(styleFile); } fields = Context.getBuildFields(); @@ -65,7 +65,7 @@ class Builder { case "class": a[1]; case "layout": - var template = BuilderUtil.loadFile(a[1]); + var template = BuilderUtil.loadJsonFile(a[1]); return getValue(name, key, template, position); case "link": "(links == null) ? untyped this : Reflect.field(links, \"" + a[1] + "\")"; diff --git a/src/main/haxework/gui/build/BuilderUtil.hx b/src/main/haxework/gui/build/BuilderUtil.hx index 7c6c125..5f2ac04 100755 --- a/src/main/haxework/gui/build/BuilderUtil.hx +++ b/src/main/haxework/gui/build/BuilderUtil.hx @@ -7,11 +7,17 @@ import haxe.macro.Expr.ExprDef; class BuilderUtil { - public static function loadFile(path:String, json:Bool = true) { + public static function loadJsonFile(path:String) { Context.registerModuleDependency(Context.getLocalModule(), path); var content = sys.io.File.getContent(path); + var json = null; + try { + json = PositionJsonParser.parse(content, path); + } catch(error:Dynamic) { + Context.error(error, Context.makePosition({min:0, max:0, file:path})); + } Context.parse(content, Context.makePosition({min:0, max:0, file:path})); - return json ? PositionJsonParser.parse(content, path) : content; + return json; } public static function getMeta(key:String):Array {