Skip to content

Commit

Permalink
feat: restore vertical layout in candidate window
Browse files Browse the repository at this point in the history
refactor: update rime options on start input view
  • Loading branch information
WhiredPlanck committed Dec 5, 2024
1 parent d9408de commit 4559365
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class PagedCandidatesUi(
) : Ui {
private var menu = RimeProto.Context.Menu()

private var isHorizontal = true

sealed class UiHolder(
open val ui: Ui,
) : RecyclerView.ViewHolder(ui.root) {
Expand Down Expand Up @@ -78,7 +80,7 @@ class PagedCandidatesUi(
is UiHolder.Pagination -> {
holder.ui.update(menu)
holder.ui.root.updateLayoutParams<FlexboxLayoutManager.LayoutParams> {
alignSelf = AlignItems.CENTER
alignSelf = if (isHorizontal) AlignItems.CENTER else AlignItems.STRETCH
}
}
}
Expand All @@ -92,8 +94,6 @@ class PagedCandidatesUi(
private val candidatesLayoutManager =
FlexboxLayoutManager(ctx).apply {
flexWrap = FlexWrap.WRAP
flexDirection = FlexDirection.ROW
alignItems = AlignItems.BASELINE
}

override val root =
Expand All @@ -106,8 +106,21 @@ class PagedCandidatesUi(
layoutManager = candidatesLayoutManager
}

fun update(menu: RimeProto.Context.Menu) {
fun update(
menu: RimeProto.Context.Menu,
isHorizontal: Boolean,
) {
this.menu = menu
this.isHorizontal = isHorizontal
candidatesLayoutManager.apply {
if (isHorizontal) {
flexDirection = FlexDirection.ROW
alignItems = AlignItems.BASELINE
} else {
flexDirection = FlexDirection.COLUMN
alignItems = AlignItems.STRETCH
}
}
candidatesAdapter.submitList(menu.candidates.toList())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,24 @@ class CandidatesView(
private fun updateUi() {
if (evaluateVisibility()) {
preeditUi.update(inputComposition)
// if CandidatesView can be shown, rime engine is ready most of the time,
// so it should be safety to get option immediately
val isHorizontalLayout = rime.run { getRuntimeOption("_horizontal") }
when (candidatesMode) {
PopupCandidatesMode.CURRENT_PAGE -> {
candidatesUi.root.let {
if (it.visibility == View.GONE) {
it.visibility = View.VISIBLE
}
}
candidatesUi.update(menu)
candidatesUi.update(menu, isHorizontalLayout)
}

PopupCandidatesMode.PREEDIT_ONLY -> {
candidatesUi.root.let {
if (it.visibility != View.GONE) {
it.visibility = View.GONE
candidatesUi.update(RimeProto.Context.Menu())
candidatesUi.update(RimeProto.Context.Menu(), isHorizontalLayout)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
2 -> Locale(latinLocale[0], latinLocale[1])
else -> Locale.US
}
updateRimeOption(this)
Timber.d("Trime.onCreate completed")
}
} catch (e: Exception) {
Expand Down Expand Up @@ -428,6 +427,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
) {
Timber.d("onStartInputView: restarting=%s", restarting)
postRimeJob {
updateRimeOption(this)
InputFeedbackManager.loadSoundEffects(this@TrimeInputMethodService)
InputFeedbackManager.resetPlayProgress()
isComposable =
Expand Down

0 comments on commit 4559365

Please sign in to comment.