-
Notifications
You must be signed in to change notification settings - Fork 212
Add theme properties for candidate label/text/comment color #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add theme properties for candidate label/text/comment color #647
Conversation
Adding new theme propety `candidateTextColor` to control candidate text color. The default value is as same as the keyTextColor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! However I can't merge this PR in current state since it does not meet some of the design pattern in the code base. I'll explain all of my considerations.
To begin with, Theme
is not an arbitary JSON object, it's a versioned structure with migration strategies:
fcitx5-android/app/src/main/java/org/fcitx/fcitx5/android/data/theme/CustomThemeSerializer.kt
Lines 55 to 79 in 78cfe81
private val strategies: List<MigrationStrategy> = | |
// Add migrations here | |
listOf( | |
MigrationStrategy("2.0") { | |
JsonObject(it.toMutableMap().apply { | |
if (get("backgroundImage") != null) { | |
val popupBkgColor = if (getValue("isDark").jsonPrimitive.boolean) { | |
ThemePreset.PixelDark.popupBackgroundColor | |
} else { | |
ThemePreset.PixelLight.popupBackgroundColor | |
} | |
put("popupBackgroundColor", JsonPrimitive(popupBkgColor)) | |
put("popupTextColor", getValue("keyTextColor")) | |
put("genericActiveBackgroundColor", getValue("accentKeyBackgroundColor")) | |
put("genericActiveForegroundColor", getValue("accentKeyTextColor")) | |
} else { | |
put("popupBackgroundColor", getValue("barColor")) | |
put("popupTextColor", getValue("keyTextColor")) | |
put("genericActiveBackgroundColor", getValue("accentKeyBackgroundColor")) | |
put("genericActiveForegroundColor", getValue("accentKeyTextColor")) | |
} | |
}) | |
}, | |
MigrationStrategy("1.0", EmptyTransform) | |
) |
which means that you should bump the theme version and implement migration strategy when adding new properties, in order to keep compatibility with older theme files.
Additionally, I feel like it's kind of not "worth it" to bump the version for just one new property. In fact I'm also planning to add more theme properties in this version, including toolbarIconColor
, candidateLabelColor
, candidateWindowBorderColor
and so on.
Seeing you've also submitted fcitx5-android/theme-designer#5 , I suggest following changes:
- Add 2 additional theme properties
candidateLabelColor
andcandidateCommentColor
- Bump theme version to
2.1
- Apply those new theme properites to CandidateView as well
Lines 29 to 42 in 78cfe81
fun update(candidate: FcitxEvent.Candidate, active: Boolean) { val fg = if (active) theme.genericActiveForegroundColor else theme.keyTextColor val altFg = if (active) theme.genericActiveForegroundColor else theme.altKeyTextColor root.text = buildSpannedString { color(fg) { append(candidate.label) } color(fg) { append(candidate.text) } if (candidate.comment.isNotBlank()) { append(" ") color(altFg) { append(candidate.comment) } } } val bg = if (active) theme.genericActiveBackgroundColor else Color.TRANSPARENT root.backgroundColor = bg }
- Add candidateTextColor, candidateLabelColor, and candidateCommentColor to Theme interface - Update CandidateItemUi and LabeledCandidateItemUi to use new candidate text colors - Add migration strategy for upgrading themes to version 2.1 - Update ThemePreset with default values for new candidate text colors
# Conflicts: # app/src/main/java/org/fcitx/fcitx5/android/data/theme/Theme.kt # app/src/main/java/org/fcitx/fcitx5/android/data/theme/ThemePreset.kt
Thank you so much for the detailed review @rocka ! I have incorporated all your suggestions and modified the code. Could you please take another look? Again, thanks a lot for your thorough review! Under my basic test, the mirgration strategy works well. But I am a liitle confused about the migration over more than two versions. It seems I only need to add the new strategy based on the latest version and this funcation will do the rest. fcitx5-android/app/src/main/java/org/fcitx/fcitx5/android/data/theme/CustomThemeSerializer.kt Lines 44 to 48 in 78cfe81
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some little suggestions: simplify the migration strategy and actually apply candidateLabelColor
app/src/main/java/org/fcitx/fcitx5/android/input/candidates/floating/LabeledCandidateItemUi.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/org/fcitx/fcitx5/android/input/candidates/floating/LabeledCandidateItemUi.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/org/fcitx/fcitx5/android/data/theme/CustomThemeSerializer.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/org/fcitx/fcitx5/android/data/theme/CustomThemeSerializer.kt
Outdated
Show resolved
Hide resolved
…oating/LabeledCandidateItemUi.kt Co-authored-by: rocka <i@rocka.me>
…emeSerializer.kt Co-authored-by: rocka <i@rocka.me>
…emeSerializer.kt Co-authored-by: rocka <i@rocka.me>
…oating/LabeledCandidateItemUi.kt Co-authored-by: rocka <i@rocka.me>
also add candidate text preview on the bar related: fcitx5-android/fcitx5-android#647 Co-authored-by: Rocka <i@rocka.me>
…ndroid#647) bump theme verison to 2.1 Co-authored-by: rocka <i@rocka.me>
…ndroid#647) bump theme verison to 2.1 Co-authored-by: rocka <i@rocka.me>
Adding new
Theme
propetycandidateTextColor
to control candidate text color. The default value is as same as thekeyTextColor
添加新的
Theme
属性candidateTextColor
,以控制候选文本颜色。默认值与keyTextColor
相同。