Skip to content

Commit

Permalink
Adding origin to text.
Browse files Browse the repository at this point in the history
Adds origin to text object that works just like the origin of a parametric path. It can be moved in freeze mode too. Adds support in the editor, Flutter runtime, and C++ runtime.

Diffs=
9b8dacbac Adding origin to text. (#5533)
797fb4cbd Add CMake support for building Android and Catch2 Tests (#5468)

Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
  • Loading branch information
luigi-rosso and luigi-rosso committed Jul 7, 2023
1 parent e42bfd2 commit 8e9077d
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5c76c52e1792a94a5cf0f7b9d03b48f2d96b6a02
9b8dacbacbfb232303773dd7a6008fdffaecc29c
26 changes: 26 additions & 0 deletions lib/src/generated/rive_core_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,16 @@ class RiveCoreContext {
object.height = value;
}
break;
case TextBase.originXPropertyKey:
if (object is TextBase && value is double) {
object.originX = value;
}
break;
case TextBase.originYPropertyKey:
if (object is TextBase && value is double) {
object.originY = value;
}
break;
case TextValueRunBase.styleIdPropertyKey:
if (object is TextValueRunBase && value is int) {
object.styleId = value;
Expand Down Expand Up @@ -1738,6 +1748,8 @@ class RiveCoreContext {
case TextStyleAxisBase.axisValuePropertyKey:
case TextBase.widthPropertyKey:
case TextBase.heightPropertyKey:
case TextBase.originXPropertyKey:
case TextBase.originYPropertyKey:
case DrawableAssetBase.heightPropertyKey:
case DrawableAssetBase.widthPropertyKey:
return doubleType;
Expand Down Expand Up @@ -2202,6 +2214,10 @@ class RiveCoreContext {
return (object as TextBase).width;
case TextBase.heightPropertyKey:
return (object as TextBase).height;
case TextBase.originXPropertyKey:
return (object as TextBase).originX;
case TextBase.originYPropertyKey:
return (object as TextBase).originY;
case DrawableAssetBase.heightPropertyKey:
return (object as DrawableAssetBase).height;
case DrawableAssetBase.widthPropertyKey:
Expand Down Expand Up @@ -3324,6 +3340,16 @@ class RiveCoreContext {
object.height = value;
}
break;
case TextBase.originXPropertyKey:
if (object is TextBase) {
object.originX = value;
}
break;
case TextBase.originYPropertyKey:
if (object is TextBase) {
object.originY = value;
}
break;
case DrawableAssetBase.heightPropertyKey:
if (object is DrawableAssetBase) {
object.height = value;
Expand Down
50 changes: 50 additions & 0 deletions lib/src/generated/text/text_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,54 @@ abstract class TextBase extends Drawable {

void heightChanged(double from, double to);

/// --------------------------------------------------------------------------
/// OriginX field with key 363.
static const double originXInitialValue = 0.0;
double _originX = originXInitialValue;
static const int originXPropertyKey = 363;

/// Origin x in normalized coordinates (0.5 = center, 0 = left, 1 = right).
double get originX => _originX;

/// Change the [_originX] field value.
/// [originXChanged] will be invoked only if the field's value has changed.
set originX(double value) {
if (_originX == value) {
return;
}
double from = _originX;
_originX = value;
if (hasValidated) {
originXChanged(from, value);
}
}

void originXChanged(double from, double to);

/// --------------------------------------------------------------------------
/// OriginY field with key 364.
static const double originYInitialValue = 0.0;
double _originY = originYInitialValue;
static const int originYPropertyKey = 364;

/// Origin y in normalized coordinates (0.5 = center, 0 = top, 1 = bottom).
double get originY => _originY;

/// Change the [_originY] field value.
/// [originYChanged] will be invoked only if the field's value has changed.
set originY(double value) {
if (_originY == value) {
return;
}
double from = _originY;
_originY = value;
if (hasValidated) {
originYChanged(from, value);
}
}

void originYChanged(double from, double to);

@override
void copy(covariant TextBase source) {
super.copy(source);
Expand All @@ -149,5 +197,7 @@ abstract class TextBase extends Drawable {
_overflowValue = source._overflowValue;
_width = source._width;
_height = source._height;
_originX = source._originX;
_originY = source._originY;
}
}
29 changes: 28 additions & 1 deletion lib/src/rive_core/text/text.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:math';
import 'dart:typed_data';
import 'dart:ui';

Expand Down Expand Up @@ -173,7 +174,11 @@ class Text extends TextBase with TextStyleContainer {
}


final Size _size = Size.zero;
Mat2D get originTransform => Mat2D.multiply(Mat2D(), worldTransform,
Mat2D.fromTranslate(-_size.width * originX, -_size.height * originY));

Size _size = Size.zero;
Size get size => _size;

static const double paragraphSpacing = 20;

Expand Down Expand Up @@ -343,6 +348,17 @@ class Text extends TextBase with TextStyleContainer {
}
y += paragraphSpacing;
}
switch (sizing) {
case TextSizing.autoWidth:
_size = Size(maxX, max(0, y - paragraphSpacing));
break;
case TextSizing.autoHeight:
_size = Size(width, max(0, y - paragraphSpacing));
break;
case TextSizing.fixed:
_size = Size(width, height);
break;
}
}

bool _renderStylesDirty = true;
Expand All @@ -361,6 +377,7 @@ class Text extends TextBase with TextStyleContainer {

canvas.save();
canvas.transform(worldTransform.mat4);
canvas.translate(-_size.width * originX, -_size.height * originY);
if (overflow == TextOverflow.clipped) {
canvas.clipRect(Offset.zero & _size);
}
Expand Down Expand Up @@ -534,4 +551,14 @@ class Text extends TextBase with TextStyleContainer {

@override
String toString() => 'Text(id: $id, text: $text)';

@override
void originXChanged(double from, double to) {
context.markNeedsAdvance();
}

@override
void originYChanged(double from, double to) {
context.markNeedsAdvance();
}
}
5 changes: 4 additions & 1 deletion lib/src/rive_core/text/text_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ class TextStyle extends TextStyleBase
asset = context.resolve(to);
}

void _fontDecoded() => _markShapeDirty();
void _fontDecoded() {
_markShapeDirty();
_variationHelper?.addDirt(ComponentDirt.textShape);
}


@override
Expand Down

0 comments on commit 8e9077d

Please sign in to comment.