Skip to content

Commit

Permalink
allow setting row count for scroll mode
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Sep 29, 2024
1 parent d36dd67 commit a5210d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 11 additions & 0 deletions page/customize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
HOVER_BEHAVIOR,
PAGING_BUTTONS_STYLE,
} from './ux'
import { setMaxRow } from './scroll'
import {
setBlink,
setBlur,
Expand Down Expand Up @@ -42,6 +43,9 @@ interface STYLE_JSON {
Typography: {
PagingButtonsStyle: PAGING_BUTTONS_STYLE
}
ScrollMode: {
MaxRowCount: string
}
Background: {
ImageUrl: string
Blur: CONFIG_BOOL
Expand Down Expand Up @@ -108,6 +112,7 @@ const PAGING_OUTER = `${PANEL} :is(.fcitx-prev, .fcitx-next)`
const PAGING_INNER = `${PANEL} .fcitx-paging-inner`
const HIGHLIGHT_MARK = `${PANEL} .fcitx-highlighted .fcitx-mark`
const HIGHLIGHT_ORIGINAL_MARK = `${PANEL} .fcitx-highlighted-original .fcitx-mark`
const HORIZONTAL_SCROLL = `${PANEL} .fcitx-hoverables.fcitx-horizontal-scroll`

const PANEL_LIGHT = `.fcitx-light${PANEL}`
const PANEL_LIGHT_HIGHLIGHT = `${PANEL_LIGHT} .fcitx-hoverable.fcitx-highlighted .fcitx-hoverable-inner`
Expand Down Expand Up @@ -396,6 +401,12 @@ export function setStyle(style: string) {

setPagingButtonsStyle(j.Typography.PagingButtonsStyle)

const maxRow = Number(j.ScrollMode.MaxRowCount)
setMaxRow(maxRow)
rules[HORIZONTAL_SCROLL] = {
'max-block-size': px(maxRow * 30),
}

if (j.Background.ImageUrl) {
let url = j.Background.ImageUrl
if (url.startsWith('fcitx://')) {
Expand Down
2 changes: 1 addition & 1 deletion page/generic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
}

&.fcitx-horizontal-scroll {
max-block-size: 180px; /* If block-size, 2 rows will have 90px each. */
max-block-size: 180px; /* For default 6 rows. If block-size, 2 rows will have 90px each. */
inline-size: 400px;
flex-wrap: wrap;
overflow-y: auto;
Expand Down
8 changes: 6 additions & 2 deletions page/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import {
hideContextmenu,
} from './ux'

const MAX_ROW = 6
let MAX_ROW = 6
const MAX_COLUMN = 6

export function setMaxRow(n: number) {
MAX_ROW = n
}

let scrollState: SCROLL_STATE = 0

export function getScrollState() {
Expand Down Expand Up @@ -244,7 +248,7 @@ hoverables.addEventListener('scroll', () => {
if (scrollEnd || fetching) {
return
}
// This is safe since there are at least 7 lines.
// This is safe since there are at least 2 lines.
const bottomRightIndex = itemCountInFirstNRows(rowItemCount.length - 1) - 1
const candidates = hoverables.querySelectorAll('.fcitx-candidate')
const bottomRight = candidates[bottomRightIndex]
Expand Down

0 comments on commit a5210d4

Please sign in to comment.