[add] frames views

This commit is contained in:
2020-01-17 14:51:03 +03:00
parent a4a33708a1
commit 10a01a971c
19 changed files with 341 additions and 139 deletions

View File

@@ -0,0 +1,48 @@
package ru.m.puzzlez.view;
import haxework.view.data.DataView;
import haxework.view.form.ButtonView;
import haxework.view.frame.FrameSwitcher;
import haxework.view.frame.FrameView;
import ru.m.puzzlez.core.ImageSource;
import ru.m.puzzlez.storage.AssetStorage;
import ru.m.puzzlez.storage.ISourceStorage;
import ru.m.puzzlez.storage.PixabayStorage;
typedef Source<T> = {
var storage:ISourceStorage<T>;
@:optional var type:T;
}
@:template class StartFrame extends FrameView<Dynamic> {
public static var ID = "start";
@:view var sources:DataView<Source<Dynamic>, ButtonView>;
@:provide var assetStorage:AssetStorage;
@:provide var pixabayStorage:PixabayStorage;
@:provide var switcher:FrameSwitcher;
public function new() {
super(ID);
var data:Array<Source<Dynamic>> = [];
data.push({storage: assetStorage});
for (type in AbstractEnumTools.getValues(PixabayCategory)) {
data.push({storage: pixabayStorage, type: type});
}
sources.data = data;
}
private function sourceViewFactory(index:Int, source:Source<Dynamic>):ButtonView {
var result = new ButtonView();
result.text = Std.string(source.type != null ? source.type : "custom");
return result;
}
private function load(source:Source<Dynamic>):Void {
source.storage.resolve(source.type).then(onLoaded);
}
private function onLoaded(result:Array<ImageSource>):Void {
switcher.change(ImagesFrame.ID, result);
}
}