Skip to content

Commit

Permalink
Merging intrinsic_size_experiment changes
Browse files Browse the repository at this point in the history
Merging intrinsic artboard size option from #104 #112
  • Loading branch information
luigi-rosso committed Jul 6, 2019
1 parent 15682ac commit 52d5e6e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 21 deletions.
31 changes: 17 additions & 14 deletions flare_dart/lib/actor_shape.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import "dart:math";
import "actor_artboard.dart";
import "actor_color.dart";
import "actor_component.dart";
import "actor_node.dart";
import "actor_drawable.dart";
import "actor_artboard.dart";
import "stream_reader.dart";
import "actor_node.dart";
import "actor_path.dart";
import "dart:math";
import "math/aabb.dart";
import "math/mat2d.dart";
import "math/vec2d.dart";
import "math/aabb.dart";
import "stream_reader.dart";

class ActorShape extends ActorDrawable {
List<ActorStroke> _strokes = List<ActorStroke>();
List<ActorFill> _fills = List<ActorFill>();
final List<ActorStroke> _strokes = <ActorStroke>[];
final List<ActorFill> _fills = <ActorFill>[];

ActorFill get fill => _fills.length > 0 ? _fills.first : null;
ActorStroke get stroke => _strokes.length > 0 ? _strokes.first : null;
ActorFill get fill => _fills.isNotEmpty ? _fills.first : null;
ActorStroke get stroke => _strokes.isNotEmpty ? _strokes.first : null;
List<ActorFill> get fills => _fills;
List<ActorStroke> get strokes => _strokes;

@override
void update(int dirt) {
super.update(dirt);
invalidateShape();
Expand Down Expand Up @@ -73,12 +74,13 @@ class ActorShape extends ActorDrawable {
return aabb;
}

for (ActorNode node in children) {
for (final ActorNode node in children) {
ActorBasePath path = node as ActorBasePath;
if (path == null) {
continue;
}
// This is the axis aligned bounding box in the space of the parent (this case our shape).
// This is the axis aligned bounding box in the space of the
// parent (this case our shape).
AABB pathAABB = path.getPathAABB();

if (aabb == null) {
Expand All @@ -105,7 +107,7 @@ class ActorShape extends ActorDrawable {

if (_strokes != null) {
double maxStroke = 0.0;
for (ActorStroke stroke in _strokes) {
for (final ActorStroke stroke in _strokes) {
if (stroke.width > maxStroke) {
maxStroke = stroke.width;
}
Expand Down Expand Up @@ -151,11 +153,12 @@ class ActorShape extends ActorDrawable {
_fills.add(fill);
}

@override
void initializeGraphics() {
for (ActorStroke stroke in _strokes) {
for (final ActorStroke stroke in _strokes) {
stroke.initializeGraphics();
}
for (ActorFill fill in _fills) {
for (final ActorFill fill in _fills) {
fill.initializeGraphics();
}
}
Expand Down
15 changes: 10 additions & 5 deletions flare_flutter/lib/flare_actor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class FlareActor extends LeafRenderObjectWidget {
final FlareCompletedCallback callback;
final Color color;
final String boundsNode;
final bool sizeFromArtboard;

const FlareActor(this.filename,
{this.boundsNode,
Expand All @@ -34,7 +35,8 @@ class FlareActor extends LeafRenderObjectWidget {
this.controller,
this.callback,
this.color,
this.shouldClip = true});
this.shouldClip = true,
this.sizeFromArtboard = false});

@override
RenderObject createRenderObject(BuildContext context) {
Expand All @@ -50,7 +52,8 @@ class FlareActor extends LeafRenderObjectWidget {
..completed = callback
..color = color
..shouldClip = shouldClip
..boundsNodeName = boundsNode;
..boundsNodeName = boundsNode
..useIntrinsicSize = sizeFromArtboard;
}

@override
Expand All @@ -66,7 +69,8 @@ class FlareActor extends LeafRenderObjectWidget {
..isPaused = isPaused
..color = color
..shouldClip = shouldClip
..boundsNodeName = boundsNode;
..boundsNodeName = boundsNode
..useIntrinsicSize = sizeFromArtboard;
}

@override
Expand Down Expand Up @@ -204,8 +208,8 @@ class FlareActorRenderObject extends FlareRenderBox {
if (_filename == null) {
markNeedsPaint();
}
// file will change, let's clear out old animations.
_animationLayers.clear();
// file will change, let's clear out old animations.
_animationLayers.clear();
load();
}

Expand All @@ -223,6 +227,7 @@ class FlareActorRenderObject extends FlareRenderBox {
actor.artboard.makeInstance() as FlutterActorArtboard;
artboard.initializeGraphics();
_artboard = artboard;
intrinsicSize = Size(artboard.width, artboard.height);
_artboard.overrideColor = _color == null
? null
: Float32List.fromList([
Expand Down
35 changes: 33 additions & 2 deletions flare_flutter/lib/flare_render_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ abstract class FlareRenderBox extends RenderBox {
int _frameCallbackID;
double _lastFrameTime = 0.0;
final List<FlareCacheAsset> _assets = [];
bool _useIntrinsicSize = false;

bool get useIntrinsicSize => _useIntrinsicSize;
set useIntrinsicSize(bool value) {
if (_useIntrinsicSize == value) {
return;
}
_useIntrinsicSize = value;
if (parent != null) {
markNeedsLayoutForSizedByParentChange();
}
}

Size _intrinsicSize;
Size get intrinsicSize => _intrinsicSize;
set intrinsicSize(Size value) {
if (_intrinsicSize == value) {
return;
}
_intrinsicSize = value;
if (parent != null) {
markNeedsLayoutForSizedByParentChange();
}
}

AssetBundle get assetBundle => _assetBundle;
set assetBundle(AssetBundle value) {
Expand Down Expand Up @@ -59,15 +83,22 @@ abstract class FlareRenderBox extends RenderBox {
}
}

@override
bool get sizedByParent => !_useIntrinsicSize || _intrinsicSize == null;

@override
bool get sizedByParent => true;
void performLayout() {
if (!sizedByParent) {
size = constraints.constrain(_intrinsicSize);
}
}

@override
bool hitTestSelf(Offset screenOffset) => true;

@override
void performResize() {
size = constraints.biggest;
size = _useIntrinsicSize ? constraints.smallest : constraints.biggest;
}

@override
Expand Down

0 comments on commit 52d5e6e

Please sign in to comment.