Skip to content

Commit

Permalink
feat!: Make arc_scale a combo field
Browse files Browse the repository at this point in the history
  • Loading branch information
caksoylar committed Jul 10, 2023
1 parent 87f7b7b commit 55c7575
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions KEYMAP_SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ This is an optional field that contains a list of combo specs, each of which is
| `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 |
| `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 |
| `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 |
| `arc_scale` | `float` | `1.0` | scale the arcs going left/right for `top`/`bottom` or up/down for `left`/`right` aligned combos |
| `type` | `str` | `"combo"` | the styling of the key that corresponds to the [SVG class](keymap_drawer/config.py#L51), see `LayoutKey` definition above |

[^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.
Expand Down
3 changes: 0 additions & 3 deletions keymap_drawer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class DrawConfig(BaseSettings, env_prefix="KEYMAP_", extra="ignore"):
# curve radius for combo dendrons
arc_radius: float = 6

# length multiplier for dendrons
arc_scale: float = 1.0

# whether to add a colon after layer name while printing the layer header
append_colon_to_layer_header: bool = True

Expand Down
14 changes: 9 additions & 5 deletions keymap_drawer/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ def _draw_glyph(self, p: Point, name: str, legend_type: LegendType, classes: Seq
f'height="{height}" width="{width}"{self._to_class_str(classes)}/>\n'
)

def _draw_arc_dendron(self, p_1: Point, p_2: Point, x_first: bool, shorten: float) -> None:
def _draw_arc_dendron( # pylint: disable=too-many-arguments
self, p_1: Point, p_2: Point, x_first: bool, shorten: float, arc_scale: float
) -> None:
diff = p_2 - p_1

# check if the points are too close to draw an arc, if so draw a line instead
if (x_first and abs(diff.x) < self.cfg.arc_radius) or (not x_first and abs(diff.y) < self.cfg.arc_radius):
self._draw_line_dendron(p_1, p_2, shorten)
return
Expand All @@ -86,11 +90,11 @@ def _draw_arc_dendron(self, p_1: Point, p_2: Point, x_first: bool, shorten: floa
arc_y = copysign(self.cfg.arc_radius, diff.y)
clockwise = (diff.x > 0) ^ (diff.y > 0)
if x_first:
line_1 = f"h{self.cfg.arc_scale * diff.x - arc_x}"
line_1 = f"h{arc_scale * diff.x - arc_x}"
line_2 = f"v{diff.y - arc_y - copysign(shorten, diff.y)}"
clockwise = not clockwise
else:
line_1 = f"v{self.cfg.arc_scale * diff.y - arc_y}"
line_1 = f"v{arc_scale * diff.y - arc_y}"
line_2 = f"h{diff.x - arc_x - copysign(shorten, diff.x)}"
arc = f"a{self.cfg.arc_radius},{self.cfg.arc_radius} 0 0 {int(clockwise)} {arc_x},{arc_y}"
self.out.write(f'<path d="{start} {line_1} {arc} {line_2}" class="combo"/>\n')
Expand Down Expand Up @@ -225,11 +229,11 @@ def print_combo(self, p_0: Point, combo: ComboSpec) -> None:
case "top" | "bottom":
for k in p_keys:
offset = k.height / 5 if abs(p_0.x + k.pos.x - p.x) < self.cfg.combo_w / 2 else k.height / 3
self._draw_arc_dendron(p, p_0 + k.pos, True, offset)
self._draw_arc_dendron(p, p_0 + k.pos, True, offset, combo.arc_scale)
case "left" | "right":
for k in p_keys:
offset = k.width / 5 if abs(p_0.y + k.pos.y - p.y) < self.cfg.combo_h / 2 else k.width / 3
self._draw_arc_dendron(p, p_0 + k.pos, False, offset)
self._draw_arc_dendron(p, p_0 + k.pos, False, offset, combo.arc_scale)
case "mid":
for k in p_keys:
if combo.dendron is True or abs(p_0 + k.pos - p) >= k.width - 1:
Expand Down
1 change: 1 addition & 0 deletions keymap_drawer/keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ComboSpec(BaseModel, allow_population_by_field_name=True):
offset: float = Field(alias="o", default=0.0)
dendron: bool | None = Field(alias="d", default=None)
slide: float | None = Field(alias="s", default=None)
arc_scale: float = 1.0
type: str = "combo"

@classmethod
Expand Down

0 comments on commit 55c7575

Please sign in to comment.