Skip to content

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

Merged
merged 7 commits into from
Dec 29, 2024

Conversation

DEAN-Cherry
Copy link
Contributor

@DEAN-Cherry DEAN-Cherry commented Dec 10, 2024

Adding new Theme propety candidateTextColor to control candidate text color. The default value is as same as the keyTextColor


添加新的 Theme 属性 candidateTextColor,以控制候选文本颜色。默认值与 keyTextColor 相同。

Adding new theme propety `candidateTextColor` to control candidate text color. The default value is as same as the keyTextColor
@DEAN-Cherry DEAN-Cherry changed the title feat(Candidate & Theme): Adding control of Candidate Text feat(Candidate & Theme): Adding control of candidate text color Dec 10, 2024
@DEAN-Cherry DEAN-Cherry changed the title feat(Candidate & Theme): Adding control of candidate text color feat(Candidate & Theme): Add control of candidate text color Dec 10, 2024
Copy link
Member

@rocka rocka left a 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:

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:

  1. Add 2 additional theme properties candidateLabelColor and candidateCommentColor
  2. Bump theme version to 2.1
  3. Apply those new theme properites to CandidateView as well
    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
@DEAN-Cherry
Copy link
Contributor Author

DEAN-Cherry commented Dec 27, 2024

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.

private fun applyStrategy(oldVersion: String, obj: JsonObject) =
strategies
.takeWhile { it.version != oldVersion }
.foldRight(EmptyTransform) { it, acc -> it.transformation compose acc }
.invoke(obj)

Images

candidateLabelColor

PixPin_2024-12-28_13-11-51

candidateCommentColor

PixPin_2024-12-28_13-14-22

candidateTextColor

PixPin_2024-12-28_13-13-07

@DEAN-Cherry DEAN-Cherry requested a review from rocka December 27, 2024 19:28
Copy link
Member

@rocka rocka left a 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

DEAN-Cherry and others added 4 commits December 28, 2024 14:34
…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>
@DEAN-Cherry
Copy link
Contributor Author

Thanks for your review, I didn't realize I could use candidateTextColor to specify the text color for LabelUI. I overlooked that.

PixPin_2024-12-28_14-40-55

@DEAN-Cherry DEAN-Cherry requested a review from rocka December 28, 2024 10:35
@rocka rocka changed the title feat(Candidate & Theme): Add control of candidate text color Add theme properties for candidate label/text/comment color Dec 29, 2024
@rocka rocka merged commit fda9ecb into fcitx5-android:master Dec 29, 2024
6 checks passed
rocka added a commit to fcitx5-android/theme-designer that referenced this pull request Dec 29, 2024
also add candidate text preview on the bar
related: fcitx5-android/fcitx5-android#647

Co-authored-by: Rocka <i@rocka.me>
@DEAN-Cherry DEAN-Cherry deleted the feat/candidateTextColor branch December 29, 2024 13:34
mokapsing pushed a commit to mokapsing/fcitx5-android that referenced this pull request Dec 30, 2024
…ndroid#647)

bump theme verison to 2.1

Co-authored-by: rocka <i@rocka.me>
wxyzh pushed a commit to wxyzh/fcitx5-android that referenced this pull request Jan 2, 2025
…ndroid#647)

bump theme verison to 2.1

Co-authored-by: rocka <i@rocka.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants