From bfa47c83ef427e32365d10dfd2f40cded8108444 Mon Sep 17 00:00:00 2001 From: skydoves Date: Fri, 3 Nov 2023 17:15:50 +0900 Subject: [PATCH] Support setting includeFontPadding for the default text --- balloon/api/balloon.api | 7 +++++++ balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt | 8 ++++++++ balloon/src/main/kotlin/com/skydoves/balloon/TextForm.kt | 9 +++++++++ .../com/skydoves/balloon/extensions/TextViewExtension.kt | 1 + 4 files changed, 25 insertions(+) diff --git a/balloon/api/balloon.api b/balloon/api/balloon.api index 2796e35a..2625c291 100644 --- a/balloon/api/balloon.api +++ b/balloon/api/balloon.api @@ -241,6 +241,7 @@ public final class com/skydoves/balloon/Balloon$Builder { public final fun getIconHeight ()I public final fun getIconSpace ()I public final fun getIconWidth ()I + public final fun getIncludeFontPadding ()Z public final fun getLayout ()Landroid/view/View; public final fun getLayoutRes ()Ljava/lang/Integer; public final fun getLifecycleObserver ()Landroidx/lifecycle/LifecycleObserver; @@ -415,6 +416,8 @@ public final class com/skydoves/balloon/Balloon$Builder { public final fun setIconWidth (I)Lcom/skydoves/balloon/Balloon$Builder; public final synthetic fun setIconWidth (I)V public final fun setIconWidthResource (I)Lcom/skydoves/balloon/Balloon$Builder; + public final fun setIncludeFontPadding (Z)Lcom/skydoves/balloon/Balloon$Builder; + public final synthetic fun setIncludeFontPadding (Z)V public final fun setIsAttachedInDecor (Z)Lcom/skydoves/balloon/Balloon$Builder; public final fun setIsComposableContent (Z)Lcom/skydoves/balloon/Balloon$Builder; public final fun setIsStatusBarVisible (Z)Lcom/skydoves/balloon/Balloon$Builder; @@ -823,6 +826,7 @@ public final class com/skydoves/balloon/PlacementType : java/lang/Enum { public final class com/skydoves/balloon/TextForm { public synthetic fun (Lcom/skydoves/balloon/TextForm$Builder;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getIncludeFontPadding ()Z public final fun getMovementMethod ()Landroid/text/method/MovementMethod; public final fun getText ()Ljava/lang/CharSequence; public final fun getTextColor ()I @@ -839,6 +843,7 @@ public final class com/skydoves/balloon/TextForm$Builder { public fun (Landroid/content/Context;)V public final fun build ()Lcom/skydoves/balloon/TextForm; public final fun getContext ()Landroid/content/Context; + public final fun getIncludeFontPadding ()Z public final fun getMovementMethod ()Landroid/text/method/MovementMethod; public final fun getText ()Ljava/lang/CharSequence; public final fun getTextColor ()I @@ -849,6 +854,8 @@ public final class com/skydoves/balloon/TextForm$Builder { public final fun getTextSize ()F public final fun getTextTypeface ()I public final fun getTextTypefaceObject ()Landroid/graphics/Typeface; + public final fun setIncludeFontPadding (Z)Lcom/skydoves/balloon/TextForm$Builder; + public final synthetic fun setIncludeFontPadding (Z)V public final fun setMovementMethod (Landroid/text/method/MovementMethod;)Lcom/skydoves/balloon/TextForm$Builder; public final synthetic fun setMovementMethod (Landroid/text/method/MovementMethod;)V public final fun setText (Ljava/lang/CharSequence;)Lcom/skydoves/balloon/TextForm$Builder; diff --git a/balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt b/balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt index a79ca187..0c242fbe 100644 --- a/balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt +++ b/balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt @@ -1951,6 +1951,9 @@ public class Balloon private constructor( @set:JvmSynthetic public var textLetterSpacing: Float? = null + @set:JvmSynthetic + public var includeFontPadding: Boolean = true + @set:JvmSynthetic public var textGravity: Int = Gravity.CENTER @@ -2606,6 +2609,11 @@ public class Balloon private constructor( this.textLetterSpacing = context.dimen(value) } + /** includes the font paddings of the text. */ + public fun setIncludeFontPadding(value: Boolean): Builder = apply { + this.includeFontPadding = value + } + /** * sets gravity of the text. * this only works when the width or setWidthRatio set explicitly. diff --git a/balloon/src/main/kotlin/com/skydoves/balloon/TextForm.kt b/balloon/src/main/kotlin/com/skydoves/balloon/TextForm.kt index c19e9523..ccc3a18e 100644 --- a/balloon/src/main/kotlin/com/skydoves/balloon/TextForm.kt +++ b/balloon/src/main/kotlin/com/skydoves/balloon/TextForm.kt @@ -74,6 +74,8 @@ public class TextForm private constructor( public val textLineSpacing: Float? = builder.textLineSpacing + public val includeFontPadding: Boolean = builder.includeFontPadding + public val textLetterSpacing: Float? = builder.textLetterSpacing public val textGravity: Int = builder.textGravity @@ -107,6 +109,9 @@ public class TextForm private constructor( @set:JvmSynthetic public var textLineSpacing: Float? = null + @set:JvmSynthetic + public var includeFontPadding: Boolean = true + @set:JvmSynthetic public var textLetterSpacing: Float? = null @@ -153,6 +158,10 @@ public class TextForm private constructor( public fun setTextLetterSpacing(@Dp value: Float?): Builder = apply { this.textLetterSpacing = value } + /** includes the font paddings of the text. */ + public fun setIncludeFontPadding(value: Boolean): Builder = + apply { this.includeFontPadding = value } + /** sets the line spacing value resource of the text. */ public fun setTextLineSpacingResource(@DimenRes value: Int): Builder = apply { this.textLineSpacing = context.dimen(value) diff --git a/balloon/src/main/kotlin/com/skydoves/balloon/extensions/TextViewExtension.kt b/balloon/src/main/kotlin/com/skydoves/balloon/extensions/TextViewExtension.kt index 9220b04c..475390f4 100644 --- a/balloon/src/main/kotlin/com/skydoves/balloon/extensions/TextViewExtension.kt +++ b/balloon/src/main/kotlin/com/skydoves/balloon/extensions/TextViewExtension.kt @@ -41,6 +41,7 @@ internal fun TextView.applyTextForm(textForm: TextForm) { textSize = textForm.textSize gravity = textForm.textGravity setTextColor(textForm.textColor) + includeFontPadding = textForm.includeFontPadding textForm.textLineSpacing?.let { setLineSpacing(it, 1.0f) } textForm.textLetterSpacing?.let { letterSpacing = it } textForm.textTypeface?.let { typeface = it } ?: setTypeface(typeface, textForm.textStyle)