Skip to content

Commit

Permalink
slide animation tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Nov 17, 2023
1 parent 65a756e commit bfdb498
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 4 deletions.
132 changes: 132 additions & 0 deletions haxe/ui/animation/AnimationTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package haxe.ui.animation;

import haxe.ui.animation.AnimationBuilder;
import haxe.ui.core.Component;
import haxe.ui.core.Screen;
import haxe.ui.events.UIEvent;
import haxe.ui.util.Color;

@:access(haxe.ui.core.Component)
Expand All @@ -23,4 +25,134 @@ class AnimationTools {
}
return builder;
}

public static function slideFromLeft(c:Component, delayMs:Int = 0, onComplete:Void->Void = null, duration:Float = .2, easing:String = "linear") {
c.opacity = 0;
if (!c.isReady) {
c.registerEvent(UIEvent.READY, function(_) {
slideFromLeft(c, delayMs, onComplete, duration, easing);
});
return;
}
c.validateNow();
var parentX:Float = 0;
if (c.parentComponent != null) {
parentX = c.parentComponent.screenLeft;
}
var destX = c.screenLeft - parentX;
var originX = 0 - c.width - parentX;

c.left = originX;

var builder = new AnimationBuilder(c, duration, easing);
builder.onComplete = onComplete;
builder.setPosition(0, "left", Std.int(originX), true);
builder.setPosition(100, "left", Std.int(destX), true);
if (delayMs <= 0) {
builder.play();
c.opacity = 1;
} else {
haxe.ui.util.Timer.delay(function() {
builder.play();
c.opacity = 1;
}, delayMs);
}
}

public static function slideFromTop(c:Component, delayMs:Int = 0, onComplete:Void->Void = null, duration:Float = .2, easing:String = "linear") {
c.opacity = 0;
if (!c.isReady) {
c.registerEvent(UIEvent.READY, function(_) {
slideFromTop(c, delayMs, onComplete, duration, easing);
});
return;
}
c.validateNow();
var parentY:Float = 0;
if (c.parentComponent != null) {
parentY = c.parentComponent.screenTop;
}
var destY = c.screenTop - parentY;
var originY = 0 - c.height - parentY;

c.top = originY;

var builder = new AnimationBuilder(c, duration, easing);
builder.onComplete = onComplete;
builder.setPosition(0, "top", Std.int(originY), true);
builder.setPosition(100, "top", Std.int(destY), true);
if (delayMs <= 0) {
builder.play();
c.opacity = 1;
} else {
haxe.ui.util.Timer.delay(function() {
builder.play();
c.opacity = 1;
}, delayMs);
}
}

public static function slideFromRight(c:Component, delayMs:Int = 0, onComplete:Void->Void = null, duration:Float = .2, easing:String = "linear") {
c.opacity = 0;
if (!c.isReady) {
c.registerEvent(UIEvent.READY, function(_) {
slideFromRight(c, delayMs, onComplete, duration, easing);
});
return;
}
c.validateNow();
var parentX:Float = 0;
if (c.parentComponent != null) {
parentX = c.parentComponent.screenLeft;
}
var destX = c.screenLeft - parentX;
var originX = (Screen.instance.width) - parentX;

c.left = originX;
var builder = new AnimationBuilder(c, duration, easing);
builder.onComplete = onComplete;
builder.setPosition(0, "left", Std.int(originX), true);
builder.setPosition(100, "left", Std.int(destX), true);
if (delayMs <= 0) {
builder.play();
c.opacity = 1;
} else {
haxe.ui.util.Timer.delay(function() {
builder.play();
c.opacity = 1;
}, delayMs);
}
}

public static function slideFromBottom(c:Component, delayMs:Int = 0, onComplete:Void->Void = null, duration:Float = .2, easing:String = "linear") {
c.opacity = 0;
if (!c.isReady) {
c.registerEvent(UIEvent.READY, function(_) {
slideFromBottom(c, delayMs, onComplete, duration, easing);
});
return;
}
c.validateNow();
var parentY:Float = 0;
if (c.parentComponent != null) {
parentY = c.parentComponent.screenTop;
}
var destY = c.screenTop - parentY;
var originY = (Screen.instance.height) - parentY;

c.top = originY;
var builder = new AnimationBuilder(c, duration, easing);
builder.onComplete = onComplete;
builder.setPosition(0, "top", Std.int(originY), true);
builder.setPosition(100, "top", Std.int(destY), true);
if (delayMs <= 0) {
builder.play();
c.opacity = 1;
} else {
haxe.ui.util.Timer.delay(function() {
builder.play();
c.opacity = 1;
}, delayMs);
}
}
}
4 changes: 2 additions & 2 deletions haxe/ui/styles/animation/Animation.hx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package haxe.ui.styles.animation;

import haxe.ui.constants.AnimationFillMode;
import haxe.ui.constants.AnimationDirection;
import haxe.ui.util.StyleUtil;
import haxe.ui.constants.AnimationFillMode;
import haxe.ui.styles.EasingFunction;
import haxe.ui.styles.elements.AnimationKeyFrames;
import haxe.ui.util.StyleUtil;

@:structInit
class AnimationOptions {
Expand Down
4 changes: 2 additions & 2 deletions haxe/ui/styles/animation/util/Actuator.hx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package haxe.ui.styles.animation.util;

import haxe.ui.util.MathUtil;
import haxe.ui.core.Component;
import haxe.ui.core.TypeMap;
import haxe.ui.styles.EasingFunction;
import haxe.ui.util.Color;
import haxe.ui.util.MathUtil;
import haxe.ui.util.StringUtil;
import haxe.ui.util.StyleUtil;
import haxe.ui.util.Variant;
import haxe.ui.util.Variant.VariantType;
import haxe.ui.util.Variant;

@:structInit
class ActuatorOptions {
Expand Down

0 comments on commit bfdb498

Please sign in to comment.