Skip to content
This repository was archived by the owner on Sep 3, 2023. It is now read-only.

Commit 985e161

Browse files
committed
maybeSetAdditionalPadding -> additionalPaddingForFont, fix formatting, add kdoc. additionalPaddingForFont doesn't need a height parameter, can just use measuredHeight. Part of #1936.
1 parent e28453b commit 985e161

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

core/src/main/java/com/afollestad/materialdialogs/internal/main/DialogTitleLayout.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import android.widget.TextView
2828
import androidx.annotation.RestrictTo
2929
import androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP
3030
import com.afollestad.materialdialogs.R
31+
import com.afollestad.materialdialogs.utils.MDUtil.additionalPaddingForFont
3132
import com.afollestad.materialdialogs.utils.MDUtil.dimenPx
32-
import com.afollestad.materialdialogs.utils.MDUtil.maybeSetAdditionalPadding
3333
import com.afollestad.materialdialogs.utils.isNotVisible
3434
import com.afollestad.materialdialogs.utils.isRtl
3535
import com.afollestad.materialdialogs.utils.isVisible
@@ -92,10 +92,7 @@ class DialogTitleLayout(
9292
val requiredHeight = iconViewHeight.coerceAtLeast(titleView.measuredHeight)
9393
val actualHeight = requiredHeight + frameMarginVertical + titleMarginBottom
9494

95-
setMeasuredDimension(
96-
parentWidth,
97-
actualHeight
98-
)
95+
setMeasuredDimension(parentWidth, actualHeight)
9996
}
10097

10198
override fun onLayout(
@@ -114,8 +111,8 @@ class DialogTitleLayout(
114111

115112
val titleHalfHeight = titleView.measuredHeight / 2
116113
val titleTop = contentMidPoint - titleHalfHeight
117-
val titleBottom = contentMidPoint + titleHalfHeight
118-
+ titleView.maybeSetAdditionalPadding(titleView.measuredHeight)
114+
val titleBottom = contentMidPoint + titleHalfHeight +
115+
titleView.additionalPaddingForFont()
119116
var titleLeft: Int
120117
var titleRight: Int
121118

core/src/main/java/com/afollestad/materialdialogs/utils/MDUtil.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,14 @@ object MDUtil {
234234
}
235235
}
236236

237-
@RestrictTo(LIBRARY_GROUP) fun TextView.maybeSetAdditionalPadding(height: Int): Int {
237+
/**
238+
* See [https://github.com/afollestad/material-dialogs/issues/1936]. Calculates additional
239+
* spacing required to prevent a given [TextView] from being cut off at the bottom.
240+
*/
241+
@RestrictTo(LIBRARY_GROUP) fun TextView.additionalPaddingForFont(): Int {
238242
val fm = paint.fontMetrics
239243
val textHeight = fm.descent - fm.ascent
240-
return if (textHeight > height) (textHeight - height).toInt() else 0
244+
return if (textHeight > measuredHeight) (textHeight - measuredHeight).toInt() else 0
241245
}
242246

243247
@RestrictTo(LIBRARY_GROUP) inline fun Int?.ifNotZero(block: (value: Int) -> Unit) {

0 commit comments

Comments
 (0)