Skip to content

Commit

Permalink
feat: Also use key.type for combo CSS class (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
englmaxi authored Feb 27, 2024
1 parent aac8bb2 commit 6defcaf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion KEYMAP_SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ This is an optional field that contains a list of `ComboSpec`s, each of which is
| field name (alias) | type | default value | description |
| ------------------- | ------------------------------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `key_positions (p)` | `list[int]` | required | list of key indices that trigger the combo[^4] |
| `key (k)` | `LayoutKey`[^5] | required | key produced by the combo when triggered, `type` field will be ignored |
| `key (k)` | `LayoutKey`[^5] | required | key produced by the combo when triggered, `LayoutKey`'s `type` field will be combined with the type field of `ComboSpec` |
| `layers (l)` | `list[str]` | `[]`[^6] | list of layers the combo can trigger on, specified using layer names in `layers` field |
| `align (a)` | `"mid" \| "top" \| "bottom" \| "left" \| "right"` | `"mid"` | where to draw the combo: `mid` draws on the mid-point of triggering keys' center coordinates, or to the `top`/`bottom`/`left`/`right` of the triggering keys |
| `offset (o)` | `float` | `0.0` | additional offset to `top`/`bottom`/`left`/`right` positioning, specified in units of key width/height: useful for combos that would otherwise overlap |
Expand Down
13 changes: 8 additions & 5 deletions keymap_drawer/draw/combo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module containing class and methods to draw combo representations."""

from io import StringIO
from math import copysign
from typing import Sequence
Expand Down Expand Up @@ -99,7 +100,7 @@ def print_combo(self, combo: ComboSpec, combo_ind: int) -> Point:
p_mid.y,
)

class_str = self._to_class_str(["combo", combo.type, f"combopos-{combo_ind}"])
class_str = self._to_class_str(["combo", combo.type, combo.key.type, f"combopos-{combo_ind}"])
self.out.write(f"<g{class_str}>\n")

# draw dendrons going from box to combo keys
Expand Down Expand Up @@ -133,20 +134,22 @@ def print_combo(self, combo: ComboSpec, combo_ind: int) -> Point:
p,
Point(width, height),
Point(self.cfg.key_rx, self.cfg.key_ry),
classes=["combo", combo.type],
classes=["combo", combo.type, combo.key.type],
)

self._draw_legend(p, self._split_text(combo.key.tap), classes=["combo", combo.type], legend_type="tap")
self._draw_legend(
p, self._split_text(combo.key.tap), classes=["combo", combo.type, combo.key.type], legend_type="tap"
)
self._draw_legend(
p + Point(0, self.cfg.combo_h / 2 - self.cfg.small_pad),
[combo.key.hold],
classes=["combo", combo.type],
classes=["combo", combo.type, combo.key.type],
legend_type="hold",
)
self._draw_legend(
p - Point(0, self.cfg.combo_h / 2 - self.cfg.small_pad),
[combo.key.shifted],
classes=["combo", combo.type],
classes=["combo", combo.type, combo.key.type],
legend_type="shifted",
)
if combo.rotation != 0.0:
Expand Down
1 change: 1 addition & 0 deletions keymap_drawer/keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Module with classes that define the keymap representation, with multiple layers
containing key and combo specifications, paired with the physical keyboard layout.
"""

from collections import defaultdict
from functools import partial
from itertools import chain
Expand Down
1 change: 1 addition & 0 deletions streamlit/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Redirect users to the canonical URL pointing to the new app."""

import streamlit as st

APP_URL = "https://caksoylar.github.io/keymap-drawer"
Expand Down

0 comments on commit 6defcaf

Please sign in to comment.