feat: add runtime layout fit type for ios, android, web · borisblizzard/rive-runtime@fb00a35 · GitHub
Skip to content

Commit fb00a35

Browse files
HayesGordonHayesGordondskuzaphilter
committed
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>
1 parent 2046c4d commit fb00a35

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

.rive_head

Lines changed: 1 addition & 1 deletion

include/rive/layout.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ enum class Fit : unsigned char
1010
fitWidth,
1111
fitHeight,
1212
none,
13-
scaleDown
13+
scaleDown,
14+
layout
1415
};
1516

1617
class Alignment

include/rive/renderer.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ class Vec2D;
2626

2727
// Helper that computes a matrix to "align" content (source) to fit inside frame
2828
// (destination).
29-
Mat2D computeAlignment(Fit, Alignment, const AABB& frame, const AABB& content);
29+
Mat2D computeAlignment(Fit,
30+
Alignment,
31+
const AABB& frame,
32+
const AABB& content,
33+
const float scaleFactor = 1.0f);
3034

3135
enum class RenderBufferType
3236
{
@@ -183,9 +187,11 @@ class Renderer
183187
void align(Fit fit,
184188
Alignment alignment,
185189
const AABB& frame,
186-
const AABB& content)
190+
const AABB& content,
191+
const float scaleFactor = 1.0f)
187192
{
188-
transform(computeAlignment(fit, alignment, frame, content));
193+
transform(
194+
computeAlignment(fit, alignment, frame, content, scaleFactor));
189195
}
190196
};
191197
} // namespace rive

src/renderer.cpp

Lines changed: 6 additions & 1 deletion

0 commit comments

Comments
 (0)