-
Notifications
You must be signed in to change notification settings - Fork 1
templates: add motion template system for dynamic SDUI generation #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ import kotlin.math.min | |||||||||||
| /** | ||||||||||||
| * Text size variants for video overlays. | ||||||||||||
| */ | ||||||||||||
| internal enum class MotionTextVariant { | ||||||||||||
| enum class MotionTextVariant { | ||||||||||||
| H1, | ||||||||||||
| H2, | ||||||||||||
| H3, | ||||||||||||
|
|
@@ -33,6 +33,11 @@ internal data class MotionTextSizes( | |||||||||||
| * Provides scaled font sizes in pixels relative to the video dimensions. | ||||||||||||
| */ | ||||||||||||
| object MotionTextSizeProvider { | ||||||||||||
| /** | ||||||||||||
| * Base scale for all font sizes. Can be updated to scale all text sizes at once. | ||||||||||||
| */ | ||||||||||||
| var baseTextScale: Float = 1.5f | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate Line [39] exposes global mutable scale without bounds checks; Proposed fix object MotionTextSizeProvider {
@@
- var baseTextScale: Float = 1.5f
+ var baseTextScale: Float = 1.5f
+ set(value) {
+ field = value.coerceAtLeast(0.1f)
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Returns the [MotionTextSizes] for the given [aspectRatio]. | ||||||||||||
| * | ||||||||||||
|
|
@@ -44,26 +49,26 @@ object MotionTextSizeProvider { | |||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return MotionTextSizes( | ||||||||||||
| h1 = aspectRatio.scale(96f), | ||||||||||||
| h2 = aspectRatio.scale(72f), | ||||||||||||
| h3 = aspectRatio.scale(48f), | ||||||||||||
| h4 = aspectRatio.scale(36f), | ||||||||||||
| h5 = aspectRatio.scale(24f), | ||||||||||||
| h6 = aspectRatio.scale(20f), | ||||||||||||
| p = aspectRatio.scale(32f), | ||||||||||||
| h1 = aspectRatio.scale(160f * baseTextScale), | ||||||||||||
| h2 = aspectRatio.scale(120f * baseTextScale), | ||||||||||||
| h3 = aspectRatio.scale(80f * baseTextScale), | ||||||||||||
| h4 = aspectRatio.scale(60f * baseTextScale), | ||||||||||||
| h5 = aspectRatio.scale(40f * baseTextScale), | ||||||||||||
| h6 = aspectRatio.scale(32f * baseTextScale), | ||||||||||||
| p = aspectRatio.scale(48f * baseTextScale), | ||||||||||||
| ) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Returns the font size in pixels for the given [variant] and [aspectRatio]. | ||||||||||||
| * | ||||||||||||
| * For [VideoAspectRatio.Custom], it returns a fallback size of 32.0f. | ||||||||||||
| * For [VideoAspectRatio.Custom], it returns a fallback size of (32.0f * baseTextScale). | ||||||||||||
| */ | ||||||||||||
| internal fun getFontSize( | ||||||||||||
| fun getFontSize( | ||||||||||||
| aspectRatio: VideoAspectRatio, | ||||||||||||
| variant: MotionTextVariant, | ||||||||||||
| ): Float { | ||||||||||||
| val sizes = getTextSizes(aspectRatio) ?: return 32f | ||||||||||||
| val sizes = getTextSizes(aspectRatio) ?: return aspectRatio.scale(32f * baseTextScale) | ||||||||||||
|
|
||||||||||||
| return when (variant) { | ||||||||||||
| MotionTextVariant.H1 -> sizes.h1 | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||||||||||
| package com.tejpratapsingh.motionlib.core | ||||||||||||||
|
|
||||||||||||||
| import android.view.ViewGroup | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Interface for defining a transition between two [MotionView]s. | ||||||||||||||
| * A transition usually overlaps the end of the first view and the start of the second view. | ||||||||||||||
| */ | ||||||||||||||
| interface MotionTransition { | ||||||||||||||
| /** | ||||||||||||||
| * Applies the transition between [from] and [to]. | ||||||||||||||
| * | ||||||||||||||
| * @param from The outgoing view. | ||||||||||||||
| * @param to The incoming view. | ||||||||||||||
| * @param duration The duration of the transition in frames. | ||||||||||||||
| */ | ||||||||||||||
| fun apply(from: MotionView, to: MotionView, duration: Int) | ||||||||||||||
|
Check failure on line 17 in modules/core/src/main/java/com/tejpratapsingh/motionlib/core/MotionTransition.kt
|
||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap Line 17 needs multiline parameter formatting; current signature fails style checks. Proposed fix- fun apply(from: MotionView, to: MotionView, duration: Int)
+ fun apply(
+ from: MotionView,
+ to: MotionView,
+ duration: Int,
+ )📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: ktlint[failure] 17-17: [failure] 17-17: [failure] 17-17: 🤖 Prompt for AI Agents |
||||||||||||||
| } | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.tejpratapsingh.motionlib.core | ||
|
|
||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
|
|
||
| class MotionTextSizeProviderTest { | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| // Reset baseTextScale before each test | ||
| MotionTextSizeProvider.baseTextScale = 1.0f | ||
| } | ||
|
|
||
| @Test | ||
| fun testDefaultFontSizes() { | ||
| val aspectRatio = VideoAspectRatio.Ratio16x9_1080 // 1920x1080, min is 1080, scale is 1.0 | ||
|
|
||
| // H1 should be 160f * 1.0 = 160f | ||
| assertEquals(160f, MotionTextSizeProvider.getFontSize(aspectRatio, MotionTextVariant.H1), 0.01f) | ||
|
|
||
| // P should be 48f * 1.0 = 48f | ||
| assertEquals(48f, MotionTextSizeProvider.getFontSize(aspectRatio, MotionTextVariant.P), 0.01f) | ||
| } | ||
|
|
||
| @Test | ||
| fun testBaseTextScale() { | ||
| val aspectRatio = VideoAspectRatio.Ratio16x9_1080 // 1920x1080, min is 1080, scale is 1.0 | ||
|
|
||
| MotionTextSizeProvider.baseTextScale = 2.0f | ||
|
|
||
| // H1 should be 160f * 2.0 = 320f | ||
| assertEquals(320f, MotionTextSizeProvider.getFontSize(aspectRatio, MotionTextVariant.H1), 0.01f) | ||
|
|
||
| // P should be 48f * 2.0 = 96f | ||
| assertEquals(96f, MotionTextSizeProvider.getFontSize(aspectRatio, MotionTextVariant.P), 0.01f) | ||
| } | ||
|
|
||
| @Test | ||
| fun testScalingWithAspectRatio() { | ||
| // 480p 16:9 is 854x480, min is 480. | ||
| // Scale = 480 / 1080 = 0.4444... | ||
| val aspectRatio = VideoAspectRatio.Ratio16x9_480 | ||
|
|
||
| val expectedH1 = 160f * (480f / 1080f) | ||
| assertEquals(expectedH1, MotionTextSizeProvider.getFontSize(aspectRatio, MotionTextVariant.H1), 0.01f) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.