Skip to content

「仓输入法皮肤」迁移指南


背景及前景样式添加 buttonStyleType 参数

Section titled “背景及前景样式添加 buttonStyleType 参数”

新增必选参数 buttonStyleType,用于设定样式的类型。

确保背景样式(backgroundStyle)及前景样式(foregroundStyle)中都指定了 buttonStyleType 参数,否则无法解析已定义的样式。

示例:

# 改造前
foregroundStyle: qButtonForegroundStyle
qButtonForegroundStyle:
text: "q"
# 改造后
foregroundStyle: qButtonForegroundStyle
qButtonForegroundStyle:
buttonStyleType: text
text: "q"

根据你想要添加的样式内容,为 buttonStyleType 指定相应的值,具体内容请查阅 buttonStyleType 配置参考

在新版中,文字样式的初始位置为「居中」对齐。如果之前为文字样式添加了 center 属性,需要将其移除或者调整其值,使文字显示在您想要的位置。

在新版中,皮肤中的 JavaScript 脚本功能已被废除。这意味着之前通过 JavaScript 动态生成的样式名称或文本内容将不再有效。

如需动态生成样式或文本,请使用事件通知条件样式来代替。

  • 事件通知:用来监听某个键盘的状态变化,当状态改变时,更新相应的样。使用场景:根据输入了某个按键,切换另一个按键的样式;回车键根据环境变化。
  • 条件样式:用来初始化按键的样式,根据某个条件来决定使用哪种样式。使用场景:中英切换,简繁切换。

示例:

修改前
lockButton:
backgroundStyle: systemButtonBackgroundStyle
foregroundStyle: |-
// JavaScript
function getText() {
return $getSymbolicKeyboardLockState() ? "lockButtonForegroundStyle" : "unlockButtonForegroundStyle";
}
lockButtonForegroundStyle:
systemImageName: "lock"
normalColor: 000000
highlightColor: 000000
fontSize: 20
unlockButtonForegroundStyle:
systemImageName: "lock.open"
normalColor: 000000
highlightColor: 000000
fontSize: 20
修改后
lockButton:
backgroundStyle: systemButtonBackgroundStyle
foregroundStyle:
- {
styleName: unlockButtonForegroundStyle,
conditionKey: $symbolicKeyboardLockState,
conditionValue: false,
}
- {
styleName: lockButtonForegroundStyle,
conditionKey: $symbolicKeyboardLockState,
conditionValue: true,
}
lockButtonForegroundStyle:
buttonStyleType: systemImage
systemImageName: "lock"
normalColor: 000000
highlightColor: 000000
fontSize: 20
unlockButtonForegroundStyle:
buttonStyleType: systemImage
systemImageName: "lock.open"
normalColor: 000000
highlightColor: 000000
fontSize: 20

在新版本中使用 hintSymbolsStyle(旧版本为:holdSymbolsStyle)来定义按键长按时显示的符号样式。

示例:

长按样式名变更
qButton:
holdSymbolsStyle: qButtonHoldSymbolsStyle
hintSymbolsStyle: qButtonHintSymbolsStyle

同时,里面的参数也发生了一些变化。

  • 新增可选 size 参数,可自定义符号列表中符号的大小,如果不指定,默认与当前按键的可视区域大小相同。
  • 旧版本使用 selectedStyle 定义选中后的符号高亮样式,新版本中使用 selectedBackgroundStyle 参数。
  • 旧版本使用 foregroundStyleactions 联合定义一个符号的外观及它的行为。新版本新增 symbolStyles 参数,用于定义长按后显示的每个符号的样式。
修改前
qButtonHoldSymbolsStyle:
backgroundStyle: alphabeticHoldSymbolsBackgroundStyle
foregroundStyle:
- qButtonHoldSymbolsOfqForegroundStyle
- qButtonHoldSymbolsOf1ForegroundStyle
- qButtonHoldSymbolsOfQForegroundStyle
actions:
- { character: q }
- { symbol: 1 }
- { character: Q }
selectedStyle: alphabeticHoldSymbolsSelectedStyle
selectedIndex: 0
修改后
qButtonHintSymbolsStyle:
size:
width: 50
height: 50
insets: { top: 4, bottom: 4, left: 4, right: 4 }
backgroundStyle: alphabeticHoldSymbolsBackgroundStyle
selectedBackgroundStyle: alphabeticHoldSymbolsSelectedStyle
selectedIndex: 0
symbolStyles:
- qButtonHintSymbolsOf1Style
- qButtonHintSymbolsOf2Style
- qButtonHintSymbolsOf3Style

现在单个符号的样式与键盘按键样式是相同的。如:

qButtonHintSymbolsOf1Style:
foregroundStyle: qButtonHoldSymbolsOfqForegroundStyle
action: { character: q }

旧版本的动画定义是在背景样式或前景样式中定义的,而新版本中,动画必须定义在「按键」的样式下。

示例:

修改前
# 字母按键背景样式
alphabeticBackgroundStyle:
...
animation: alphabeticBackgroundAnimation
# 字母按键背景动画
alphabeticBackgroundAnimation:
# type: 动画类型
# - bounds: 尺寸大小变化动画
- type: bounds
duration: 40 # 动画时长,单位毫秒
repeatCount: 1
fromScale: 1
toScale: 0.87
- type: bounds
duration: 80
repeatCount: 1
fromScale: 0.87
toScale: 1
- type: apng
file: animation
修改后
qButton:
backgroundStyle: qButtonBackgroundStyle
animation:
- scaleAnimation
- cartoonAnimation
- physicsAnimation
# 放大或缩小的动画
scaleAnimation:
animationType: scale
isAutoReverse: false
scale: 0.80
pressDuration: 40
releaseDuration: 80
# 用于替代 apng 图片类型的动画
cartoonAnimation:
animationType: cartoon
# 默认60,可不设置
fps: 60
images:
- lleeimage_0.png
- lleeimage_1.png
# 用于替换之前 emit 动画
physicsAnimation:
animationType: physics
duration: 1500
images:
- 01.png
- 02.png
randomImage: true
randomPosition: { x: 50, y: 10 }
startPosition: { x: 0, y: 0 }
endPosition: { x: 0, y: -70 }
useOpacity: true
startOpacity: 1
endOpacity: 0.2
useRotation: true
randomAngle: 6.28
startAngle: 0
endAngle: 6.28

在按键的定义中,新增了 animation 参数,用于定义按键的动画效果。其中每个动画通过 animationType 参数来指定动画类型,不同的动画类型有不同的参数和动画效果。

具体参数说明请查阅参数字典。

预编辑区样式关键字变更

预编辑区样式调整
#
preedit:
preeditStyle:
insets: { left: 4, top: 1 }
backgroundStyle: preeditBackgroundStyle
foregroundStyle: preeditForegroundStyle

工具栏调整结构

  • 将工具栏样式与工具栏布局单独为两个属性:toolbarStyletoolbarLayout
  • 删除原候选文字栏设置相关属性

工具栏布局 toolbarLayout 与按键区域布局逻辑相同

工具栏调整
#
toolbar:
backgroundStyle: toolbarBackgroundStyle
# primaryButtonStyle: primaryButtonStyle
secondaryButtonStyle:
- toolbarButton1Style
- toolbarButton2Style
- toolbarButton3Style
- toolbarButton4Style
horizontalCandidateStyle: horizontalCandidateStyle
verticalCandidateStyle: verticalCandidateStyle
# 工具栏样式
toolbarStyle:
insets: { left: 50, right: 50 }
backgroundStyle: toolbarBackgroundStyle
# 工具栏布局
toolbarLayout:
- HStack:
subviews:
- Cell: horizontalNumberSymbols
- Cell: leftArrowButton
- Cell: downArrowButton
- Cell: rightArrowButton

横向候选文字栏从原 toolbar 属性中拆分,独立为 horizontalCandidatesStylehorizontalCandidatesLayout 两个属性。

  • horizontalCandidatesStyle:用于设置文字栏整体的外观样式
  • horizontalCandidatesLayout:用于设置文字栏的内部空间的布局,与按键区域布局逻辑相同
横向候选文字栏调整
#
toolbar:
...
horizontalCandidateStyle: horizontalCandidateStyle
# 横向候选文字栏调整
horizontalCandidatesStyle:
insets: { left: 3, bottom: 1, top: 3 }
backgroundStyle: horizontalCandidatesBackgroundStyle
# 横向候选文字栏布局
horizontalCandidatesLayout:
- HStack:
subviews:
- Cell: horizontalCandidates
- Cell: clearPreeditButton
- Cell: expandButton

纵向候选文字栏也从原 toolbar 属性中拆分,独立为样式 verticalCandidatesStyle 布局 verticalCandidatesLayout 两个属性。

  • verticalCandidatesStyle:用于设置文字栏整体的外观样式
  • verticalCandidatesLayout:用于设置文字栏的内部空间的布局,与按键区域布局逻辑相同
纵向候选文字栏调整
#
toolbar:
...
verticalCandidateStyle: verticalCandidateStyle
# 纵向候选文字栏样式
verticalCandidatesStyle:
insets: { top: 3, bottom: 3, left: 4, right: 4 }
backgroundStyle: verticalCandidateBackgroundStyle
# 纵向候选文字栏布局
verticalCandidatesLayout:
- HStack:
subviews:
- Cell: verticalCandidates
- HStack:
style: verticalLastRowStyle
subviews:
- Cell: verticalPageUpButton
- Cell: verticalPageDownButton
- Cell: collapseCandidatesButton
- Cell: candidateBackspaceButton

候选字长按列表 candidateContextMenu 属性从 toolbar 中拆分。

候选字长按列表调整
#
toolbar:
...
candidateContextMenu: candidateContextMenu
candidateContextMenu:
- name: "测试删除"
action: { sendKeys: "Shift+Delete" }
candidateContextMenu:
- name: "测试删除"
action: { sendKeys: "Shift+Delete" }
横向自定义符号列表
horizontalNumberSymbols:
type: horizontalSymbols
size:
width: 2/3
# (非必须,默认为 5)用来调整显示区域内最大列数
maxColumns: 10
# (非必须,默认为 false)用来调整显示区域内的内容是否从右向左排列
contentRightToLeft: true
insets: { left: 3, right: 3 }
backgroundStyle: alphabeticBackgroundStyle
dataSource: horizontalSymbolsDataSource
# 用于定义符号列表中每个符号的样式(仅支持文本)
cellStyle: collectionCellStyle
collectionCellStyle:
backgroundStyle: collectionCellBackgroundStyle
foregroundStyle: collectionCellForegroundStyle
collectionCellBackgroundStyle:
buttonStyleType: fileImage
highlightImage:
file: anjian
image: image11
collectionCellForegroundStyle:
buttonStyleType: text
normalColor: 000000
badgeNormalColor: 575757
badgeHighlightColor: 575757
fontSize: 18
fontWeight: bold
# 数据源无需定义在 dataSource 之下
horizontalSymbolsDataSource:
- { label: '1', action: tab }
- 2
- 3
- 4

数据源的定义目前支持三种方式

  • 纯字符串
horizontalSymbolsDataSource:
- 1
- 2
...
  • 显示与输出分开定义
horizontalSymbolsDataSource:
- { label: '1', value: "a" }
...

注意:这种方式会使用 symbol 类型直接上屏,不会发送给 rime 引擎。

  • 独立 action 定义
horizontalSymbolsDataSource:
- { label: '1', action: tab }
...

这种方式有最大的灵活度,你可以为每个数据源自定义按键动作。

数据源对象新增 styleName 参数,用于指定自定义样式。

  • 可选参数,默认为空,如果不指定,则使用 cellStyle 定义的文本样式。

注意:此参数必须与 label 一起使用。

horizontalSymbolsDataSource:
- { label: '1', action: tab, styleName: 'leftArrowButton'}
- { label: '1', value: "1", styleName: 'leftArrowButton'}
- 2
- 3
- 4
leftArrowButton:
backgroundStyle: alphabeticBackgroundStyle
foregroundStyle:
- leftArrowButtonForegroundStyle

styleName 引用的样式与按键样式定义相同。

注意:动作 action 的定义需要放在数据源中,样式引用中的定义的 action 是无效的。

为了支持横向候选文字栏可以自定义布局,新增了 horizontalCandidates 类型。

用于在自定义布局中,自定义一块区域用来显示横向候选文字。

注意:此类型仅适用于 horizontalCandidatesLayout 布局中,如果在其他布局中使用,会出现不显示候选字的问题。

horizontalCandidates:
# 定义一个横向候选文字展示区域
type: horizontalCandidates
size:
width: 2/3
# (非必须,默认值为 7)用于定义显示区域内最大候选文字数量
maxColumns: 10
insets: { left: 3, right: 3 }
backgroundStyle: alphabeticBackgroundStyle
# 用于定义候选文字显示样式
candidateStyle: candidateStyle
candidateStyle:
insets: { left: 3, right: 3 }
highlightBackgroundColor: ffffff
preferredBackgroundColor: ffffff
preferredIndexColor: 000000
preferredTextColor: 000000
preferredCommentColor: 000000
indexColor: 000000
textColor: 000000
commentColor: 000000
indexFontSize: 18
textFontSize: 18
commentFontSize: 18

为了支持纵向候选文字区域可以自定义布局,新增了 verticalCandidates 类型。

用于在自定义布局中,自定义一块区域用来显示纵向候选文字。

注意:此类型仅适用于 verticalCandidatesLayout 布局中,如果在其他布局中使用,会出现不显示候选字的问题。

verticalCandidates:
# 定义一个纵向候选文字显示区域
type: verticalCandidates
insets: { left: 3, right: 3 }
# (非必须,默认值为 4)显示区域内候选文字最大行数
maxRows: 8
# (非必须,默认值为 5)显示区域内候选文字最大列数
maxColumns: 10
# (非必须)显示区域内分割线颜色
separatorColor: '#33338888'
backgroundStyle: alphabeticBackgroundStyle
# 候选文字样式
candidateStyle: verticalCandidateCellStyle
verticalCandidateCellStyle:
highlightBackgroundColor: ffffff
preferredBackgroundColor: ffffff
preferredIndexColor: 1a73e9
preferredTextColor: 1a73e9
preferredCommentColor: 1a73e9
indexColor: 000000
textColor: 000000
commentColor: 000000
indexFontSize: 16
textFontSize: 16
commentFontSize: 16
bottomRowHeight: 50

符号列表的数据源,无需在放在 dataSource 下。

数据源调整
#
dataSource:
category:
[
"常用",
"中文",
...
]
常用:
- ""
- ""
- ""
...
category:
[
"常用",
"中文",
...
]
常用:
- ""
- ""
- ""
...