Skip to content

Commit

Permalink
editor: nine-slicing core data type definitions
Browse files Browse the repository at this point in the history
This PR adds the core data types to support n-slicing. There are three main types: Axis, NSlicer and NSlicerTileMode.
1. Axis: I didn't want to make this super specific, since it could be used for grids later. So rn, it just represents some position in some dimension, and can either be a value in terms of a positional unit (like 10px) or bounds percentage (like 10%).
2. NSlicer: It's as simple as a component gets, we'll just use it to be a parent of all the n-slicer Axes, and have it be a child of Image later.
3. NSlicerTileMode: The main data here is 'style'. We said to use patchX and patchY separately from patchIndex. The last one is persisted in file, while the other two are actually used at runtime.

The non-json files are auto generated, with the runtime json files copy pasted from the dev/defs version. I verified that the editor still runs, and the runtime also runs without error.

Next up, I'll use these definitions to change editor behavior.

Documentation: https://www.notion.so/rive-app/9-Slice-Tech-Proposal-Image-only-50b25ea8e79c4efabb681110e288f064#15f3a49ce3534baeafc31c37fb30cc0b

For a rough direction of how to implement nine-slicing, check out this research branch: https://github.com/rive-app/rive/compare/master...susan/nine-slice-research

Diffs=
ed56d2de6 editor: nine-slicing core data type definitions (#7840)

Co-authored-by: Susan Wang <susan@rive.app>
  • Loading branch information
susan101566 and susan101566 committed Aug 14, 2024
1 parent a7a0a01 commit f450f95
Show file tree
Hide file tree
Showing 21 changed files with 544 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4fb978a9230fc006b5e575364f062907e7dd2afe
ed56d2de61afb05abd99e8bab6775b63ab89f1a3
29 changes: 29 additions & 0 deletions dev/defs/layout/axis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "Axis",
"key": {
"int": 492,
"string": "axis"
},
"abstract": true,
"extends": "component.json",
"properties": {
"offset": {
"type": "double",
"initialValue": "0",
"animates": true,
"key": {
"int": 675,
"string": "offset"
}
},
"normalized": {
"type": "bool",
"initialValue": "false",
"key": {
"int": 676,
"string": "normalized"
},
"description": "true means offset indicates a percentage"
}
}
}
8 changes: 8 additions & 0 deletions dev/defs/layout/axis_x.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "AxisX",
"key": {
"int": 495,
"string": "axisx"
},
"extends": "layout/axis.json"
}
8 changes: 8 additions & 0 deletions dev/defs/layout/axis_y.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "AxisY",
"key": {
"int": 494,
"string": "axisy"
},
"extends": "layout/axis.json"
}
8 changes: 8 additions & 0 deletions dev/defs/layout/n_slicer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "NSlicer",
"key": {
"int": 493,
"string": "nslicer"
},
"extends": "component.json"
}
48 changes: 48 additions & 0 deletions dev/defs/layout/n_slicer_tile_mode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "NSlicerTileMode",
"key": {
"int": 491,
"string": "nslicertilemode"
},
"extends": "component.json",
"properties": {
"patchX": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 670,
"string": "patchx"
},
"description": "the x index of the patch to style",
"runtime": false
},
"patchY": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 671,
"string": "patchy"
},
"description": "the y index of the patch to style",
"runtime": false
},
"patchIndex": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 672,
"string": "patchindex"
},
"description": "the index of the patch to style, non-negative"
},
"style": {
"type": "uint",
"initialValue": "0",
"key": {
"int": 673,
"string": "style"
},
"description": "represents stretch, repeat, hidden, etc."
}
}
}
45 changes: 45 additions & 0 deletions include/rive/generated/core_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@
#include "rive/drawable.hpp"
#include "rive/event.hpp"
#include "rive/joystick.hpp"
#include "rive/layout/axis.hpp"
#include "rive/layout/axis_x.hpp"
#include "rive/layout/axis_y.hpp"
#include "rive/layout/layout_component_style.hpp"
#include "rive/layout/n_slicer.hpp"
#include "rive/layout/n_slicer_tile_mode.hpp"
#include "rive/layout_component.hpp"
#include "rive/nested_animation.hpp"
#include "rive/nested_artboard.hpp"
Expand Down Expand Up @@ -277,8 +282,16 @@ class CoreRegistry
return new Solo();
case NestedArtboardLayoutBase::typeKey:
return new NestedArtboardLayout();
case NSlicerTileModeBase::typeKey:
return new NSlicerTileMode();
case AxisYBase::typeKey:
return new AxisY();
case LayoutComponentStyleBase::typeKey:
return new LayoutComponentStyle();
case AxisXBase::typeKey:
return new AxisX();
case NSlicerBase::typeKey:
return new NSlicer();
case ListenerFireEventBase::typeKey:
return new ListenerFireEvent();
case KeyFrameUintBase::typeKey:
Expand Down Expand Up @@ -554,6 +567,9 @@ class CoreRegistry
case FollowPathConstraintBase::offsetPropertyKey:
object->as<FollowPathConstraintBase>()->offset(value);
break;
case AxisBase::normalizedPropertyKey:
object->as<AxisBase>()->normalized(value);
break;
case LayoutComponentStyleBase::intrinsicallySizedValuePropertyKey:
object->as<LayoutComponentStyleBase>()->intrinsicallySizedValue(value);
break;
Expand Down Expand Up @@ -701,6 +717,12 @@ class CoreRegistry
case NestedArtboardLayoutBase::instanceHeightScaleTypePropertyKey:
object->as<NestedArtboardLayoutBase>()->instanceHeightScaleType(value);
break;
case NSlicerTileModeBase::patchIndexPropertyKey:
object->as<NSlicerTileModeBase>()->patchIndex(value);
break;
case NSlicerTileModeBase::stylePropertyKey:
object->as<NSlicerTileModeBase>()->style(value);
break;
case LayoutComponentStyleBase::layoutWidthScaleTypePropertyKey:
object->as<LayoutComponentStyleBase>()->layoutWidthScaleType(value);
break;
Expand Down Expand Up @@ -1246,6 +1268,9 @@ class CoreRegistry
case NestedArtboardLayoutBase::instanceHeightPropertyKey:
object->as<NestedArtboardLayoutBase>()->instanceHeight(value);
break;
case AxisBase::offsetPropertyKey:
object->as<AxisBase>()->offset(value);
break;
case LayoutComponentStyleBase::gapHorizontalPropertyKey:
object->as<LayoutComponentStyleBase>()->gapHorizontal(value);
break;
Expand Down Expand Up @@ -1732,6 +1757,8 @@ class CoreRegistry
return object->as<FollowPathConstraintBase>()->orient();
case FollowPathConstraintBase::offsetPropertyKey:
return object->as<FollowPathConstraintBase>()->offset();
case AxisBase::normalizedPropertyKey:
return object->as<AxisBase>()->normalized();
case LayoutComponentStyleBase::intrinsicallySizedValuePropertyKey:
return object->as<LayoutComponentStyleBase>()->intrinsicallySizedValue();
case LayoutComponentStyleBase::linkCornerRadiusPropertyKey:
Expand Down Expand Up @@ -1833,6 +1860,10 @@ class CoreRegistry
return object->as<NestedArtboardLayoutBase>()->instanceWidthScaleType();
case NestedArtboardLayoutBase::instanceHeightScaleTypePropertyKey:
return object->as<NestedArtboardLayoutBase>()->instanceHeightScaleType();
case NSlicerTileModeBase::patchIndexPropertyKey:
return object->as<NSlicerTileModeBase>()->patchIndex();
case NSlicerTileModeBase::stylePropertyKey:
return object->as<NSlicerTileModeBase>()->style();
case LayoutComponentStyleBase::layoutWidthScaleTypePropertyKey:
return object->as<LayoutComponentStyleBase>()->layoutWidthScaleType();
case LayoutComponentStyleBase::layoutHeightScaleTypePropertyKey:
Expand Down Expand Up @@ -2206,6 +2237,8 @@ class CoreRegistry
return object->as<NestedArtboardLayoutBase>()->instanceWidth();
case NestedArtboardLayoutBase::instanceHeightPropertyKey:
return object->as<NestedArtboardLayoutBase>()->instanceHeight();
case AxisBase::offsetPropertyKey:
return object->as<AxisBase>()->offset();
case LayoutComponentStyleBase::gapHorizontalPropertyKey:
return object->as<LayoutComponentStyleBase>()->gapHorizontal();
case LayoutComponentStyleBase::gapVerticalPropertyKey:
Expand Down Expand Up @@ -2521,6 +2554,7 @@ class CoreRegistry
case IKConstraintBase::invertDirectionPropertyKey:
case FollowPathConstraintBase::orientPropertyKey:
case FollowPathConstraintBase::offsetPropertyKey:
case AxisBase::normalizedPropertyKey:
case LayoutComponentStyleBase::intrinsicallySizedValuePropertyKey:
case LayoutComponentStyleBase::linkCornerRadiusPropertyKey:
case NestedSimpleAnimationBase::isPlayingPropertyKey:
Expand Down Expand Up @@ -2569,6 +2603,8 @@ class CoreRegistry
case NestedArtboardLayoutBase::instanceHeightUnitsValuePropertyKey:
case NestedArtboardLayoutBase::instanceWidthScaleTypePropertyKey:
case NestedArtboardLayoutBase::instanceHeightScaleTypePropertyKey:
case NSlicerTileModeBase::patchIndexPropertyKey:
case NSlicerTileModeBase::stylePropertyKey:
case LayoutComponentStyleBase::layoutWidthScaleTypePropertyKey:
case LayoutComponentStyleBase::layoutHeightScaleTypePropertyKey:
case LayoutComponentStyleBase::layoutAlignmentTypePropertyKey:
Expand Down Expand Up @@ -2749,6 +2785,7 @@ class CoreRegistry
case NodeBase::yArtboardPropertyKey:
case NestedArtboardLayoutBase::instanceWidthPropertyKey:
case NestedArtboardLayoutBase::instanceHeightPropertyKey:
case AxisBase::offsetPropertyKey:
case LayoutComponentStyleBase::gapHorizontalPropertyKey:
case LayoutComponentStyleBase::gapVerticalPropertyKey:
case LayoutComponentStyleBase::maxWidthPropertyKey:
Expand Down Expand Up @@ -2947,6 +2984,8 @@ class CoreRegistry
return object->is<FollowPathConstraintBase>();
case FollowPathConstraintBase::offsetPropertyKey:
return object->is<FollowPathConstraintBase>();
case AxisBase::normalizedPropertyKey:
return object->is<AxisBase>();
case LayoutComponentStyleBase::intrinsicallySizedValuePropertyKey:
return object->is<LayoutComponentStyleBase>();
case LayoutComponentStyleBase::linkCornerRadiusPropertyKey:
Expand Down Expand Up @@ -3041,6 +3080,10 @@ class CoreRegistry
return object->is<NestedArtboardLayoutBase>();
case NestedArtboardLayoutBase::instanceHeightScaleTypePropertyKey:
return object->is<NestedArtboardLayoutBase>();
case NSlicerTileModeBase::patchIndexPropertyKey:
return object->is<NSlicerTileModeBase>();
case NSlicerTileModeBase::stylePropertyKey:
return object->is<NSlicerTileModeBase>();
case LayoutComponentStyleBase::layoutWidthScaleTypePropertyKey:
return object->is<LayoutComponentStyleBase>();
case LayoutComponentStyleBase::layoutHeightScaleTypePropertyKey:
Expand Down Expand Up @@ -3393,6 +3436,8 @@ class CoreRegistry
return object->is<NestedArtboardLayoutBase>();
case NestedArtboardLayoutBase::instanceHeightPropertyKey:
return object->is<NestedArtboardLayoutBase>();
case AxisBase::offsetPropertyKey:
return object->is<AxisBase>();
case LayoutComponentStyleBase::gapHorizontalPropertyKey:
return object->is<LayoutComponentStyleBase>();
case LayoutComponentStyleBase::gapVerticalPropertyKey:
Expand Down
89 changes: 89 additions & 0 deletions include/rive/generated/layout/axis_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#ifndef _RIVE_AXIS_BASE_HPP_
#define _RIVE_AXIS_BASE_HPP_
#include "rive/component.hpp"
#include "rive/core/field_types/core_bool_type.hpp"
#include "rive/core/field_types/core_double_type.hpp"
namespace rive
{
class AxisBase : public Component
{
protected:
typedef Component Super;

public:
static const uint16_t typeKey = 492;

/// Helper to quickly determine if a core object extends another without RTTI
/// at runtime.
bool isTypeOf(uint16_t typeKey) const override
{
switch (typeKey)
{
case AxisBase::typeKey:
case ComponentBase::typeKey:
return true;
default:
return false;
}
}

uint16_t coreType() const override { return typeKey; }

static const uint16_t offsetPropertyKey = 675;
static const uint16_t normalizedPropertyKey = 676;

private:
float m_Offset = 0.0f;
bool m_Normalized = false;

public:
inline float offset() const { return m_Offset; }
void offset(float value)
{
if (m_Offset == value)
{
return;
}
m_Offset = value;
offsetChanged();
}

inline bool normalized() const { return m_Normalized; }
void normalized(bool value)
{
if (m_Normalized == value)
{
return;
}
m_Normalized = value;
normalizedChanged();
}

void copy(const AxisBase& object)
{
m_Offset = object.m_Offset;
m_Normalized = object.m_Normalized;
Component::copy(object);
}

bool deserialize(uint16_t propertyKey, BinaryReader& reader) override
{
switch (propertyKey)
{
case offsetPropertyKey:
m_Offset = CoreDoubleType::deserialize(reader);
return true;
case normalizedPropertyKey:
m_Normalized = CoreBoolType::deserialize(reader);
return true;
}
return Component::deserialize(propertyKey, reader);
}

protected:
virtual void offsetChanged() {}
virtual void normalizedChanged() {}
};
} // namespace rive

#endif
37 changes: 37 additions & 0 deletions include/rive/generated/layout/axis_x_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef _RIVE_AXIS_XBASE_HPP_
#define _RIVE_AXIS_XBASE_HPP_
#include "rive/layout/axis.hpp"
namespace rive
{
class AxisXBase : public Axis
{
protected:
typedef Axis Super;

public:
static const uint16_t typeKey = 495;

/// Helper to quickly determine if a core object extends another without RTTI
/// at runtime.
bool isTypeOf(uint16_t typeKey) const override
{
switch (typeKey)
{
case AxisXBase::typeKey:
case AxisBase::typeKey:
case ComponentBase::typeKey:
return true;
default:
return false;
}
}

uint16_t coreType() const override { return typeKey; }

Core* clone() const override;

protected:
};
} // namespace rive

#endif
Loading

0 comments on commit f450f95

Please sign in to comment.