Fixes issue with nested artboard opacity not updating in sync with the artboard.

This commit is contained in:
Luigi Rosso
2021-10-26 17:39:36 -07:00
committed by Luigi Rosso
parent 75ccbd0a0b
commit 61b5a1b363
5 changed files with 24 additions and 14 deletions

View File

@ -92,7 +92,6 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
bool get hasAnimations => _animations.isNotEmpty;
int _dirtDepth = 0;
int _dirt = 255;
/// Iterate each component and call callback for it.
void forEachComponent(void Function(Component) callback) =>
@ -120,17 +119,17 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
bool updateComponents() {
bool didUpdate = false;
if ((_dirt & ComponentDirt.drawOrder) != 0) {
if ((dirt & ComponentDirt.drawOrder) != 0) {
sortDrawOrder();
_dirt &= ~ComponentDirt.drawOrder;
dirt &= ~ComponentDirt.drawOrder;
didUpdate = true;
}
if ((_dirt & ComponentDirt.components) != 0) {
if ((dirt & ComponentDirt.components) != 0) {
const int maxSteps = 100;
int step = 0;
int count = _dependencyOrder.length;
while ((_dirt & ComponentDirt.components) != 0 && step < maxSteps) {
_dirt &= ~ComponentDirt.components;
while ((dirt & ComponentDirt.components) != 0 && step < maxSteps) {
dirt &= ~ComponentDirt.components;
// Track dirt depth here so that if something else marks
// dirty, we restart.
for (int i = 0; i < count; i++) {
@ -164,6 +163,9 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
didUpdate = true;
}
}
if (updateComponents() || didUpdate) {
didUpdate = true;
}
if (nested) {
var active = _activeNestedArtboards.toList(growable: false);
@ -172,10 +174,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
}
}
if (updateComponents() || didUpdate) {
return true;
}
return false;
return didUpdate;
}
@override
@ -187,7 +186,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
void onComponentDirty(Component component) {
if ((dirt & ComponentDirt.components) == 0) {
context.markNeedsAdvance();
_dirt |= ComponentDirt.components;
dirt |= ComponentDirt.components;
}
/// If the order of the component is less than the current dirt depth,
@ -218,7 +217,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
// component.dirt = 255;
}
_dirt |= ComponentDirt.components;
dirt |= ComponentDirt.components;
}
@override
@ -228,6 +227,13 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
Rect.fromLTWH(width * -originX, height * -originY, width, height);
path.reset();
path.addRect(rect);
for (final fill in fills) {
fill.renderOpacity = opacity;
}
for (final stroke in strokes) {
stroke.renderOpacity = opacity;
}
}
}
@ -278,7 +284,7 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
void markDrawOrderDirty() {
if ((dirt & ComponentDirt.drawOrder) == 0) {
context.markNeedsAdvance();
_dirt |= ComponentDirt.drawOrder;
dirt |= ComponentDirt.drawOrder;
}
}

View File

@ -33,4 +33,5 @@ abstract class TargetedConstraint extends TargetedConstraintBase {
super.onAddedDirty();
target = context.resolve(targetId);
}
}

View File

@ -12,6 +12,7 @@ abstract class NestedAnimation<T extends Animation>
@override
void animationIdChanged(int from, int to) {}
bool get isEnabled;
void advance(double elapsedSeconds, MountedArtboard mountedArtboard);

View File

@ -39,12 +39,14 @@ class NestedArtboard extends NestedArtboardBase {
_mountedArtboard = value;
_mountedArtboard?.worldTransform = worldTransform;
_mountedArtboard?.renderOpacity = renderOpacity;
_mountedArtboard?.advance(0);
addDirt(ComponentDirt.paint);
}
@override
void artboardIdChanged(int from, int to) {}
@override
void childAdded(Component child) {
super.childAdded(child);

View File

@ -34,7 +34,7 @@ abstract class TransformComponent extends TransformComponentBase {
final List<Constraint> _constraints = [];
Iterable<Constraint> get constraints => _constraints;
double _renderOpacity = 0;
double _renderOpacity = 1;
double get renderOpacity => _renderOpacity;
final Mat2D transform = Mat2D();