mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 21:21:17 +01:00
don't expose yoga includes
This makes sure that the yoga includes are only included in internal headers. Eventually we should move private headers to the "internal" folder, for now I'm just defining a helper header to include in internal only headers which will assert if it's incorrectly included by a runtime/higher level public implementation. Diffs= 071b19ba62 don't expose yoga includes (#8526) Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com> Co-authored-by: blakdragan7 <jcopela4@gmail.com>
This commit is contained in:
@@ -1 +1 @@
|
||||
ad1ca22bd5911398018c9a6883e4cba7a1b07c53
|
||||
071b19ba62ea97db039f71dcab264d4934161db4
|
||||
|
||||
@@ -50,7 +50,7 @@ do
|
||||
yoga,
|
||||
})
|
||||
|
||||
defines({ 'YOGA_EXPORT=' })
|
||||
defines({ 'YOGA_EXPORT=', '_RIVE_INTERNAL_' })
|
||||
|
||||
files({ '../src/**.cpp' })
|
||||
|
||||
|
||||
3
include/rive/internal/assert_internal_only.hpp
Normal file
3
include/rive/internal/assert_internal_only.hpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#ifndef _RIVE_INTERNAL_
|
||||
static_assert(false, "This file should never be included by public headers.");
|
||||
#endif
|
||||
@@ -1,49 +1,14 @@
|
||||
#ifndef _RIVE_LAYOUT_COMPONENT_STYLE_HPP_
|
||||
#define _RIVE_LAYOUT_COMPONENT_STYLE_HPP_
|
||||
#include "rive/generated/layout/layout_component_style_base.hpp"
|
||||
#include "rive/layout/layout_enums.hpp"
|
||||
#include "rive/internal/assert_internal_only.hpp"
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
#include "yoga/Yoga.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
namespace rive
|
||||
{
|
||||
enum class LayoutAnimationStyle : uint8_t
|
||||
{
|
||||
none,
|
||||
inherit,
|
||||
custom
|
||||
};
|
||||
|
||||
enum class LayoutStyleInterpolation : uint8_t
|
||||
{
|
||||
hold,
|
||||
linear,
|
||||
cubic,
|
||||
elastic
|
||||
};
|
||||
|
||||
enum class LayoutAlignmentType : uint8_t
|
||||
{
|
||||
topLeft,
|
||||
topCenter,
|
||||
topRight,
|
||||
centerLeft,
|
||||
center,
|
||||
centerRight,
|
||||
bottomLeft,
|
||||
bottomCenter,
|
||||
bottomRight,
|
||||
spaceBetweenStart,
|
||||
spaceBetweenCenter,
|
||||
spaceBetweenEnd
|
||||
};
|
||||
|
||||
enum class LayoutScaleType : uint8_t
|
||||
{
|
||||
fixed,
|
||||
fill,
|
||||
hug
|
||||
};
|
||||
|
||||
class KeyFrameInterpolator;
|
||||
class LayoutComponentStyle : public LayoutComponentStyleBase
|
||||
|
||||
21
include/rive/layout/layout_data.hpp
Normal file
21
include/rive/layout/layout_data.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef _RIVE_LAYOUT_DATA_HPP_
|
||||
#define _RIVE_LAYOUT_DATA_HPP_
|
||||
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
#include "yoga/YGNode.h"
|
||||
#include "yoga/YGStyle.h"
|
||||
#include "yoga/Yoga.h"
|
||||
#endif
|
||||
|
||||
namespace rive
|
||||
{
|
||||
struct LayoutData
|
||||
{
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
YGNode node;
|
||||
YGStyle style;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace rive
|
||||
#endif
|
||||
46
include/rive/layout/layout_enums.hpp
Normal file
46
include/rive/layout/layout_enums.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef _RIVE_LAYOUT_ENUMS_HPP_
|
||||
#define _RIVE_LAYOUT_ENUMS_HPP_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace rive
|
||||
{
|
||||
enum class LayoutAnimationStyle : uint8_t
|
||||
{
|
||||
none,
|
||||
inherit,
|
||||
custom
|
||||
};
|
||||
|
||||
enum class LayoutStyleInterpolation : uint8_t
|
||||
{
|
||||
hold,
|
||||
linear,
|
||||
cubic,
|
||||
elastic
|
||||
};
|
||||
|
||||
enum class LayoutAlignmentType : uint8_t
|
||||
{
|
||||
topLeft,
|
||||
topCenter,
|
||||
topRight,
|
||||
centerLeft,
|
||||
center,
|
||||
centerRight,
|
||||
bottomLeft,
|
||||
bottomCenter,
|
||||
bottomRight,
|
||||
spaceBetweenStart,
|
||||
spaceBetweenCenter,
|
||||
spaceBetweenEnd
|
||||
};
|
||||
|
||||
enum class LayoutScaleType : uint8_t
|
||||
{
|
||||
fixed,
|
||||
fill,
|
||||
hug
|
||||
};
|
||||
} // namespace rive
|
||||
#endif
|
||||
@@ -4,32 +4,19 @@
|
||||
#include "rive/animation/keyframe_interpolator.hpp"
|
||||
#include "rive/drawable.hpp"
|
||||
#include "rive/generated/layout_component_base.hpp"
|
||||
#include "rive/layout/layout_component_style.hpp"
|
||||
#include "rive/layout/layout_measure_mode.hpp"
|
||||
#include "rive/math/raw_path.hpp"
|
||||
#include "rive/shapes/rectangle.hpp"
|
||||
#include "rive/shapes/shape_paint_container.hpp"
|
||||
#include "rive/advancing_component.hpp"
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
#include "yoga/YGNode.h"
|
||||
#include "yoga/YGStyle.h"
|
||||
#include "yoga/Yoga.h"
|
||||
#endif
|
||||
#include "rive/layout/layout_enums.hpp"
|
||||
|
||||
namespace rive
|
||||
{
|
||||
|
||||
class AABB;
|
||||
class KeyFrameInterpolator;
|
||||
|
||||
struct LayoutData
|
||||
{
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
YGNode node;
|
||||
YGStyle style;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct LayoutData;
|
||||
class LayoutComponentStyle;
|
||||
class Layout
|
||||
{
|
||||
public:
|
||||
@@ -37,9 +24,6 @@ public:
|
||||
Layout(float left, float top, float width, float height) :
|
||||
m_left(left), m_top(top), m_width(width), m_height(height)
|
||||
{}
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
Layout(const YGLayout& layout);
|
||||
#endif
|
||||
|
||||
bool operator==(const Layout& o) const
|
||||
{
|
||||
@@ -86,7 +70,7 @@ class LayoutComponent : public LayoutComponentBase,
|
||||
{
|
||||
protected:
|
||||
LayoutComponentStyle* m_style = nullptr;
|
||||
std::unique_ptr<LayoutData> m_layoutData;
|
||||
LayoutData* m_layoutData;
|
||||
|
||||
Layout m_layout;
|
||||
|
||||
@@ -97,7 +81,7 @@ protected:
|
||||
LayoutStyleInterpolation m_inheritedInterpolation =
|
||||
LayoutStyleInterpolation::hold;
|
||||
float m_inheritedInterpolationTime = 0;
|
||||
Rectangle* m_backgroundRect = new Rectangle();
|
||||
Rectangle m_backgroundRect;
|
||||
rcp<RenderPath> m_backgroundPath;
|
||||
rcp<RenderPath> m_clipPath;
|
||||
DrawableProxy m_proxy;
|
||||
@@ -130,8 +114,6 @@ private:
|
||||
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
protected:
|
||||
YGNode& layoutNode() { return m_layoutData->node; }
|
||||
YGStyle& layoutStyle() { return m_layoutData->style; }
|
||||
void syncLayoutChildren();
|
||||
void propagateSizeToChildren(ContainerComponent* component);
|
||||
bool applyInterpolation(float elapsedSeconds, bool animate = true);
|
||||
@@ -184,20 +166,16 @@ public:
|
||||
bool overridesKeyedInterpolation(int propertyKey) override;
|
||||
Drawable* hittableComponent() override { return nullptr; }
|
||||
bool hasShapePaints() const { return m_ShapePaints.size() > 0; }
|
||||
Rectangle* backgroundRect() const { return m_backgroundRect; }
|
||||
const Rectangle* backgroundRect() const { return &m_backgroundRect; }
|
||||
RenderPath* backgroundPath() const { return m_backgroundPath.get(); }
|
||||
bool advanceComponent(float elapsedSeconds,
|
||||
AdvanceFlags flags = AdvanceFlags::Animate |
|
||||
AdvanceFlags::NewFrame) override;
|
||||
|
||||
LayoutComponent();
|
||||
~LayoutComponent();
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
LayoutComponent() :
|
||||
m_layoutData(std::unique_ptr<LayoutData>(new LayoutData())),
|
||||
m_proxy(this)
|
||||
{
|
||||
layoutNode().getConfig()->setPointScaleFactor(0);
|
||||
}
|
||||
~LayoutComponent() { delete m_backgroundRect; }
|
||||
|
||||
void syncStyle();
|
||||
virtual void propagateSize();
|
||||
void updateLayoutBounds(bool animate = true);
|
||||
@@ -222,11 +200,6 @@ public:
|
||||
bool isLeaf();
|
||||
void positionTypeChanged();
|
||||
void scaleTypeChanged();
|
||||
#else
|
||||
LayoutComponent() :
|
||||
m_layoutData(std::unique_ptr<LayoutData>(new LayoutData())),
|
||||
m_proxy(this)
|
||||
{}
|
||||
#endif
|
||||
void buildDependencies() override;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ do
|
||||
end
|
||||
filter({})
|
||||
|
||||
defines({ 'YOGA_EXPORT=' })
|
||||
defines({ 'YOGA_EXPORT=', '_RIVE_INTERNAL_' })
|
||||
|
||||
files({ 'src/**.cpp' })
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "rive/text/text_value_run.hpp"
|
||||
#include "rive/event.hpp"
|
||||
#include "rive/assets/audio_asset.hpp"
|
||||
#include "rive/layout/layout_data.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -770,7 +771,7 @@ void* Artboard::takeLayoutNode()
|
||||
{
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
m_updatesOwnLayout = false;
|
||||
return static_cast<void*>(&layoutNode());
|
||||
return static_cast<void*>(&m_layoutData->node);
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "rive/shapes/paint/stroke.hpp"
|
||||
#include "rive/shapes/rectangle.hpp"
|
||||
#include "rive/nested_artboard_layout.hpp"
|
||||
#include "rive/layout/layout_data.hpp"
|
||||
#include "rive/layout/layout_component_style.hpp"
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
#include "rive/transform_component.hpp"
|
||||
#include "yoga/YGEnums.h"
|
||||
@@ -131,6 +133,13 @@ bool LayoutComponent::overridesKeyedInterpolation(int propertyKey)
|
||||
}
|
||||
|
||||
#ifdef WITH_RIVE_LAYOUT
|
||||
|
||||
LayoutComponent::LayoutComponent() :
|
||||
m_layoutData(new LayoutData()), m_proxy(this)
|
||||
{
|
||||
m_layoutData->node.getConfig()->setPointScaleFactor(0);
|
||||
}
|
||||
|
||||
StatusCode LayoutComponent::onAddedDirty(CoreContext* context)
|
||||
{
|
||||
auto code = Super::onAddedDirty(context);
|
||||
@@ -161,8 +170,8 @@ StatusCode LayoutComponent::onAddedClean(CoreContext* context)
|
||||
markLayoutStyleDirty();
|
||||
m_backgroundPath = artboard()->factory()->makeEmptyRenderPath();
|
||||
m_clipPath = artboard()->factory()->makeEmptyRenderPath();
|
||||
m_backgroundRect->originX(0);
|
||||
m_backgroundRect->originY(0);
|
||||
m_backgroundRect.originX(0);
|
||||
m_backgroundRect.originY(0);
|
||||
syncLayoutChildren();
|
||||
return StatusCode::Ok;
|
||||
}
|
||||
@@ -186,13 +195,13 @@ void LayoutComponent::drawProxy(Renderer* renderer)
|
||||
{
|
||||
shapePaint->draw(renderer,
|
||||
m_backgroundPath.get(),
|
||||
&m_backgroundRect->rawPath());
|
||||
&m_backgroundRect.rawPath());
|
||||
}
|
||||
if (shapePaint->is<Fill>())
|
||||
{
|
||||
shapePaint->draw(renderer,
|
||||
m_backgroundPath.get(),
|
||||
&m_backgroundRect->rawPath());
|
||||
&m_backgroundRect.rawPath());
|
||||
}
|
||||
}
|
||||
renderer->restore();
|
||||
@@ -209,23 +218,23 @@ void LayoutComponent::draw(Renderer* renderer)
|
||||
|
||||
void LayoutComponent::updateRenderPath()
|
||||
{
|
||||
m_backgroundRect->width(m_layout.width());
|
||||
m_backgroundRect->height(m_layout.height());
|
||||
m_backgroundRect.width(m_layout.width());
|
||||
m_backgroundRect.height(m_layout.height());
|
||||
if (style() != nullptr)
|
||||
{
|
||||
m_backgroundRect->linkCornerRadius(style()->linkCornerRadius());
|
||||
m_backgroundRect->cornerRadiusTL(style()->cornerRadiusTL());
|
||||
m_backgroundRect->cornerRadiusTR(style()->cornerRadiusTR());
|
||||
m_backgroundRect->cornerRadiusBL(style()->cornerRadiusBL());
|
||||
m_backgroundRect->cornerRadiusBR(style()->cornerRadiusBR());
|
||||
m_backgroundRect.linkCornerRadius(style()->linkCornerRadius());
|
||||
m_backgroundRect.cornerRadiusTL(style()->cornerRadiusTL());
|
||||
m_backgroundRect.cornerRadiusTR(style()->cornerRadiusTR());
|
||||
m_backgroundRect.cornerRadiusBL(style()->cornerRadiusBL());
|
||||
m_backgroundRect.cornerRadiusBR(style()->cornerRadiusBR());
|
||||
}
|
||||
m_backgroundRect->update(ComponentDirt::Path);
|
||||
m_backgroundRect.update(ComponentDirt::Path);
|
||||
|
||||
m_backgroundPath->rewind();
|
||||
m_backgroundRect->rawPath().addTo(m_backgroundPath.get());
|
||||
m_backgroundRect.rawPath().addTo(m_backgroundPath.get());
|
||||
|
||||
RawPath clipPath;
|
||||
clipPath.addPath(m_backgroundRect->rawPath(), &m_WorldTransform);
|
||||
clipPath.addPath(m_backgroundRect.rawPath(), &m_WorldTransform);
|
||||
m_clipPath =
|
||||
artboard()->factory()->makeRenderPath(clipPath, FillRule::nonZero);
|
||||
for (auto shapePaint : m_ShapePaints)
|
||||
@@ -320,8 +329,8 @@ void LayoutComponent::syncStyle()
|
||||
{
|
||||
return;
|
||||
}
|
||||
YGNode& ygNode = layoutNode();
|
||||
YGStyle& ygStyle = layoutStyle();
|
||||
YGNode& ygNode = m_layoutData->node;
|
||||
YGStyle& ygStyle = m_layoutData->style;
|
||||
if (m_style->intrinsicallySized() && isLeaf())
|
||||
{
|
||||
ygNode.setContext(this);
|
||||
@@ -644,7 +653,7 @@ void LayoutComponent::syncStyle()
|
||||
|
||||
void LayoutComponent::syncLayoutChildren()
|
||||
{
|
||||
YGNode& ourNode = layoutNode();
|
||||
YGNode& ourNode = m_layoutData->node;
|
||||
YGNodeRemoveAllChildren(&ourNode);
|
||||
int index = 0;
|
||||
for (auto child : children())
|
||||
@@ -653,7 +662,7 @@ void LayoutComponent::syncLayoutChildren()
|
||||
switch (child->coreType())
|
||||
{
|
||||
case LayoutComponentBase::typeKey:
|
||||
node = &child->as<LayoutComponent>()->layoutNode();
|
||||
node = &child->as<LayoutComponent>()->m_layoutData->node;
|
||||
break;
|
||||
case NestedArtboardLayoutBase::typeKey:
|
||||
node = static_cast<YGNode*>(
|
||||
@@ -702,7 +711,7 @@ void LayoutComponent::propagateSizeToChildren(ContainerComponent* component)
|
||||
|
||||
void LayoutComponent::calculateLayout()
|
||||
{
|
||||
YGNodeCalculateLayout(&layoutNode(),
|
||||
YGNodeCalculateLayout(&m_layoutData->node,
|
||||
width(),
|
||||
height(),
|
||||
YGDirection::YGDirectionInherit);
|
||||
@@ -719,16 +728,17 @@ void LayoutComponent::onDirty(ComponentDirt value)
|
||||
}
|
||||
}
|
||||
|
||||
Layout::Layout(const YGLayout& layout) :
|
||||
m_left(layout.position[YGEdgeLeft]),
|
||||
m_top(layout.position[YGEdgeTop]),
|
||||
m_width(layout.dimensions[YGDimensionWidth]),
|
||||
m_height(layout.dimensions[YGDimensionHeight])
|
||||
{}
|
||||
static Layout layoutFromYoga(const YGLayout& layout)
|
||||
{
|
||||
return Layout(layout.position[YGEdgeLeft],
|
||||
layout.position[YGEdgeTop],
|
||||
layout.dimensions[YGDimensionWidth],
|
||||
layout.dimensions[YGDimensionHeight]);
|
||||
}
|
||||
|
||||
void LayoutComponent::updateLayoutBounds(bool animate)
|
||||
{
|
||||
YGNode& node = layoutNode();
|
||||
YGNode& node = m_layoutData->node;
|
||||
bool updated = node.getHasNewLayout();
|
||||
if (!updated)
|
||||
{
|
||||
@@ -748,7 +758,7 @@ void LayoutComponent::updateLayoutBounds(bool animate)
|
||||
}
|
||||
}
|
||||
|
||||
Layout newLayout(node.getLayout());
|
||||
Layout newLayout = layoutFromYoga(node.getLayout());
|
||||
|
||||
if (animate && animates())
|
||||
{
|
||||
@@ -1036,7 +1046,7 @@ void LayoutComponent::interruptAnimation()
|
||||
|
||||
void LayoutComponent::markLayoutNodeDirty()
|
||||
{
|
||||
layoutNode().markDirtyAndPropagate();
|
||||
m_layoutData->node.markDirtyAndPropagate();
|
||||
artboard()->markLayoutDirty(this);
|
||||
}
|
||||
|
||||
@@ -1099,6 +1109,10 @@ void LayoutComponent::scaleTypeChanged()
|
||||
markLayoutNodeDirty();
|
||||
}
|
||||
#else
|
||||
LayoutComponent::LayoutComponent() :
|
||||
m_layoutData(new LayoutData()), m_proxy(this)
|
||||
{}
|
||||
|
||||
void LayoutComponent::drawProxy(Renderer* renderer) {}
|
||||
|
||||
void LayoutComponent::draw(Renderer* renderer) {}
|
||||
@@ -1126,6 +1140,8 @@ bool LayoutComponent::mainAxisIsRow() { return true; }
|
||||
bool LayoutComponent::mainAxisIsColumn() { return false; }
|
||||
#endif
|
||||
|
||||
LayoutComponent::~LayoutComponent() { delete m_layoutData; }
|
||||
|
||||
void LayoutComponent::clipChanged() { markLayoutNodeDirty(); }
|
||||
void LayoutComponent::widthChanged() { markLayoutNodeDirty(); }
|
||||
void LayoutComponent::heightChanged() { markLayoutNodeDirty(); }
|
||||
|
||||
Reference in New Issue
Block a user