Skip to content

Commit

Permalink
Fix for bug in Runtime LayoutComponent proxy
Browse files Browse the repository at this point in the history
This bug caused layout proxies to be drawn out of order causing layout rendering issues in the runtimes.

Diffs=
85343a4e1 Fix for bug in Runtime LayoutComponent proxy (#7867)

Co-authored-by: Philip Chung <[email protected]>
  • Loading branch information
philter and philter committed Aug 17, 2024
1 parent 198caee commit 43d7f27
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
93cc33b45086e528b22d1245a8f7855bac299a21
85343a4e1c287922f872d14172167af72b4c3358
3 changes: 3 additions & 0 deletions include/rive/drawable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace rive
class ClippingShape;
class Artboard;
class DrawRules;
class LayoutComponent;

class Drawable : public DrawableBase
{
Expand Down Expand Up @@ -47,6 +48,8 @@ class Drawable : public DrawableBase
DrawableFlag::Opaque;
}

bool isChildOfLayout(LayoutComponent* layout);

StatusCode onAddedDirty(CoreContext* context) override;
};

Expand Down
25 changes: 12 additions & 13 deletions src/artboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,12 @@ StatusCode Artboard::initialize()
for (int i = 0; i < m_Drawables.size(); i++)
{
auto drawable = m_Drawables[i];
LayoutComponent* currentLayout;
LayoutComponent* currentLayout = nullptr;
bool isInCurrentLayout = true;
if (!layouts.empty())
{
currentLayout = layouts.back();
isInCurrentLayout = false;
}
for (ContainerComponent* parent = drawable; parent != nullptr; parent = parent->parent())
{
if (parent == currentLayout)
{
isInCurrentLayout = true;
break;
}
isInCurrentLayout = drawable->isChildOfLayout(currentLayout);
}
// We inject a DrawableProxy after all of the children of a LayoutComponent
// so that we can draw a stroke above and background below the children
Expand All @@ -269,9 +261,16 @@ StatusCode Artboard::initialize()
{
// This is the first item in the list of drawables that isn't a child
// of the layout, so we insert a proxy before it
m_Drawables.insert(m_Drawables.begin() + i, currentLayout->proxy());
layouts.pop_back();
i += 1;
do
{
m_Drawables.insert(m_Drawables.begin() + i, currentLayout->proxy());
layouts.pop_back();
if (!layouts.empty())
{
currentLayout = layouts.back();
}
i += 1;
} while (!layouts.empty() && !drawable->isChildOfLayout(currentLayout));
}
if (drawable->is<LayoutComponent>())
{
Expand Down
13 changes: 13 additions & 0 deletions src/drawable.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "rive/drawable.hpp"
#include "rive/artboard.hpp"
#include "rive/layout_component.hpp"
#include "rive/shapes/clipping_shape.hpp"
#include "rive/shapes/path_composer.hpp"
#include "rive/shapes/shape.hpp"
Expand Down Expand Up @@ -70,4 +71,16 @@ ClipResult Drawable::applyClip(Renderer* renderer) const
}
}
return ClipResult::clip;
}

bool Drawable::isChildOfLayout(LayoutComponent* layout)
{
for (ContainerComponent* parent = this; parent != nullptr; parent = parent->parent())
{
if (parent->is<LayoutComponent>() && parent->as<LayoutComponent>() == layout)
{
return true;
}
}
return false;
}

0 comments on commit 43d7f27

Please sign in to comment.