Skip to content

Commit

Permalink
Revert checks when using percent margin
Browse files Browse the repository at this point in the history
Reverts the fix for percent margins crashing in certain cases.

Diffs=
50d49d051e Revert checks when using percent margin (#9036)

Co-authored-by: Philip Chung <[email protected]>
  • Loading branch information
philter and philter committed Feb 14, 2025
1 parent 84d5d06 commit 2e1edc3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
71d26ec7bea204c79c2e590ae2db5c61d3aa0794
50d49d051e99672c6a1dfe4b844460ad4cfde794
2 changes: 0 additions & 2 deletions include/rive/layout_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ class LayoutComponent : public LayoutComponentBase,
void scaleTypeChanged();
void displayChanged();
void flexDirectionChanged();
bool willComputeValidWidth();
bool willComputeValidHeight();
#endif
void buildDependencies() override;

Expand Down
78 changes: 5 additions & 73 deletions src/layout_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,57 +252,6 @@ StatusCode LayoutComponent::onAddedClean(CoreContext* context)
return StatusCode::Ok;
}

bool LayoutComponent::willComputeValidWidth()
{
auto p = parent();
while (p != nullptr)
{
if (p->is<LayoutComponent>() && !p->is<Artboard>())
{
auto layout = p->as<LayoutComponent>();
if (layout->style() != nullptr)
{
if (layout->style()->widthScaleType() == LayoutScaleType::fixed)
{
return true;
}
if (layout->style()->positionType() == YGPositionTypeAbsolute)
{
break;
}
}
}
p = p->parent();
}
return false;
}

bool LayoutComponent::willComputeValidHeight()
{
auto p = parent();
while (p != nullptr)
{
if (p->is<LayoutComponent>() && !p->is<Artboard>())
{
auto layout = p->as<LayoutComponent>();
if (layout->style() != nullptr)
{
if (layout->style()->heightScaleType() ==
LayoutScaleType::fixed)
{
return true;
}
if (layout->style()->positionType() == YGPositionTypeAbsolute)
{
break;
}
}
}
p = p->parent();
}
return false;
}

void LayoutComponent::drawProxy(Renderer* renderer)
{
if (clip())
Expand Down Expand Up @@ -756,31 +705,14 @@ void LayoutComponent::syncStyle()
ygStyle.border()[YGEdgeBottom] =
YGValue{m_style->borderBottom(), m_style->borderBottomUnits()};

auto hasValidWidth = willComputeValidWidth();
auto hasValidHeight = willComputeValidHeight();
auto marginLeftUnits =
!hasValidWidth && m_style->marginLeftUnits() == YGUnitPercent
? YGUnitAuto
: m_style->marginLeftUnits();
auto marginRightUnits =
!hasValidWidth && m_style->marginRightUnits() == YGUnitPercent
? YGUnitAuto
: m_style->marginRightUnits();
auto marginTopUnits =
!hasValidHeight && m_style->marginTopUnits() == YGUnitPercent
? YGUnitAuto
: m_style->marginTopUnits();
auto marginBottomUnits =
!hasValidHeight && m_style->marginBottomUnits() == YGUnitPercent
? YGUnitAuto
: m_style->marginBottomUnits();
ygStyle.margin()[YGEdgeLeft] =
YGValue{m_style->marginLeft(), marginLeftUnits};
YGValue{m_style->marginLeft(), m_style->marginLeftUnits()};
ygStyle.margin()[YGEdgeRight] =
YGValue{m_style->marginRight(), marginRightUnits};
ygStyle.margin()[YGEdgeTop] = YGValue{m_style->marginTop(), marginTopUnits};
YGValue{m_style->marginRight(), m_style->marginRightUnits()};
ygStyle.margin()[YGEdgeTop] =
YGValue{m_style->marginTop(), m_style->marginTopUnits()};
ygStyle.margin()[YGEdgeBottom] =
YGValue{m_style->marginBottom(), marginBottomUnits};
YGValue{m_style->marginBottom(), m_style->marginBottomUnits()};
ygStyle.padding()[YGEdgeLeft] =
YGValue{m_style->paddingLeft(), m_style->paddingLeftUnits()};
ygStyle.padding()[YGEdgeRight] =
Expand Down

0 comments on commit 2e1edc3

Please sign in to comment.