-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: labeled candidate item in CandidatesView couldn't break line cor…
…rectly The spans for spanned string can influence the line break strategy in TextView, therefore, CandidateItemSpan is implemented to replace the original CandidateSpan to fix the issue.
- Loading branch information
1 parent
2b4736e
commit 0d45c41
Showing
2 changed files
with
36 additions
and
21 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/osfans/trime/ime/candidates/popup/CandidateItemSpan.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2015 - 2025 Rime community | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package com.osfans.trime.ime.candidates.popup | ||
|
||
import android.graphics.Typeface | ||
import android.text.TextPaint | ||
import android.text.style.MetricAffectingSpan | ||
import androidx.annotation.ColorInt | ||
|
||
class CandidateItemSpan( | ||
@ColorInt | ||
private val color: Int, | ||
private val textSize: Float, | ||
private val typeface: Typeface, | ||
) : MetricAffectingSpan() { | ||
override fun updateDrawState(textPaint: TextPaint) { | ||
textPaint.color = color | ||
updateState(textPaint) | ||
} | ||
|
||
override fun updateMeasureState(textPaint: TextPaint) { | ||
updateState(textPaint) | ||
} | ||
|
||
private fun updateState(textPaint: TextPaint) { | ||
textPaint.textSize = textSize | ||
textPaint.typeface = typeface | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters