Skip to content

Commit

Permalink
slideToLeft/Right/Top/Bottom animations
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Jan 28, 2024
1 parent a9550bf commit c819107
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions haxe/ui/animation/AnimationTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,40 @@ class AnimationTools {
}
}


public static function slideToLeft(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(_) {
slideToLeft(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(destX), true);
builder.setPosition(100, "left", Std.int(originX), 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) {
Expand Down Expand Up @@ -92,6 +126,39 @@ class AnimationTools {
}
}

public static function slideToTop(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(_) {
slideToTop(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(destY), true);
builder.setPosition(100, "top", Std.int(originY), 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) {
Expand Down Expand Up @@ -124,6 +191,36 @@ class AnimationTools {
}
}

public static function slideToRight(c:Component, delayMs:Int = 0, onComplete:Void->Void = null, duration:Float = .2, easing:String = "linear") {
if (!c.isReady) {
c.registerEvent(UIEvent.READY, function(_) {
slideToRight(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(destX), true);
builder.setPosition(100, "left", Std.int(originX), true);
if (delayMs <= 0) {
builder.play();
} else {
haxe.ui.util.Timer.delay(function() {
builder.play();
}, 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) {
Expand Down Expand Up @@ -155,4 +252,36 @@ class AnimationTools {
}, delayMs);
}
}

public static function slideToBottom(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(_) {
slideToBottom(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(destY), true);
builder.setPosition(100, "top", Std.int(originY), true);
if (delayMs <= 0) {
builder.play();
c.opacity = 1;
} else {
haxe.ui.util.Timer.delay(function() {
builder.play();
c.opacity = 1;
}, delayMs);
}
}
}

0 comments on commit c819107

Please sign in to comment.