[view] add back method to frame switcher

This commit is contained in:
2020-02-05 23:18:29 +03:00
parent a6ff04fd1b
commit 07c228121c
2 changed files with 15 additions and 4 deletions

View File

@@ -18,6 +18,7 @@ class ButtonView extends LabelView {
public var disabled(default, set):Bool; public var disabled(default, set):Bool;
public var state(get, null):ButtonState; public var state(get, null):ButtonState;
public var onPress(default, null):Signal<ButtonView>; public var onPress(default, null):Signal<ButtonView>;
public var propagation(default, default):Bool;
private var overed:Bool; private var overed:Bool;
private var downed:Bool; private var downed:Bool;
@@ -26,6 +27,7 @@ class ButtonView extends LabelView {
super(); super();
skin = new ButtonColorSkin(); skin = new ButtonColorSkin();
style = "button"; style = "button";
propagation = true;
overed = false; overed = false;
downed = false; downed = false;
state = ButtonState.UP; state = ButtonState.UP;
@@ -47,7 +49,7 @@ class ButtonView extends LabelView {
private function onMouseClick(event:MouseEvent):Void { private function onMouseClick(event:MouseEvent):Void {
#if js if (downed) { #end #if js if (downed) { #end
//event.stopImmediatePropagation(); if (!propagation) event.stopImmediatePropagation();
if (!disabled) onPress.emit(this); if (!disabled) onPress.emit(this);
#if js } #end #if js } #end
} }

View File

@@ -17,11 +17,13 @@ class FrameSwitcher extends GroupView {
public var animateFactory(default, default):Class<IAnimate>; public var animateFactory(default, default):Class<IAnimate>;
private var animate:IAnimate; private var animate:IAnimate;
private var history:Array<{id:String, data:Dynamic}>;
public function new() { public function new() {
super(); super();
factory = new Map(); factory = new Map();
frames = new Map(); frames = new Map();
history = [];
current = null; current = null;
} }
@@ -65,16 +67,23 @@ class FrameSwitcher extends GroupView {
} }
animate = buildAnimate(current); animate = buildAnimate(current);
if (animate != null && prev != null) { if (animate != null && prev != null) {
animate.start(function(_) { animate.start(function(_) removePrev(prev));
removePrev(prev);
});
} else { } else {
removePrev(prev); removePrev(prev);
} }
history.push({id:current.frameId, data:data});
onSwitch.emit(current); onSwitch.emit(current);
return cast current; return cast current;
} }
public function back():Void {
if (history.length > 1) {
history.pop();
var item = history.pop();
change(item.id, item.data);
}
}
private function removePrev(prev:Null<FrameView<Dynamic>>):Void { private function removePrev(prev:Null<FrameView<Dynamic>>):Void {
if (prev != null) { if (prev != null) {
prev.onHide(); prev.onHide();