feat: add runtime layout fit type for ios, android, web

First steps towards supporting artboard resizing in our runtimes. This PR includes:
- New Fit type `autoResizeArtboard`. After a bit of back and forth, I think this keeps the API simple.
- ScaleFactor which represents a scale value to scale the artboard by in addition to resizing (only applies with `autoResizeArtboard`). This may be useful because an artboard is created at a specific width/height, but it may be deployed to platforms where it is rendered to a much smaller or larger surface/texture. Currently the default is 1.0 (no scale), however, an alternative is to have it default to something like textureSize / artboardSize so we sort of auto normalize it.
- Implemented on iOS. Once this is finalzed, we can work with DevRels to implement across all runtimes.
- TODO : Bubble up an event when the artboard size is changed internally by the .riv

https://github.com/user-attachments/assets/20e9fdda-5c3e-4f3f-b2f5-104ff0291fbe

Diffs=
e71b4cc081 feat: add runtime layout fit type for ios, android, web (#8341)

Co-authored-by: CI <pggordonhayes@gmail.com>
Co-authored-by: David Skuza <david@rive.app>
Co-authored-by: Philip Chung <philterdesign@gmail.com>
This commit is contained in:
HayesGordon
2024-10-30 12:35:33 +00:00
parent 2046c4ddc6
commit fb00a355a3
4 changed files with 18 additions and 6 deletions

View File

@@ -1 +1 @@
c64659be84f36d2855173491d6bcab8255c50950
e71b4cc081aad43f304589d7233fe2d8065fda85

View File

@@ -10,7 +10,8 @@ enum class Fit : unsigned char
fitWidth,
fitHeight,
none,
scaleDown
scaleDown,
layout
};
class Alignment

View File

@@ -26,7 +26,11 @@ class Vec2D;
// Helper that computes a matrix to "align" content (source) to fit inside frame
// (destination).
Mat2D computeAlignment(Fit, Alignment, const AABB& frame, const AABB& content);
Mat2D computeAlignment(Fit,
Alignment,
const AABB& frame,
const AABB& content,
const float scaleFactor = 1.0f);
enum class RenderBufferType
{
@@ -183,9 +187,11 @@ public:
void align(Fit fit,
Alignment alignment,
const AABB& frame,
const AABB& content)
const AABB& content,
const float scaleFactor = 1.0f)
{
transform(computeAlignment(fit, alignment, frame, content));
transform(
computeAlignment(fit, alignment, frame, content, scaleFactor));
}
};
} // namespace rive

View File

@@ -7,7 +7,8 @@ using namespace rive;
Mat2D rive::computeAlignment(Fit fit,
Alignment alignment,
const AABB& frame,
const AABB& content)
const AABB& content,
const float scaleFactor)
{
float contentWidth = content.width();
float contentHeight = content.height();
@@ -52,6 +53,10 @@ Mat2D rive::computeAlignment(Fit fit,
scaleX = scaleY = minScale;
break;
}
case Fit::layout:
{
return Mat2D::fromScale(scaleFactor, scaleFactor);
}
case Fit::none:
{
scaleX = scaleY = 1.0f;