Skip to content

Commit

Permalink
don't expose yoga includes
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: blakdragan7 <[email protected]>
  • Loading branch information
3 people committed Nov 9, 2024
1 parent a4cee7f commit d3e4bcf
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ad1ca22bd5911398018c9a6883e4cba7a1b07c53
071b19ba62ea97db039f71dcab264d4934161db4
2 changes: 1 addition & 1 deletion build/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ do
yoga,
})

defines({ 'YOGA_EXPORT=' })
defines({ 'YOGA_EXPORT=', '_RIVE_INTERNAL_' })

files({ '../src/**.cpp' })

Expand Down
3 changes: 3 additions & 0 deletions include/rive/internal/assert_internal_only.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifndef _RIVE_INTERNAL_
static_assert(false, "This file should never be included by public headers.");
#endif
39 changes: 2 additions & 37 deletions include/rive/layout/layout_component_style.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 21 additions & 0 deletions include/rive/layout/layout_data.hpp
Original file line number Diff line number Diff line change
@@ -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 changes: 46 additions & 0 deletions include/rive/layout/layout_enums.hpp
Original file line number Diff line number Diff line change
@@ -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
45 changes: 9 additions & 36 deletions include/rive/layout_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,26 @@
#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:
Layout() : m_left(0.0f), m_top(0.0f), m_width(0.0f), m_height(0.0f) {}
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
{
Expand Down Expand Up @@ -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;

Expand All @@ -97,7 +81,7 @@ class LayoutComponent : public LayoutComponentBase,
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;
Expand Down Expand Up @@ -130,8 +114,6 @@ class LayoutComponent : public LayoutComponentBase,

#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);
Expand Down Expand Up @@ -184,20 +166,16 @@ class LayoutComponent : public LayoutComponentBase,
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);
Expand All @@ -222,11 +200,6 @@ class LayoutComponent : public LayoutComponentBase,
bool isLeaf();
void positionTypeChanged();
void scaleTypeChanged();
#else
LayoutComponent() :
m_layoutData(std::unique_ptr<LayoutData>(new LayoutData())),
m_proxy(this)
{}
#endif
void buildDependencies() override;

Expand Down
2 changes: 1 addition & 1 deletion premake5_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ do
end
filter({})

defines({ 'YOGA_EXPORT=' })
defines({ 'YOGA_EXPORT=', '_RIVE_INTERNAL_' })

files({ 'src/**.cpp' })

Expand Down
3 changes: 2 additions & 1 deletion src/artboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit d3e4bcf

Please sign in to comment.