Skip to content

feat(ui): zebra hilite slots for candidate rows - #1986

Closed
takomitkm wants to merge 5 commits into
rime:masterfrom
takomitkm:feat/zebra-hilite-upstream
Closed

takomitkm wants to merge 5 commits into
rime:masterfrom
takomitkm:feat/zebra-hilite-upstream

Conversation

@takomitkm

@takomitkm takomitkm commented Nov 19, 2026 •

Copy link
Copy Markdown

What

Adds configurable "zebra hilite" stripes: besides the moving selection highlight, any set of candidate rows can stay permanently hilited, selected by repeating 0/1 patterns with per-slot colors.

Config (user weasel.custom.yaml):

patch:
  style/zebra_hilite: true            # master switch, default off
  style/zebra_hilite_slots:           # sibling node, see note below
    a:                                # slot names are free-form;
      pattern: "01"                   # repeating bitmap over the 0-based page row index:
                                      # "01" lights rows 2, 4, 6, ... of every page
      # all colors are optional; transparent (0) inherits the scheme's hilited colors
      back_color: 0x30fa3a0a
      text_color: 0xffffff
    b:
      pattern: "000100"               # any other period/phase, different colors
      back_color: 0x302184d0

Semantics:

  • Patterns are matched against the 0-based row index within the current page, so the stripes stay aligned with on-screen rows regardless of menu/page_size.
  • The first slot whose pattern selects a row wins; slots iterate in alphabetical name order (librime maps are std::map), so a outranks z when patterns overlap.
  • A slot's colors override only what it specifies; transparent entries fall back to the active color scheme's hilited colors. Rows matching no slot keep the scheme's normal colors.
  • The moving selection highlight and hover highlight keep precedence over stripes.
  • A slot without a usable pattern (no 0/1 digits after filtering) is skipped with a log line; separators like "0,1" are filtered out so they cannot stretch the period.
  • Patterns are filtered down to 0/1 only.

Why a sibling node for the slots

style/zebra_hilite (a scalar) and the slot list cannot live under one config node: rime patches apply scalar and map writes to the same node in document order, and one write would either fail the patch or wipe the other (a bool over a map, or a map over a bool). Keeping them as siblings makes the two independent and order-insensitive.

Implementation notes

  • include/WeaselIPCData.h: UIStyle gains zebra_hilite plus a std::vector<ZebraSlot> (pattern + five optional colors). The slot vector is serialized at the end of the UIStyle IPC stream, keeping the legacy prefix byte-compatible with older peers: an old server ignores the trailing bytes; a new client against an old server only occurs in a half-install window and fails deserialization cleanly there.
  • RimeWithWeasel/RimeWithWeasel.cpp: slots are enumerated via config_begin_map/config_next in LoadWeaselUIStyle; the slot list is cleared only when the config actually defines style/zebra_hilite_slots, so a schema without zebra settings keeps inheriting the base slot table (matching how other style keys work).
  • WeaselUI/WeaselPanel.cpp: in _DrawCandidates, after the per-row colors are picked, the first matching slot overrides them before drawing. Works with both the GDI and DirectWrite paths of the 0.17.4 painter and with the DirectWrite-only painter on current master (this branch is based on master).

Before submitting

  • Searched rime/weasel issues/PRs for zebra/alternating/every-other/odd/even highlight — no prior art found
  • Checked squirrel (macOS) and fcitx5 — neither implements per-row stripes
  • CI green on the fork (lint with clang-format 18, msbuild, xmake)
  • NOT yet tested on a real machine — this PR is a draft; the author will verify the rendered result on an actual installation before marking it ready for review

Notes for reviewers

  • WeaselDeployer's style preview (UIStyleSettings::LoadPreviewStyle) picks the feature up automatically through LoadWeaselUIStyle; no deployer-side changes were needed.
  • Happy to rework the config surface (key names, slot ordering, pattern syntax) if maintainers prefer a different shape — that's why this is a draft.

Port of the 0.17.4 zebra hilite feature onto current master, adapted
to the DirectWrite-only painter: colors are overridden in the unified
per-row drawing loop instead of the removed GDI channel.

Adds style/zebra_hilite (bool, default off) plus a sibling node
style/zebra_hilite_slots whose entries each carry a repeating 0/1
pattern (matched against the 0-based page row index, so "01" lights
the 2nd/4th/6th... rows regardless of page size) and optional
back_color/text_color/label_color/comment_color/border_color that fall
back to the active color scheme's hilited colors when left transparent.
The first slot matching a row wins; slots iterate in alphabetical name
order (librime maps are std::map). The moving selection and hover
highlight keep precedence over stripes. A slot without a usable
pattern is skipped with a log line; patterns are filtered down to 0/1
so separators cannot stretch the period.

The switch and the slot list live in separate config nodes because a
scalar and a map cannot coexist under one rime config node: patches
apply in document order and one write would either fail or wipe the
other. The slot vector is serialized at the end of the UIStyle IPC
stream, keeping the legacy prefix byte-compatible with older peers.
Three spots flagged by the lint job (clang-format 18).
The previous commit flipped ar & to ar& per clang-format 15 output,
but the lint job uses clang-format 18 (Chromium style), which wants
the spaced form here.
clang-format 18 (Chromium) wraps each parameter onto its own line
here; the two-line wrap tripped the lint job at 547:28.
A zebra slot that leaves border_color at 0 kept the normal candidate
border, while back/text/label/comment colors all inherit the scheme's
hilited variants. Fall back to hilited_candidate_border_color when the
scheme defines one, mirroring the back-color fallback; otherwise keep
the normal candidate border.
@takomitkm
takomitkm marked this pull request as ready for review November 22, 2026 21:13
@takomitkm
takomitkm marked this pull request as draft November 22, 2026 21:15
@takomitkm

Copy link
Copy Markdown
Author

我觉得这个把ui搞得太复杂了,好像不太好,只是我觉得在我一直用数字选的情况下高亮永远都在第一个没什么用,所以弄了这个,好像还是有错,不想改了,感觉没用

@takomitkm takomitkm closed this Nov 23, 2026
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.

1 participant