imfuxiao / Hamster

librime for iOS App
GNU General Public License v3.0
1.29k stars 80 forks source link

切换语言时键盘布局问题 #397

Closed weearc closed 11 months ago

weearc commented 1 year ago

类似 #391 启用中英文切换按键并设置为空格左侧后,中文下位置如图所示 IMG_3709 英文键盘如下所示 IMG_3710 希望能够保持切换后位置或给出可以自定义默认键盘布局的配置文件或开关。另:启用自定义布局或配色后,尽管已经将边框大小设置为0且圆角大小设置为0仍显示了圆角 IMG_3712 目前自定义布局没法应用在英文输入面板上,因此切换后是默认布局。附配置文件

# 通用配置
general:
  enableAppleCloud: false
  regexOnCopyFile:
#    - ^.*[.]userdb.*$
#    - ^.*build.*$
#    - ^.*SharedSupport.*$
#    - ^.*[.]bin$

# 工具栏
toolbar:
  # 是否开启工具栏
  enableToolbar: true
  # 显示键盘 icon 按钮
  displayAppIconButton: false
  # 显示键盘 dissmiss 按钮
  displayKeyboardDismissButton: false
  # 工具栏总高度
  heightOfToolbar: 50
  # 拼写区高度(剩余高度由候选文字占用)
  heightOfCodingArea: 10
  # 拼写区字体大小
  codingAreaFontSize: 12
  # 候选文字字体大小
  candidateWordFontSize: 18
  # 候选文字备注信息字体大小。
  # 对应 rime 候选字的 comment 信息
  candidateCommentFontSize: 12
  # 是否显示候选文字索引
  displayIndexOfCandidateWord: false
  # 是否显示候选文字 Comment 信息
  displayCommentOfCandidateWord: false

# 键盘相关配置
keyboard:
  # 使用键盘类型:
  # chinese: 中文26键
  # chineseNineGrid: 中文九宫格
  # custom(name): 自定义键盘,其中 name 对应自定义键盘配置(customizeKeyboards)中的 name。如: custom(中文26键)
  useKeyboardType: chinese
  # 关闭划动文本显示
  disableSwipeLabel: false
  # 上下显示划动文本不规则布局
  swipeLabelUpAndDownIrregularLayout: false
  # 上下显示划动文本规则布局
  swipeLabelUpAndDownLayout: false
  # 上划显示到左侧
  upSwipeOnLeft: true
  # 显示按键气泡
  displayButtonBubbles: true
  # 启用按键声
  enableKeySounds: true
  # 启用触控反馈
  enableHapticFeedback: false
  # 反馈强度
  hapticFeedbackIntensity: 3
  # 启用分号按键
  displaySemicolonButton: false
  # 启用符号按键
  displayClassifySymbolButton: false
  # 启用空格左侧按键
  displaySpaceLeftButton: false
  spaceLeftButtonProcessByRIME: true
  keyValueOfSpaceLeftButton: ","
  # 启用空格右侧按键
  displaySpaceRightButton: false
  spaceRightButtonProcessByRIME: true
  keyValueOfSpaceRightButton: "."
  # 启用中英切换按键
  displayChineseEnglishSwitchButton: false
  # 按键位于空格左侧
  chineseEnglishSwitchButtonIsOnLeftOfSpaceButton: false
  # 启用数字九宫格键盘
  enableNineGridOfNumericKeyboard: true
  # (数字九宫格键盘)符号是否直接上屏
  enterDirectlyOnScreenByNineGridOfNumericKeyboard: true
  symbolsOfGridOfNumericKeyboard:
    - +
    - "-"
    - "*"
    - /
  lockShiftState: true
  enableEmbeddedInputMode: false
  widthOfOneHandedKeyboard: 80
  symbolsOfCursorBack:
    - '""'
    - "“”"
    - "[]"
  symbolsOfReturnToMainKeyboard:
    - ","
    - "。"
    - "!"
  symbolsOfChineseNineGridKeyboard:
    - ","
    - "。"
    - "?"
    - "!"
    - "…"
    - "~"
    - "'"
    - "、"
  pairsOfSymbols:
    - "[]"
    - ()
    - "“”"
  enableSymbolKeyboard: true
  lockForSymbolKeyboard: false

  # 是否启用空格加载文本
  enableLoadingTextForSpaceButton: true

  # 空格按钮加载文本
  loadingTextForSpaceButton: ""

  # 空格按钮长显文本
  labelTextForSpaceButton: ""

  # 空格按钮长显为当前输入方案
  # 当开启此选项后,labelForSpaceButton 设置的值无效
  showCurrentInputSchemaNameForSpaceButton: false

  # 空格按钮加载文字显示当前输入方案
  # 当开启此选项后, loadingTextForSpaceButton 设置的值无效
  showCurrentInputSchemaNameOnLoadingTextForSpaceButton: false

  # 是否启用配色方案
  enableColorSchema: false
  # 浅色模式下配色
  useColorSchemaForLight: ""
  # 暗色模式下配色
  useColorSchemaForDark: ""

  # 配色方案
  # 来源: https://github.com/rime/squirrel/blob/master/data/squirrel.yaml
  colorSchemas:
    - schemaName: darksys
      name: 暗色方案
      author: weearc
      back_color: "0x212121"
      button_back_color: "0x212121"
      button_pressed_back_color: "0x545454"
      button_front_color: "0xBDBDBD"
      button_pressed_front_color: "0xBDBDBD"
      button_swipe_front_color: "0xBDBDBD"
      corner_radius: 0.01
      border_color: "0x21212100"
      text_color: "0xBDBDBD"
      hilited_candidate_back_color: "0x545454"
      hilited_candidate_text_color: "0xBDBDBD"
      hilited_comment_text_color: "0xBDBDBD"
      candidate_text_color: "0xBDBDBD"
      comment_text_color: "0xBDBDBD"

# RIME 引擎相关配置
rime:
  maximumNumberOfCandidateWords: 100
  keyValueOfSwitchSimplifiedAndTraditional: simplified
  # RIME 重新部署时,是否覆盖词库文件
  # 如果使用自造词,需要改为 false, 否则部署时会覆盖键盘自造词文件
  overrideDictFiles: true
  # 覆盖词库文件的正则表达式
  # 使用场景:
  # 在开启 overrideDictFiles 后,每次重新部署会按照正则表达式符合的条件翻盖文件
  regexOnOverrideDictFiles:
    - "^.*[.]userdb.*$"
    - "^.*[.]txt$"
  # 拷贝键盘文件至应用沙盒目录的正则表达式,只会拷贝并覆盖符合表达式的文件。
  # 正则表达式为空时,则使用默认值 ["^.*[.]userdb.*$", "^.*[.]txt$"]
  # 使用场景:在文件管理功能中,拷贝键盘词库文件至应用
  regexOnCopyAppGroupDictFile:
    - "^.*[.]userdb.*$"
    - "^.*[.]txt$"

# 划动相关配置
swipe:
  # 指空格移动多个 point,光标移动一位。所以数字越小越灵敏
  spaceDragSensitivity: 5

  # 划动距离阈值,当划动的距离大于或等于此值时,才会识别为一次划动
  distanceThreshold: 20

  # 此值是正切角度的阈值,用来限制上下左右划动时的角度,如果太大容易误触
  # 默认为 15 度的正切值,即上下左右划的的角度不能超过 15 度
  # tan(10º) ≈ 0.176, tan(15º) ≈ 0.268, tan(30º) ≈ 0.577, tan(45º) = 1, tan(60º) ≈ 1.732
  tangentThreshold: 0.577
  # 长按延迟时间,只要大于或等于此阈值,才会触发长按 Action,如空格划动
  longPressDelay: 0.3
  keyboardSwipe:
    # 中文 26 键滑动设置
    - keyboardType: chinese
      keys:
        - action: character(a)
          swipe:
            - direction: up
              action: character(`)
              processByRIME: true
              display: true
            - direction: down
              action: character(~)
              processByRIME: true
              display: false
        - action: character(b)
          swipe:
            - direction: up
              action: symbol(《》)
            - direction: down
              action: character(。)
              display: false
        - action: character(c)
          swipe:
            - direction: up
              action: character(.)
            - direction: down
              action: character(>)
              display: false
        - action: character(d)
          swipe:
            - direction: up
              action: character(=)
            - direction: down
              action: character(+)
              display: false
        - action: character(e)
          swipe:
            - direction: up
              action: character(3)
            # - direction: down
            #   action: character(#)
            #   display: false
            - direction: down
              action: keyboardType(alphabetic)
              display: false
        - action: character(f)
          swipe:
            - direction: up
              action: character([)
            - direction: down
              action: character({)
              display: false
        - action: character(g)
          swipe:
            - direction: up
              action: character(])
            - direction: down
              action: character(})
              display: false
        - action: character(h)
          swipe:
            - direction: up
              action: character(\)
            - direction: down
              action: character(|)
              display: false
        - action: character(i)
          swipe:
            - direction: up
              action: character(8)
            - direction: down
              action: character(*)
              display: false
        - action: character(j)
          swipe:
            - direction: up
              action: character(/)
            - direction: down
              action: character(?)
              display: false
        - action: character(k)
          swipe:
            - direction: up
              action: character(;)
            - direction: down
              action: character(:)
              display: false
        - action: character(l)
          swipe:
            - direction: up
              action: character(')
            - direction: down
              action: character(")
              display: false
        - action: character(m)
          swipe:
            - direction: up
              action: shortCommand(#行尾)
            - direction: down
              action: character(、)
              display: false
        - action: character(n)
          swipe:
            - direction: up
              action: symbol(『』)
            - direction: down
              action: character(、)
              display: false
        - action: character(o)
          swipe:
            - direction: up
              action: character(9)
            - direction: down
              action: character(()
              display: false
        - action: character(p)
          swipe:
            - direction: up
              action: character(0)
            - direction: down
              action: character())
              display: false
        - action: character(q)
          swipe:
            - direction: up
              action: character(1)
            - direction: down
              action: character(!)
              display: false
        - action: character(r)
          swipe:
            - direction: up
              action: character(4)
            - direction: down
              action: character($)
              display: false
        - action: character(s)
          swipe:
            - direction: up
              action: character(-)
            - direction: down
              action: character(_)
              display: false
        - action: character(t)
          swipe:
            - direction: up
              action: character(5)
            - direction: down
              action: character(%)
              display: false
        - action: character(u)
          swipe:
            - direction: up
              action: character(7)
            - direction: down
              action: character(&)
              display: false
        - action: character(v)
          swipe:
            - direction: up
              action: symbol(“”)
            - direction: down
              action: character(,)
              display: false
        - action: character(w)
          swipe:
            - direction: up
              action: character(2)
            - direction: down
              action: character(@)
              display: false
        - action: character(x)
          swipe:
            - direction: up
              action: character(,)
            - direction: down
              action: character(<)
              display: false
        - action: character(y)
          swipe:
            - direction: up
              action: character(6)
            - direction: down
              action: character(^)
              display: false
        - action: character(z)
          swipe:
            - direction: up
              action: shortCommand(#行首)
            - direction: down
              action: symbol(‘’)
              display: false
        - action: space
          swipe:
            - direction: up
              action: shortCommand(#次选上屏)
              display: false
        - action: enter
          swipe:
            - direction: up
              action: shortCommand(#换行)
              display: false
        - action: backspace
          swipe:
            - direction: up
              action: shortCommand(#重输)
              display: false
        - action: keyboardType(numericNineGrid)
          swipe:
            - direction: up
              action: shortCommand(#上个输入方案)
              display: false
    # 中文九宫格滑动设置
    - keyboardType: chineseNineGrid
      keys:
        - action: chineseNineGrid(@/.)
          swipe:
            - direction: up
              action: character(1)
              display: true
        - action: chineseNineGrid(ABC)
          swipe:
            - direction: up
              action: character(2)
              display: true
        - action: chineseNineGrid(DEF)
          swipe:
            - direction: up
              action: character(3)
              display: true
        - action: chineseNineGrid(GHI)
          swipe:
            - direction: up
              action: character(4)
              display: true
        - action: chineseNineGrid(JKL)
          swipe:
            - direction: up
              action: character(5)
              display: true
        - action: chineseNineGrid(MNO)
          swipe:
            - direction: up
              action: character(6)
              display: true
        - action: chineseNineGrid(PQRS)
          swipe:
            - direction: up
              action: character(7)
              display: true
        - action: chineseNineGrid(TUV)
          swipe:
            - direction: up
              action: character(8)
              display: true
        - action: chineseNineGrid(WXYZ)
          swipe:
            - direction: up
              action: character(9)
              display: true
# 自定义键盘布局
# 布局文档说明文档:https://github.com/imfuxiao/Hamster/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E9%94%AE%E7%9B%98%E5%B8%83%E5%B1%80
keyboards:
  - name: ZH
    rows:
      - keys:
          - action: character(q)
            width: percentage(0.1)
          - action: character(w)
            width: percentage(0.1)
          - action: character(e)
            width: percentage(0.1)
          - action: character(r)
            width: percentage(0.1)
          - action: character(t)
            width: percentage(0.1)
          - action: character(y)
            width: percentage(0.1)
          - action: character(u)
            width: percentage(0.1)
          - action: character(i)
            width: percentage(0.1)
          - action: character(o)
            width: percentage(0.1)
          - action: character(p)
            width: percentage(0.1)
      - keys:
          - action: none
            width: available
          - action: character(a)
            width: percentage(0.1)
          - action: character(s)
            width: percentage(0.1)
          - action: character(d)
            width: percentage(0.1)
          - action: character(f)
            width: percentage(0.1)
          - action: character(g)
            width: percentage(0.1)
          - action: character(h)
            width: percentage(0.1)
          - action: character(j)
            width: percentage(0.1)
          - action: character(k)
            width: percentage(0.1)
          - action: character(l)
            width: percentage(0.1)
          - action: none
            width: available
      - keys:
          - action: shift
            width: percentage(0.13)
          - action: none
            width: available
          - action: character(z)
            width: percentage(0.1)
          - action: character(x)
            width: percentage(0.1)
          - action: character(c)
            width: percentage(0.1)
          - action: character(v)
            width: percentage(0.1)
          - action: character(b)
            width: percentage(0.1)
          - action: character(n)
            width: percentage(0.1)
          - action: character(m)
            width: percentage(0.1)
          - action: none
            width: available
          - action: backspace
            width: percentage(0.13)
      - keys:
          - action: keyboardType(numericNineGrid)
            width:
              portrait: percentage(0.15)
              landscape: percentage(0.2)
          - action: keyboardType(alphabetic)
            width:
              portrait: percentage(0.08)
              landscape: percentage(0.1)
          - action: character(,)
            width:
              portrait: percentage(0.09)
              landscape: percentage(0.1)
          - action: space
            width:
              portrait: available
              landscape: percentage(0.1)
          - action: character(。)
            width:
              portrait: percentage(0.09)
              landscape: percentage(0.1)
          - action: enter
            width:
              portrait: percentage(0.14)
              landscape: percentage(0.1)
    buttonInsets: left(0),bottom(0),top(0),right(0)
  - name: EN
    rows:
      - keys:
          - action: character(q)
            width: percentage(0.1)
          - action: character(w)
            width: percentage(0.1)
          - action: character(e)
            width: percentage(0.1)
          - action: character(r)
            width: percentage(0.1)
          - action: character(t)
            width: percentage(0.1)
          - action: character(y)
            width: percentage(0.1)
          - action: character(u)
            width: percentage(0.1)
          - action: character(i)
            width: percentage(0.1)
          - action: character(o)
            width: percentage(0.1)
          - action: character(p)
            width: percentage(0.1)
      - keys:
          - action: none
            width: available
          - action: character(a)
            width: percentage(0.1)
          - action: character(s)
            width: percentage(0.1)
          - action: character(d)
            width: percentage(0.1)
          - action: character(f)
            width: percentage(0.1)
          - action: character(g)
            width: percentage(0.1)
          - action: character(h)
            width: percentage(0.1)
          - action: character(j)
            width: percentage(0.1)
          - action: character(k)
            width: percentage(0.1)
          - action: character(l)
            width: percentage(0.1)
          - action: none
            width: available
      - keys:
          - action: shift
            width: percentage(0.13)
          - action: none
            width: available
          - action: character(z)
            width: percentage(0.1)
          - action: character(x)
            width: percentage(0.1)
          - action: character(c)
            width: percentage(0.1)
          - action: character(v)
            width: percentage(0.1)
          - action: character(b)
            width: percentage(0.1)
          - action: character(n)
            width: percentage(0.1)
          - action: character(m)
            width: percentage(0.1)
          - action: none
            width: available
          - action: backspace
            width: percentage(0.13)
      - keys:
          - action: keyboardType(numericNineGrid)
            width:
              portrait: percentage(0.15)
              landscape: percentage(0.2)
          - action: keyboardType(custom(ZH))
            width:
              portrait: percentage(0.08)
              landscape: percentage(0.1)
          - action: character(,)
            width:
              portrait: percentage(0.09)
              landscape: percentage(0.1)
          - action: space
            width:
              portrait: available
              landscape: percentage(0.4)
          - action: character(.)
            width:
              portrait: percentage(0.09)
              landscape: percentage(0.1)
          - action: enter
            width:
              portrait: percentage(0.14)
              landscape: percentage(0.2)
    buttonInsets: left(0),bottom(0),top(0),right(0)
weearc commented 1 year ago

看了一下如果简单的用如下方式绑定到按键实现语言切换:

- action: shortCommand(#中英切换)
  label: "🖇"

的确可以用 ascii_mode 切换语言,但是此时要是 label 不绑定任何值则该按键显示为空(不显示为当前status),要是使用 keyboardType 的话:

- action: keyboardType(alphabetic) # 可以切换到英文键盘,但是布局为默认英文键盘
- action: keyboardType(EN) # EN 为自己定义的西文键盘布局,但当前状态没变(中文仍为中文,英文仍为英文)
weearc commented 1 year ago

看了一下相关issue,需求应该类似于 #367 ,因为目前如果在布局文件中给一个按键定义两个 action 的话后一个必定覆盖前一个,但是这个确实也不应该通过多action来做,因此还是需要label显示绑定状态

weearc commented 1 year ago

目前一个变通方法是切换到另一个布局(假定为西文输入)时所有字母按键配置 processByRIME: false,可暂时性达到目的。 附键盘布局:

keyboards:
  - name: ZH
    rows:
      - keys:
          - action: character(q)
            width: percentage(0.1)
          - action: character(w)
            width: percentage(0.1)
          - action: character(e)
            width: percentage(0.1)
          - action: character(r)
            width: percentage(0.1)
          - action: character(t)
            width: percentage(0.1)
          - action: character(y)
            width: percentage(0.1)
          - action: character(u)
            width: percentage(0.1)
          - action: character(i)
            width: percentage(0.1)
          - action: character(o)
            width: percentage(0.1)
          - action: character(p)
            width: percentage(0.1)
      - keys:
          - action: none
            width: available
          - action: character(a)
            width: percentage(0.1)
          - action: character(s)
            width: percentage(0.1)
          - action: character(d)
            width: percentage(0.1)
          - action: character(f)
            width: percentage(0.1)
          - action: character(g)
            width: percentage(0.1)
          - action: character(h)
            width: percentage(0.1)
          - action: character(j)
            width: percentage(0.1)
          - action: character(k)
            width: percentage(0.1)
          - action: character(l)
            width: percentage(0.1)
          - action: none
            width: available
      - keys:
          - action: shift
            width: percentage(0.13)
          - action: none
            width: available
          - action: character(z)
            width: percentage(0.1)
          - action: character(x)
            width: percentage(0.1)
          - action: character(c)
            width: percentage(0.1)
          - action: character(v)
            width: percentage(0.1)
          - action: character(b)
            width: percentage(0.1)
          - action: character(n)
            width: percentage(0.1)
          - action: character(m)
            width: percentage(0.1)
          - action: none
            width: available
          - action: backspace
            width: percentage(0.13)
      - keys:
          - action: keyboardType(numericNineGrid)
            width:
              portrait: percentage(0.15)
              landscape: percentage(0.2)
          - action: keyboardType(custom(EN))
            label: ""
            width:
              portrait: percentage(0.08)
              landscape: percentage(0.1)
          - action: character(,)
            width:
              portrait: percentage(0.09)
              landscape: percentage(0.1)
          - action: space
            label: "Clover"
            width: available
          - action: character(。)
            width:
              portrait: percentage(0.09)
              landscape: percentage(0.1)
          - action: enter
            width:
              portrait: percentage(0.14)
              landscape: percentage(0.1)
    buttonInsets: left(0),bottom(0),top(0),right(0)
  - name: EN
    rows:
      - keys:
          - action: character(q)
            processByRIME: false
            width: percentage(0.1)
          - action: character(w)
            processByRIME: false
            width: percentage(0.1)
          - action: character(e)
            processByRIME: false
            width: percentage(0.1)
          - action: character(r)
            processByRIME: false
            width: percentage(0.1)
          - action: character(t)
            processByRIME: false
            width: percentage(0.1)
          - action: character(y)
            processByRIME: false
            width: percentage(0.1)
          - action: character(u)
            processByRIME: false
            width: percentage(0.1)
          - action: character(i)
            processByRIME: false
            width: percentage(0.1)
          - action: character(o)
            processByRIME: false
            width: percentage(0.1)
          - action: character(p)
            processByRIME: false
            width: percentage(0.1)
      - keys:
          - action: none
            width: available
          - action: character(a)
            processByRIME: false
            width: percentage(0.1)
          - action: character(s)
            processByRIME: false
            width: percentage(0.1)
          - action: character(d)
            processByRIME: false
            width: percentage(0.1)
          - action: character(f)
            processByRIME: false
            width: percentage(0.1)
          - action: character(g)
            processByRIME: false
            width: percentage(0.1)
          - action: character(h)
            processByRIME: false
            width: percentage(0.1)
          - action: character(j)
            processByRIME: false
            width: percentage(0.1)
          - action: character(k)
            processByRIME: false
            width: percentage(0.1)
          - action: character(l)
            processByRIME: false
            width: percentage(0.1)
          - action: none
            width: available
      - keys:
          - action: shift
            width: percentage(0.13)
          - action: none
            width: available
          - action: character(z)
            processByRIME: false
            width: percentage(0.1)
          - action: character(x)
            processByRIME: false
            width: percentage(0.1)
          - action: character(c)
            processByRIME: false
            width: percentage(0.1)
          - action: character(v)
            processByRIME: false
            width: percentage(0.1)
          - action: character(b)
            processByRIME: false
            width: percentage(0.1)
          - action: character(n)
            processByRIME: false
            width: percentage(0.1)
          - action: character(m)
            processByRIME: false
            width: percentage(0.1)
          - action: none
            width: available
          - action: backspace
            width: percentage(0.13)
      - keys:
          - action: keyboardType(numericNineGrid)
            width:
              portrait: percentage(0.15)
              landscape: percentage(0.2)
          - action: keyboardType(custom(ZH))
            label: "EN"
            width:
              portrait: percentage(0.08)
              landscape: percentage(0.1)
          - action: character(,)
            width:
              portrait: percentage(0.09)
              landscape: percentage(0.1)
          - action: space
            label: "Clover"
            width: available
          - action: character(.)
            width:
              portrait: percentage(0.09)
              landscape: percentage(0.1)
          - action: enter
            width:
              portrait: percentage(0.14)
              landscape: percentage(0.1)
    buttonInsets: left(0),bottom(0),top(0),right(0)

另:大写按键在使用自定义布局时,在未双击锁定状态下,输入第二个字符后不会回到关闭状态。

Sevenyine commented 12 months ago

遇到了同样的问题(中英文切换按钮在空格左右横跳) 同时这个中英的按钮似乎贴图拉伸有点问题,现在是一个长方形 之前是正方形 看着很难看 image

weearc commented 11 months ago

确认到更新后问题已经修复,关闭此issue