From 3feaa65857f5fdc5b024498765dbc4aaae9464f7 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Fri, 28 Jun 2024 15:31:34 -0700 Subject: [PATCH] feat: Add hidden property to ComboSpec Fixes #104 --- KEYMAP_SPEC.md | 3 ++- keymap_drawer/draw/combo.py | 7 ++++--- keymap_drawer/keymap.py | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/KEYMAP_SPEC.md b/KEYMAP_SPEC.md index 03815cd..d9308ef 100644 --- a/KEYMAP_SPEC.md +++ b/KEYMAP_SPEC.md @@ -178,8 +178,9 @@ This is an optional field that contains a list of `ComboSpec`s, each of which is | `height (h)` | `float` | `null` | the height of the combo box (in pixels), defaults to `draw_config.combo_h` if null | | `rotation (r)` | `float` | `0.0` | the rotation of the combo box in degrees -- only applies to the box itself and not any dendrons | | `draw_separate` | `null \| bool` | `null` | whether to draw the combo separate from layers, using a dedicated diagram. defaults to `draw_config.separate_combo_diagrams` if null | +| `hidden` | `bool` | `false` | do not draw this combo at all -- useful when you have the combo in the parse output but you want to ignore it through your config | -All fields except `key_positions`, `key` and `type` are ignored when combo is drawn in a separate diagram using `draw_separate` or `draw_config.separate_combo_diagrams`. +All fields except `key_positions`, `key`, `type` and `hidden` are ignored when combo is drawn in a separate diagram using `draw_separate` or `draw_config.separate_combo_diagrams`. [^5]: Key indices start from `0` on the first key position and increase by columns and then rows, corresponding to their ordering in the `layers` field. This matches the `key-positions` property in ZMK combo definitions. [^6]: Just like for keys in a layer under the `layers` field, `key` field can be specified with a string value as a shortcut, or a mapping (where the `type` field will be ignored). diff --git a/keymap_drawer/draw/combo.py b/keymap_drawer/draw/combo.py index 22de16a..9aa5def 100644 --- a/keymap_drawer/draw/combo.py +++ b/keymap_drawer/draw/combo.py @@ -170,9 +170,7 @@ def print_combos_for_layer(self, combos: Sequence[ComboSpec]) -> tuple[float | N Print SVG for all given combos, relative to that point. Return min and max y-coordinates of combo boxes, for bounding box calculations. """ - combo_pts = [] - for combo_ind, combo_spec in enumerate(combos): - combo_pts.append(self.print_combo(combo_spec, combo_ind)) + combo_pts = [self.print_combo(combo, ind) for ind, combo in enumerate(combos) if not combo.hidden] return min((p.y for p, _ in combo_pts), default=None), max((p.y for _, p in combo_pts), default=None) def create_combo_diagrams( @@ -194,6 +192,9 @@ def create_combo_diagrams( layers = {} for ind, combo in enumerate(combos): + if combo.hidden: + continue + empty_layer = [LayoutKey() for _ in range(len(self.layout))] if ghost_keys: for key_position in ghost_keys: diff --git a/keymap_drawer/keymap.py b/keymap_drawer/keymap.py index 46373db..3f4bcc1 100644 --- a/keymap_drawer/keymap.py +++ b/keymap_drawer/keymap.py @@ -79,6 +79,7 @@ class ComboSpec(BaseModel, populate_by_name=True, extra="forbid"): height: float | None = Field(alias="h", default=None) rotation: float = Field(alias="r", default=0.0) draw_separate: bool | None = None + hidden: bool = False @classmethod def normalize_fields(cls, spec_dict: dict) -> dict: