-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
editor: nine-slicing core data type definitions
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
1 parent
a7a0a01
commit f450f95
Showing
21 changed files
with
544 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4fb978a9230fc006b5e575364f062907e7dd2afe | ||
ed56d2de61afb05abd99e8bab6775b63ab89f1a3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "NSlicer", | ||
"key": { | ||
"int": 493, | ||
"string": "nslicer" | ||
}, | ||
"extends": "component.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.