flame icon indicating copy to clipboard operation
flame copied to clipboard

fix: ViewportAwareBounds component and lifecycle issues

Open TheMaverickProgrammer opened this issue 1 year ago • 0 comments

Description

The behavior for CameraComponent.setBounds was not behaving correctly. The viewport-aware behavior was not triggering until a window resize event. All supported bound variants were not respecting the fixed resolution viewport, or in some cases, behaving unpredictably.

The issue was with the fact the viewport-aware behavior component depends on the bounded position component to be in its parent, but was returning null during onMount. The viewport math was using the logical size instead of the virtual size. I made some math changes to be accurate.

This PR adds new a getter CameraComponent.considerViewport. ViewportAwareBoundsBehavior is now added as a side effect of mounting BoundedPositionBehavior by listening for Viewfinder.onChildrenChanged events. This guarantees that Flames life cycle is respected and the components behave as expected.

Tests pass on my own local project.

Videos are linked on the discord thread here.

Melos dry run completed successfully.

Checklist

  • [x] I have followed the [Contributor Guide] when preparing my PR.
  • [ ] I have updated/added tests for ALL new/updated/fixed functionality.
  • [x] I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • [ ] I have updated/added relevant examples in examples or docs.

Breaking Change?

  • [ ] Yes, this PR is a breaking change.
  • [x] No, this PR is not a breaking change.

Migration instructions

No work to be done.

Related Issues

https://github.com/flame-engine/flame/pull/2769

QUESTIONS FOR THE DEVS

So I'm not satisfied with the fixes for Circle bounds. The bounds uses the maxima of the viewport, and yes, creates a circle that stays within the size of the bounds circle, but I'd expect that Circle bounds should keep my viewport inside the circle as it is documented to stay inside the desired bounds shape. Therefore, I think Circle case should have 4 incident points to fit the viewport. That is to say, the viewport is not the maxima of the newly calculated Circle, but will be fully contained by this new Circle. This way, you'll never see outside of the bounds as it, seems to me anyway, implies. However I do not know if this is intuitive for others and expected behavior. Thoughts?

TheMaverickProgrammer avatar Aug 21 '24 18:08 TheMaverickProgrammer