Skip to content

Commit 55c7575

Browse files
committed
feat!: Make arc_scale a combo field
1 parent 87f7b7b commit 55c7575

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

KEYMAP_SPEC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ This is an optional field that contains a list of combo specs, each of which is
133133
| `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 |
134134
| `dendron` (`d`) | `null \| bool` | `null` | whether to draw dendrons going from combo to triggering key coordinates, default is to draw for non-`mid` alignments and draw for `mid` if key coordinates are far from the combo |
135135
| `slide` (`s`) | `null \| float (-1 <= val <= 1)` | `null` | slide the combo box along an axis between keys -- can be used for moving `top`/`bottom` combo boxes left/right, `left`/`right` boxes up/down, or `mid` combos between two keys |
136+
| `arc_scale` | `float` | `1.0` | scale the arcs going left/right for `top`/`bottom` or up/down for `left`/`right` aligned combos |
136137
| `type` | `str` | `"combo"` | the styling of the key that corresponds to the [SVG class](keymap_drawer/config.py#L51), see `LayoutKey` definition above |
137138

138139
[^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.

keymap_drawer/config.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ class DrawConfig(BaseSettings, env_prefix="KEYMAP_", extra="ignore"):
3939
# curve radius for combo dendrons
4040
arc_radius: float = 6
4141

42-
# length multiplier for dendrons
43-
arc_scale: float = 1.0
44-
4542
# whether to add a colon after layer name while printing the layer header
4643
append_colon_to_layer_header: bool = True
4744

keymap_drawer/draw.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ def _draw_glyph(self, p: Point, name: str, legend_type: LegendType, classes: Seq
7575
f'height="{height}" width="{width}"{self._to_class_str(classes)}/>\n'
7676
)
7777

78-
def _draw_arc_dendron(self, p_1: Point, p_2: Point, x_first: bool, shorten: float) -> None:
78+
def _draw_arc_dendron( # pylint: disable=too-many-arguments
79+
self, p_1: Point, p_2: Point, x_first: bool, shorten: float, arc_scale: float
80+
) -> None:
7981
diff = p_2 - p_1
82+
83+
# check if the points are too close to draw an arc, if so draw a line instead
8084
if (x_first and abs(diff.x) < self.cfg.arc_radius) or (not x_first and abs(diff.y) < self.cfg.arc_radius):
8185
self._draw_line_dendron(p_1, p_2, shorten)
8286
return
@@ -86,11 +90,11 @@ def _draw_arc_dendron(self, p_1: Point, p_2: Point, x_first: bool, shorten: floa
8690
arc_y = copysign(self.cfg.arc_radius, diff.y)
8791
clockwise = (diff.x > 0) ^ (diff.y > 0)
8892
if x_first:
89-
line_1 = f"h{self.cfg.arc_scale * diff.x - arc_x}"
93+
line_1 = f"h{arc_scale * diff.x - arc_x}"
9094
line_2 = f"v{diff.y - arc_y - copysign(shorten, diff.y)}"
9195
clockwise = not clockwise
9296
else:
93-
line_1 = f"v{self.cfg.arc_scale * diff.y - arc_y}"
97+
line_1 = f"v{arc_scale * diff.y - arc_y}"
9498
line_2 = f"h{diff.x - arc_x - copysign(shorten, diff.x)}"
9599
arc = f"a{self.cfg.arc_radius},{self.cfg.arc_radius} 0 0 {int(clockwise)} {arc_x},{arc_y}"
96100
self.out.write(f'<path d="{start} {line_1} {arc} {line_2}" class="combo"/>\n')
@@ -225,11 +229,11 @@ def print_combo(self, p_0: Point, combo: ComboSpec) -> None:
225229
case "top" | "bottom":
226230
for k in p_keys:
227231
offset = k.height / 5 if abs(p_0.x + k.pos.x - p.x) < self.cfg.combo_w / 2 else k.height / 3
228-
self._draw_arc_dendron(p, p_0 + k.pos, True, offset)
232+
self._draw_arc_dendron(p, p_0 + k.pos, True, offset, combo.arc_scale)
229233
case "left" | "right":
230234
for k in p_keys:
231235
offset = k.width / 5 if abs(p_0.y + k.pos.y - p.y) < self.cfg.combo_h / 2 else k.width / 3
232-
self._draw_arc_dendron(p, p_0 + k.pos, False, offset)
236+
self._draw_arc_dendron(p, p_0 + k.pos, False, offset, combo.arc_scale)
233237
case "mid":
234238
for k in p_keys:
235239
if combo.dendron is True or abs(p_0 + k.pos - p) >= k.width - 1:

keymap_drawer/keymap.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ComboSpec(BaseModel, allow_population_by_field_name=True):
5858
offset: float = Field(alias="o", default=0.0)
5959
dendron: bool | None = Field(alias="d", default=None)
6060
slide: float | None = Field(alias="s", default=None)
61+
arc_scale: float = 1.0
6162
type: str = "combo"
6263

6364
@classmethod

0 commit comments

Comments
 (0)