Skip to content

Commit

Permalink
editor+runtime: text follow path orient, strength, and trim path props
Browse files Browse the repository at this point in the history
These properties take inspiration from Rive's other features. E.g. the creative time are used to manipulating the start+end+offset in trim path, and the follow path constraint has strength and orient.

For trim path, I'm noticing that the stroke always wraps. However, I thought it'd be kinda cool to intentionally not wrap if the range is <100% on a closed path. Then you can get a cool kinda effect with tangents (e.g. the penultimate row on the golden test below).

This is the new UI (in a popout):
![image](https://github.com/user-attachments/assets/952e0bc0-8c0e-47b0-8f6a-03ba67eb6349)

I added a golden test that looks like this:
<img width="926" alt="image" src="https://github.com/user-attachments/assets/376b7969-ea7b-479f-8bad-d098e5914bf0" />

Diffs=
7fe2e81969 editor+runtime: text follow path orient, strength, and trim path props (#9177)

Co-authored-by: Susan Wang <[email protected]>
  • Loading branch information
susan101566 and susan101566 committed Mar 6, 2025
1 parent dea5e09 commit ca53078
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f99c5665ceb9de1780e91483c082b190d49839f6
7fe2e819696a098f52eae52af718f036b7e08abf
50 changes: 50 additions & 0 deletions dev/defs/text/text_follow_path_modifier.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,56 @@
"string": "radial"
},
"bindable": true
},
"orient": {
"type": "bool",
"initialValue": "true",
"animates": true,
"key": {
"int": 782,
"string": "orient"
},
"bindable": true
},
"start": {
"type": "double",
"initialValue": "0",
"animates": true,
"key": {
"int": 783,
"string": "start"
},
"bindable": true
},
"end": {
"type": "double",
"initialValue": "1",
"animates": true,
"key": {
"int": 784,
"string": "end"
},
"bindable": true
},
"strength": {
"type": "double",
"initialValue": "1",
"animates": true,
"key": {
"int": 785,
"string": "strength"
},
"bindable": true
},
"offset": {
"type": "double",
"initialValue": "0",
"animates": true,
"key": {
"int": 786,
"string": "offset"
},
"bindable": true
}
}
}
40 changes: 40 additions & 0 deletions include/rive/generated/core_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,9 @@ class CoreRegistry
case TextFollowPathModifierBase::radialPropertyKey:
object->as<TextFollowPathModifierBase>()->radial(value);
break;
case TextFollowPathModifierBase::orientPropertyKey:
object->as<TextFollowPathModifierBase>()->orient(value);
break;
case TextBase::fitFromBaselinePropertyKey:
object->as<TextBase>()->fitFromBaseline(value);
break;
Expand Down Expand Up @@ -2059,6 +2062,18 @@ class CoreRegistry
case TextModifierRangeBase::offsetPropertyKey:
object->as<TextModifierRangeBase>()->offset(value);
break;
case TextFollowPathModifierBase::startPropertyKey:
object->as<TextFollowPathModifierBase>()->start(value);
break;
case TextFollowPathModifierBase::endPropertyKey:
object->as<TextFollowPathModifierBase>()->end(value);
break;
case TextFollowPathModifierBase::strengthPropertyKey:
object->as<TextFollowPathModifierBase>()->strength(value);
break;
case TextFollowPathModifierBase::offsetPropertyKey:
object->as<TextFollowPathModifierBase>()->offset(value);
break;
case TextVariationModifierBase::axisValuePropertyKey:
object->as<TextVariationModifierBase>()->axisValue(value);
break;
Expand Down Expand Up @@ -2226,6 +2241,8 @@ class CoreRegistry
return object->as<TextModifierRangeBase>()->clamp();
case TextFollowPathModifierBase::radialPropertyKey:
return object->as<TextFollowPathModifierBase>()->radial();
case TextFollowPathModifierBase::orientPropertyKey:
return object->as<TextFollowPathModifierBase>()->orient();
case TextBase::fitFromBaselinePropertyKey:
return object->as<TextBase>()->fitFromBaseline();
}
Expand Down Expand Up @@ -3123,6 +3140,14 @@ class CoreRegistry
return object->as<TextModifierRangeBase>()->falloffTo();
case TextModifierRangeBase::offsetPropertyKey:
return object->as<TextModifierRangeBase>()->offset();
case TextFollowPathModifierBase::startPropertyKey:
return object->as<TextFollowPathModifierBase>()->start();
case TextFollowPathModifierBase::endPropertyKey:
return object->as<TextFollowPathModifierBase>()->end();
case TextFollowPathModifierBase::strengthPropertyKey:
return object->as<TextFollowPathModifierBase>()->strength();
case TextFollowPathModifierBase::offsetPropertyKey:
return object->as<TextFollowPathModifierBase>()->offset();
case TextVariationModifierBase::axisValuePropertyKey:
return object->as<TextVariationModifierBase>()->axisValue();
case TextModifierGroupBase::originXPropertyKey:
Expand Down Expand Up @@ -3211,6 +3236,7 @@ class CoreRegistry
case BindablePropertyBooleanBase::propertyValuePropertyKey:
case TextModifierRangeBase::clampPropertyKey:
case TextFollowPathModifierBase::radialPropertyKey:
case TextFollowPathModifierBase::orientPropertyKey:
case TextBase::fitFromBaselinePropertyKey:
return CoreBoolType::id;
case ViewModelInstanceListItemBase::viewModelIdPropertyKey:
Expand Down Expand Up @@ -3611,6 +3637,10 @@ class CoreRegistry
case TextModifierRangeBase::falloffFromPropertyKey:
case TextModifierRangeBase::falloffToPropertyKey:
case TextModifierRangeBase::offsetPropertyKey:
case TextFollowPathModifierBase::startPropertyKey:
case TextFollowPathModifierBase::endPropertyKey:
case TextFollowPathModifierBase::strengthPropertyKey:
case TextFollowPathModifierBase::offsetPropertyKey:
case TextVariationModifierBase::axisValuePropertyKey:
case TextModifierGroupBase::originXPropertyKey:
case TextModifierGroupBase::originYPropertyKey:
Expand Down Expand Up @@ -3737,6 +3767,8 @@ class CoreRegistry
return object->is<TextModifierRangeBase>();
case TextFollowPathModifierBase::radialPropertyKey:
return object->is<TextFollowPathModifierBase>();
case TextFollowPathModifierBase::orientPropertyKey:
return object->is<TextFollowPathModifierBase>();
case TextBase::fitFromBaselinePropertyKey:
return object->is<TextBase>();
case ViewModelInstanceListItemBase::viewModelIdPropertyKey:
Expand Down Expand Up @@ -4525,6 +4557,14 @@ class CoreRegistry
return object->is<TextModifierRangeBase>();
case TextModifierRangeBase::offsetPropertyKey:
return object->is<TextModifierRangeBase>();
case TextFollowPathModifierBase::startPropertyKey:
return object->is<TextFollowPathModifierBase>();
case TextFollowPathModifierBase::endPropertyKey:
return object->is<TextFollowPathModifierBase>();
case TextFollowPathModifierBase::strengthPropertyKey:
return object->is<TextFollowPathModifierBase>();
case TextFollowPathModifierBase::offsetPropertyKey:
return object->is<TextFollowPathModifierBase>();
case TextVariationModifierBase::axisValuePropertyKey:
return object->is<TextVariationModifierBase>();
case TextModifierGroupBase::originXPropertyKey:
Expand Down
91 changes: 91 additions & 0 deletions include/rive/generated/text/text_follow_path_modifier_base.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _RIVE_TEXT_FOLLOW_PATH_MODIFIER_BASE_HPP_
#define _RIVE_TEXT_FOLLOW_PATH_MODIFIER_BASE_HPP_
#include "rive/core/field_types/core_bool_type.hpp"
#include "rive/core/field_types/core_double_type.hpp"
#include "rive/text/text_target_modifier.hpp"
namespace rive
{
Expand Down Expand Up @@ -31,9 +32,19 @@ class TextFollowPathModifierBase : public TextTargetModifier
uint16_t coreType() const override { return typeKey; }

static const uint16_t radialPropertyKey = 779;
static const uint16_t orientPropertyKey = 782;
static const uint16_t startPropertyKey = 783;
static const uint16_t endPropertyKey = 784;
static const uint16_t strengthPropertyKey = 785;
static const uint16_t offsetPropertyKey = 786;

protected:
bool m_Radial = false;
bool m_Orient = true;
float m_Start = 0.0f;
float m_End = 1.0f;
float m_Strength = 1.0f;
float m_Offset = 0.0f;

public:
inline bool radial() const { return m_Radial; }
Expand All @@ -47,10 +58,70 @@ class TextFollowPathModifierBase : public TextTargetModifier
radialChanged();
}

inline bool orient() const { return m_Orient; }
void orient(bool value)
{
if (m_Orient == value)
{
return;
}
m_Orient = value;
orientChanged();
}

inline float start() const { return m_Start; }
void start(float value)
{
if (m_Start == value)
{
return;
}
m_Start = value;
startChanged();
}

inline float end() const { return m_End; }
void end(float value)
{
if (m_End == value)
{
return;
}
m_End = value;
endChanged();
}

inline float strength() const { return m_Strength; }
void strength(float value)
{
if (m_Strength == value)
{
return;
}
m_Strength = value;
strengthChanged();
}

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

Core* clone() const override;
void copy(const TextFollowPathModifierBase& object)
{
m_Radial = object.m_Radial;
m_Orient = object.m_Orient;
m_Start = object.m_Start;
m_End = object.m_End;
m_Strength = object.m_Strength;
m_Offset = object.m_Offset;
TextTargetModifier::copy(object);
}

Expand All @@ -61,12 +132,32 @@ class TextFollowPathModifierBase : public TextTargetModifier
case radialPropertyKey:
m_Radial = CoreBoolType::deserialize(reader);
return true;
case orientPropertyKey:
m_Orient = CoreBoolType::deserialize(reader);
return true;
case startPropertyKey:
m_Start = CoreDoubleType::deserialize(reader);
return true;
case endPropertyKey:
m_End = CoreDoubleType::deserialize(reader);
return true;
case strengthPropertyKey:
m_Strength = CoreDoubleType::deserialize(reader);
return true;
case offsetPropertyKey:
m_Offset = CoreDoubleType::deserialize(reader);
return true;
}
return TextTargetModifier::deserialize(propertyKey, reader);
}

protected:
virtual void radialChanged() {}
virtual void orientChanged() {}
virtual void startChanged() {}
virtual void endChanged() {}
virtual void strengthChanged() {}
virtual void offsetChanged() {}
};
} // namespace rive

Expand Down
7 changes: 7 additions & 0 deletions include/rive/text/text_follow_path_modifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ class TextFollowPathModifier : public TextFollowPathModifierBase

protected:
void radialChanged() override;
void orientChanged() override;
void startChanged() override;
void endChanged() override;
void offsetChanged() override;
void strengthChanged() override;

private:
RawPath m_worldPath;
RawPath m_localPath;
PathMeasure m_pathMeasure;

void modifierShapeDirty();
};
} // namespace rive

Expand Down
Loading

0 comments on commit ca53078

Please sign in to comment.