view example update
This commit is contained in:
@@ -15,7 +15,12 @@ class ViewExample {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function new() {
|
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 {
|
public function onPress(view:ButtonView):Void {
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ import flash.display.Sprite;
|
|||||||
|
|
||||||
class Root {
|
class Root {
|
||||||
|
|
||||||
|
public static function bind(view:IView, autoSize:Bool = true) {
|
||||||
|
new Root(view, autoSize);
|
||||||
|
}
|
||||||
|
|
||||||
public static var instance(default, null):Root;
|
public static var instance(default, null):Root;
|
||||||
|
|
||||||
public var view(default, null):IView;
|
public var view(default, null):IView;
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ class Builder {
|
|||||||
templateFile = Context.resolvePath(templatePath[0]);
|
templateFile = Context.resolvePath(templatePath[0]);
|
||||||
templateKey = templatePath[1];
|
templateKey = templatePath[1];
|
||||||
|
|
||||||
template = BuilderUtil.loadFile(templateFile);
|
template = BuilderUtil.loadJsonFile(templateFile);
|
||||||
if (templateKey != null) template = Reflect.field(template, templateKey);
|
if (templateKey != null) template = Reflect.field(template, templateKey);
|
||||||
|
|
||||||
if (templateMeta[1] != null) {
|
if (templateMeta[1] != null) {
|
||||||
styleFile = Context.resolvePath(templateMeta[1]);
|
styleFile = Context.resolvePath(templateMeta[1]);
|
||||||
style = BuilderUtil.loadFile(styleFile);
|
style = BuilderUtil.loadJsonFile(styleFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fields = Context.getBuildFields();
|
fields = Context.getBuildFields();
|
||||||
@@ -65,7 +65,7 @@ class Builder {
|
|||||||
case "class":
|
case "class":
|
||||||
a[1];
|
a[1];
|
||||||
case "layout":
|
case "layout":
|
||||||
var template = BuilderUtil.loadFile(a[1]);
|
var template = BuilderUtil.loadJsonFile(a[1]);
|
||||||
return getValue(name, key, template, position);
|
return getValue(name, key, template, position);
|
||||||
case "link":
|
case "link":
|
||||||
"(links == null) ? untyped this : Reflect.field(links, \"" + a[1] + "\")";
|
"(links == null) ? untyped this : Reflect.field(links, \"" + a[1] + "\")";
|
||||||
|
|||||||
@@ -7,11 +7,17 @@ import haxe.macro.Expr.ExprDef;
|
|||||||
|
|
||||||
class BuilderUtil {
|
class BuilderUtil {
|
||||||
|
|
||||||
public static function loadFile(path:String, json:Bool = true) {
|
public static function loadJsonFile(path:String) {
|
||||||
Context.registerModuleDependency(Context.getLocalModule(), path);
|
Context.registerModuleDependency(Context.getLocalModule(), path);
|
||||||
var content = sys.io.File.getContent(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}));
|
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<String> {
|
public static function getMeta(key:String):Array<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user