Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
WidgetComponent, aPositionComponentthat hosts a Flutter widget inside the Flame component tree.The widget becomes a real part of the Flutter element tree under the
GameWidget, so it is laid out, painted, hit tested and focused like any other widget: buttons respond to taps, text fields receive keyboard input, and inherited widgets such asTheme,MediaQueryandDirectionalityare available to it. At the same time it is rendered in the middle of the Flame render pass, so it respects the componentpriority, the camera transform and the position, angle, scale and anchor of the component and all of its ancestors. This is different from overlays, which sit in aStackabove the whole game and are not affected by the camera or component transforms.When
sizeis given the widget gets tight constraints of that size. When it is omitted the component adopts the widget's size, laying it out with the optionalconstraintsor, by default, loose constraints bounded by the game canvas in the component's local units.How it works
RenderGameWidgetis now aMultiChildRenderObjectWidgetandGameRenderBoxmixes inContainerRenderObjectMixin. Each mountedWidgetComponentregisters itself on theGame, and theGameWidgetbuilds the hosted widgets as children of the game render box, each in a smallWidgetComponentHostthat links the child to its component, rebuilds only the hosted subtree whenwidgetis reassigned, and excludes the subtree from focus and semantics while the component is not being rendered (for example under a hidden ancestor).GameRenderBox.performLayoutlays the children out with the constraints derived from their component, andWidgetComponent.renderasks the render box to paint its child at the current canvas transform.RepaintBoundary) is painted through aTransformLayer, which requires ending the picture that is being recorded. The newProxyCanvasmakes this transparent to the rest of the component tree: it forwards every call to the current underlying canvas and, when the game's picture is split, replays the save stack, transforms and clips onto the new canvas so that pendingrestorecalls keep balancing. Games without widget components keep using the plain canvas, so there is no overhead for them.BoxHitTestResult.addWithPaintTransform, andapplyPaintTransformreports the same transforms so thatlocalToGloballookups made by Flutter (text input, tooltips, finders) are correct. Rectangular Flame clips, such as the camera viewport, are applied to composited widgets and to hit testing.Limitations
GameWidgetrender pass. It is not included when the component tree is rendered into aPictureorImageelsewhere, such as by theSnapshotmixin,PostProcesses or the devtools component snapshot.OpacityEffectdo not affect it. Transforms and rectangular clips do.saveLayeran ancestor component has active at that point is closed and reopened around the widget.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?