From 46ec1ab395ed341b1c1904249adffa9ded264d3e Mon Sep 17 00:00:00 2001 From: LeanBitLab Date: Fri, 4 Dec 2026 19:26:34 +0530 Subject: [PATCH] fix(style): match the font style strip to the keyboard theme --- .../latin/style/StylePreviewStripView.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/style/StylePreviewStripView.kt b/app/src/main/java/helium314/keyboard/latin/style/StylePreviewStripView.kt index cd27ee14f..731ad6fd3 100644 --- a/app/src/main/java/helium314/keyboard/latin/style/StylePreviewStripView.kt +++ b/app/src/main/java/helium314/keyboard/latin/style/StylePreviewStripView.kt @@ -9,6 +9,7 @@ import android.graphics.Color import android.graphics.Typeface import android.graphics.drawable.Drawable import android.graphics.drawable.GradientDrawable +import android.graphics.drawable.InsetDrawable import android.graphics.drawable.RippleDrawable import android.util.AttributeSet import android.util.TypedValue @@ -90,21 +91,32 @@ class StylePreviewStripView @JvmOverloads constructor( lp.gravity = Gravity.CENTER_VERTICAL closeButton.layoutParams = lp - closeButton.setPadding(expandPadding, expandPadding, expandPadding, expandPadding) closeButton.scaleType = ImageView.ScaleType.CENTER_INSIDE // Themed close icon matching the active keyboard theme (e.g. ic_close_rounded on rounded themes) val closeDrawable = KeyboardIconsSet.instance.getNewDrawable(ToolbarKey.CLOSE_HISTORY.name, context) ?: ContextCompat.getDrawable(context, R.drawable.ic_close) closeButton.setImageDrawable(closeDrawable) - closeButton.setBackgroundResource(R.drawable.toolbar_key_background) + val inset = ((keyDimension - chipHeightPx()) / 2).coerceAtLeast(0) + closeButton.background = InsetDrawable( + createChipDrawable(chipColor(colors), keyboardCornerRadiusPx(resources), colors.get(ColorType.KEY_TEXT)), + inset + ) + // after the background, an InsetDrawable would otherwise replace the padding + closeButton.setPadding(expandPadding, expandPadding, expandPadding, expandPadding) colors.setColor(closeButton, ColorType.TOOL_BAR_KEY) - colors.setColor(closeButton.background, ColorType.TOOL_BAR_EXPAND_KEY_BACKGROUND) } /** * Populates style chips previewing the target text or sample word. */ + private fun chipHeightPx() = (30 * resources.displayMetrics.density).toInt() + + // without key borders the key color can equal the strip, so keep the toolbar button color there + private fun chipColor(colors: Colors) = colors.get( + if (colors.hasKeyBorders) ColorType.KEY_BACKGROUND else ColorType.TOOL_BAR_EXPAND_KEY_BACKGROUND + ) + fun setTargetText( targetText: String, onApply: (String) -> Unit, @@ -116,7 +128,7 @@ class StylePreviewStripView @JvmOverloads constructor( scrollView.scrollTo(0, 0) chipsContainer.removeAllViews() val density = resources.displayMetrics.density - val chipHeight = (30 * density).toInt() + val chipHeight = chipHeightPx() val cornerRadius = keyboardCornerRadiusPx(resources) val marginH = (4 * density).toInt() val padH = (14 * density).toInt() @@ -154,7 +166,7 @@ class StylePreviewStripView @JvmOverloads constructor( setTypeface(null, Typeface.NORMAL) setTextColor(colors.get(ColorType.KEY_TEXT)) background = createChipDrawable( - bgColor = colors.get(ColorType.TOOL_BAR_EXPAND_KEY_BACKGROUND), + bgColor = chipColor(colors), cornerRadiusPx = cornerRadius, rippleColor = colors.get(ColorType.KEY_TEXT) ) @@ -211,7 +223,7 @@ class StylePreviewStripView @JvmOverloads constructor( setTypeface(null, Typeface.NORMAL) setTextColor(colors.get(ColorType.KEY_TEXT)) background = createChipDrawable( - bgColor = colors.get(ColorType.TOOL_BAR_EXPAND_KEY_BACKGROUND), + bgColor = chipColor(colors), cornerRadiusPx = cornerRadius, rippleColor = colors.get(ColorType.KEY_TEXT) )