Permalink
Browse files

UI: Add tween for translating anchor offsets.

  • Loading branch information...
unknownbrackets committed Dec 10, 2017
1 parent bab66e8 commit 6783394ae1011cdffa597d857a7b5c5d537e2514
Showing with 31 additions and 0 deletions.
  1. +4 −0 ext/native/math/geom2d.h
  2. +17 −0 ext/native/ui/ui_tween.cpp
  3. +10 −0 ext/native/ui/ui_tween.h
@@ -14,6 +14,10 @@ struct Point {
return sqrtf(dx*dx + dy*dy);
}
bool operator ==(const Point &other) const {
return x == other.x && y == other.y;
}
/*
FocusDirection directionTo(const Point &other) const {
int angle = atan2f(other.y - y, other.x - x) / (2 * M_PI) - 0.125;
@@ -1,6 +1,7 @@
#include "base/colorutil.h"
#include "ui/ui_tween.h"
#include "ui/view.h"
#include "ui/viewgroup.h"
namespace UI {
@@ -66,6 +67,7 @@ void TweenBase<Value>::PersistData(PersistStatus status, std::string anonId, Per
template void TweenBase<uint32_t>::PersistData(PersistStatus status, std::string anonId, PersistMap &storage);
template void TweenBase<Visibility>::PersistData(PersistStatus status, std::string anonId, PersistMap &storage);
template void TweenBase<Point>::PersistData(PersistStatus status, std::string anonId, PersistMap &storage);
uint32_t ColorTween::Current(float pos) {
return colorBlend(to_, from_, pos);
@@ -96,4 +98,19 @@ Visibility VisibilityTween::Current(float p) {
return p >= 1.0f ? to_ : from_;
}
void AnchorTranslateTween::DoApply(View *view, float pos) {
Point cur = Current(pos);
auto prev = view->GetLayoutParams()->As<AnchorLayoutParams>();
auto lp = new AnchorLayoutParams(prev ? *prev : AnchorLayoutParams(FILL_PARENT, FILL_PARENT));
lp->left = cur.x;
lp->top = cur.y;
view->ReplaceLayoutParams(lp);
}
Point AnchorTranslateTween::Current(float p) {
float inv = 1.0f - p;
return Point(from_.x * inv + to_.x * p, from_.y * inv + to_.y * p);
}
} // namespace
@@ -182,4 +182,14 @@ class VisibilityTween : public TweenBase<Visibility> {
Visibility Current(float pos) override;
};
class AnchorTranslateTween : public TweenBase<Point> {
public:
using TweenBase::TweenBase;
protected:
void DoApply(View *view, float pos) override;
Point Current(float pos) override;
};
} // namespace

0 comments on commit 6783394

Please sign in to comment.