-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: develop
Are you sure you want to change the base?
Animatable Size #86
Conversation
👀 |
👋 |
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! |
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 byBaseView::update()
whenever the content (e.g. background color, alpha, or size) was changed since the lastupdate()
. This method already existed, but wasn't used byBaseView
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 forci::Anim<T>
so you can dogetSize() * 0.5f
orviewA->getSize() + viewB->getSize()
instead of callinggetSize().value()
orgetSize()()
all the time.Since it's templated, this will work for any
ci::Anim<T>
(e.g.view->getPosition() + vec2(100)
orview->setAlpha(view->getAlpha() * 0.5f)
.This seems to work pretty well except for
+=
and type conversion (e.g. addingivec2
withAnim<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
andy
from size will still require you to callgetSize().value().x
or keep usinggetWidth()
.Performance
Warning: Changing the size on
TextView
andFboView
is pretty expensive, becauseTextView
needs to recalculate its layout, render everything to a surface and a texture andFboView
needs to create a new texture whenever their sizes change.Todos
Implements #32 and #59