From a9faf1d1dacd36bb781fa0b15a998c35b6785698 Mon Sep 17 00:00:00 2001 From: WhiredPlanck Date: Mon, 30 Dec 2024 23:43:51 +0800 Subject: [PATCH] refactor: share the features of CandidateItemUi to SwitchUi --- .../ime/bar/ui/always/switches/SwitchUi.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/osfans/trime/ime/bar/ui/always/switches/SwitchUi.kt b/app/src/main/java/com/osfans/trime/ime/bar/ui/always/switches/SwitchUi.kt index b02f4ba796..1d48f718ac 100644 --- a/app/src/main/java/com/osfans/trime/ime/bar/ui/always/switches/SwitchUi.kt +++ b/app/src/main/java/com/osfans/trime/ime/bar/ui/always/switches/SwitchUi.kt @@ -10,17 +10,21 @@ import android.view.ViewGroup import com.osfans.trime.data.theme.ColorManager import com.osfans.trime.data.theme.FontManager import com.osfans.trime.data.theme.Theme +import com.osfans.trime.ime.core.AutoScaleTextView import com.osfans.trime.util.rippleDrawable import splitties.dimensions.dp +import splitties.views.dsl.constraintlayout.bottomOfParent import splitties.views.dsl.constraintlayout.centerHorizontally import splitties.views.dsl.constraintlayout.centerVertically import splitties.views.dsl.constraintlayout.constraintLayout import splitties.views.dsl.constraintlayout.horizontalChain import splitties.views.dsl.constraintlayout.packed +import splitties.views.dsl.constraintlayout.topOfParent import splitties.views.dsl.constraintlayout.verticalChain import splitties.views.dsl.core.Ui import splitties.views.dsl.core.matchParent import splitties.views.dsl.core.textView +import splitties.views.dsl.core.view import splitties.views.dsl.core.wrapContent import splitties.views.gravityCenter import splitties.views.horizontalPadding @@ -32,7 +36,7 @@ class SwitchUi( var enabled: Int = -1 private val firstText = - textView { + view(::AutoScaleTextView) { textSize = theme.generalStyle.candidateTextSize typeface = FontManager.getTypeface("candidate_font") isSingleLine = true @@ -41,10 +45,11 @@ class SwitchUi( } private val lastText = - textView { + view(::AutoScaleTextView) { textSize = theme.generalStyle.commentTextSize typeface = FontManager.getTypeface("comment_font") isSingleLine = true + gravity = gravityCenter ColorManager.getColor("comment_text_color")?.let { setTextColor(it) } visibility = View.GONE } @@ -58,8 +63,15 @@ class SwitchUi( verticalChain( listOf(lastText, firstText), style = packed, - defaultHeight = wrapContent, defaultWidth = wrapContent, + initFirstViewParams = { + height = dp(theme.generalStyle.commentHeight) + topOfParent() + }, + initLastViewParams = { + height = dp(theme.generalStyle.candidateViewHeight) + bottomOfParent() + }, initParams = { centerHorizontally() }, ) } else {