add new groupId -1 for suppressing default popups e.g. on action or comma keys

fixes #1243
This commit is contained in:
Helium314 2025-01-12 21:04:32 +01:00
parent 7e3657185f
commit 465fc86e61
2 changed files with 9 additions and 4 deletions

View file

@ -56,11 +56,10 @@ sealed interface KeyData : AbstractKeyData {
fun copy(newType: KeyType? = type, newCode: Int = code, newLabel: String = label, newGroupId: Int = groupId,
newPopup: PopupSet<out AbstractKeyData> = popup, newWidth: Float = width, newLabelFlags: Int = labelFlags): KeyData
// groups (currently) not supported
companion object {
/**
* Constant for the default group. If not otherwise specified, any key is automatically
* assigned to this group.
* assigned to this group. Additional popup keys will be added for specific labels.
*/
const val GROUP_DEFAULT: Int = 0
@ -82,6 +81,11 @@ sealed interface KeyData : AbstractKeyData {
*/
const val GROUP_ENTER: Int = 3
/**
* Constant for the default key, but without assigning popups for special labels.
*/
const val GROUP_NO_DEFAULT_POPUP: Int = -1
/**
* Constant for the enter modifier key group. Any key belonging to this group will get the
* popups specified for "~kana" in the popup mapping.
@ -335,7 +339,7 @@ sealed interface KeyData : AbstractKeyData {
}
override fun compute(params: KeyboardParams): KeyData? {
require(groupId in 0..GROUP_ENTER) { "only positive groupIds up to GROUP_ENTER are supported" }
require(groupId in GROUP_NO_DEFAULT_POPUP..GROUP_ENTER) { "only groupIds from -1 to 3 are supported" }
require(label.isNotEmpty() || type == KeyType.PLACEHOLDER || code != KeyCode.UNSPECIFIED) { "non-placeholder key has no code and no label" }
require(width >= 0f || width == -1f) { "illegal width $width" }
val newLabel = label.convertFlorisLabel().resolveStringLabel(params)
@ -541,6 +545,7 @@ sealed interface KeyData : AbstractKeyData {
if (groupId == GROUP_COMMA) return SimplePopups(getCommaPopupKeys(params))
if (groupId == GROUP_PERIOD) return SimplePopups(getPunctuationPopupKeys(params))
if (groupId == GROUP_ENTER) return getActionKeyPopupKeys(params)
if (groupId == GROUP_NO_DEFAULT_POPUP) return null
return when (label) {
KeyLabel.COMMA -> SimplePopups(getCommaPopupKeys(params))
KeyLabel.PERIOD -> SimplePopups(getPunctuationPopupKeys(params))

View file

@ -58,7 +58,7 @@ If the layout has exactly 2 keys in the bottom row, these keys will replace comm
* `codePoints`: when multiple code points should be entered, only available for `multi_text_key`
* `label`: text to display on the key, determined from code if empty
* There are some special values, see the [label section](#labels)
* `groupId`: which additional popup keys to show, `0` is default and does not add anything, `1` adds the comma popup keys, `2` adds the period popup keys, `3` adds the action key popup keys (looks awkward though)
* `groupId`: which additional popup keys to show, `0` is default and does not add anything, `1` adds the comma popup keys, `2` adds the period popup keys, `3` adds the action key popup keys (looks awkward though), `-1` suppresses additional popups based on the label
* `popup`: list of keys to add in the popup, e.g. `"label": ")", "popup": {"relevant": [{ "label": "." }]}` is a `)` key with a `.` popup
* Note that in popup keys, properties are ignored with the exception of `$`, `code`, `codePoints`, and `label`
* When specifying a _selector_ key class in a popup key, it will be evaluated correctly (e.g. for changing popups dependent on shift state)