Skip to content

Commit

Permalink
feat: Add hidden property to ComboSpec
Browse files Browse the repository at this point in the history
Fixes #104
  • Loading branch information
caksoylar committed Jun 28, 2024
1 parent 809873a commit 3feaa65
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion KEYMAP_SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 4 additions & 3 deletions keymap_drawer/draw/combo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions keymap_drawer/keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3feaa65

Please sign in to comment.