Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animatable Size #86

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open

Animatable Size #86

wants to merge 25 commits into from

Conversation

benjaminbojko
Copy link
Collaborator

@benjaminbojko benjaminbojko commented Jul 23, 2017

This branch adds support for animated sizes in all view implementations.

This is a fairly big incision across all views, since many of them need to react to size changes. Previously, this could simply be done by overriding setSize(), but when the size is animated, views won't know when the size is changed that way.

Subclassing

The solution in this branch was to override validateContent(), which gets called by BaseView::update() whenever the content (e.g. background color, alpha, or size) was changed since the last update(). This method already existed, but wasn't used by BaseView subclasses as consistently.

As a bonus I also implemented #59 because invalidate() now carries more weight and needed to be more explicit.

Compatibility

As part of this change, I also added a AnimationUtils.h header, which could almost be its own Cinder block or a PR, but I'm not 100% confident about how kosher this is. What it does is to provide a ton of operator overloads for ci::Anim<T> so you can do getSize() * 0.5f or viewA->getSize() + viewB->getSize() instead of calling getSize().value() or getSize()() all the time.

Since it's templated, this will work for any ci::Anim<T> (e.g. view->getPosition() + vec2(100) or view->setAlpha(view->getAlpha() * 0.5f).

This seems to work pretty well except for += and type conversion (e.g. adding ivec2 with Anim<vec2>. Those might still be possible to implement and I might get to it eventually. I'll let this PR sit for a bit (maybe next weekend) and slowly start trying this out in production code (this is still only tested with a single sample app).

Retrieving x and y from size will still require you to call getSize().value().x or keep using getWidth().

Performance

Warning: Changing the size on TextView and FboView is pretty expensive, because TextView needs to recalculate its layout, render everything to a surface and a texture and FboView needs to create a new texture whenever their sizes change.

Todos

  • Test in production and remaining view samples
  • Create a new, tagged release and version from this branch since this is a fairly important API change

Implements #32 and #59

@benjaminbojko benjaminbojko self-assigned this Jul 23, 2017
@peterchappy
Copy link

👀

@benjaminbojko
Copy link
Collaborator Author

👋

@peterchappy
Copy link

Hope all is well 🤗 Was just talking about this library yesterday and was wondering where it's at 👯‍♂

@benjaminbojko
Copy link
Collaborator Author

Hope all is well 🤗 Was just talking about this library yesterday and was wondering where it's at 👯‍♂

Oh awesome, in what context?

We're still actively working on expanding it. Expect a bigger push coming out of a batch of projects in the next few weeks. This feature here is a bit on hold unfortunately, since we overambitiously refactored and noticed a few hick-ups ;)

Anyways, nice to hear from you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants