Skip to content

Commit

Permalink
feat: Add per-combo width/height
Browse files Browse the repository at this point in the history
  • Loading branch information
caksoylar committed Oct 20, 2023
1 parent f0e1fd4 commit 91fe5ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 4 additions & 5 deletions keymap_drawer/draw/combo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def print_combo(self, combo: ComboSpec, combo_ind: int) -> None:
specified, along with whether dendrons are drawn going to each key position from the combo.
"""
p_keys = [self.layout.keys[p] for p in combo.key_positions]
width, height = combo.width or self.cfg.combo_w, combo.height or self.cfg.combo_h

# find center of combo box
p_mid = (1 / len(p_keys)) * sum((k.pos for k in p_keys), start=Point(0, 0))
Expand Down Expand Up @@ -114,17 +115,15 @@ def print_combo(self, combo: ComboSpec, combo_ind: int) -> None:
for k in p_keys:
offset = (
k.height / 5
if abs((k.pos - p).x) < self.cfg.combo_w / 2
and abs((k.pos - p).y) <= k.height / 3 + self.cfg.combo_h / 2
if abs((k.pos - p).x) < width / 2 and abs((k.pos - p).y) <= k.height / 3 + height / 2
else k.height / 3
)
self._draw_arc_dendron(p, k.pos, True, offset, combo.arc_scale)
case "left" | "right":
for k in p_keys:
offset = (
k.width / 5
if abs((k.pos - p).y) < self.cfg.combo_h / 2
and abs((k.pos - p).x) <= k.width / 3 + self.cfg.combo_w / 2
if abs((k.pos - p).y) < height / 2 and abs((k.pos - p).x) <= k.width / 3 + width / 2
else k.width / 3
)
self._draw_arc_dendron(p, k.pos, False, offset, combo.arc_scale)
Expand All @@ -136,7 +135,7 @@ def print_combo(self, combo: ComboSpec, combo_ind: int) -> None:
# draw combo box with text
self._draw_rect(
p,
Point(self.cfg.combo_w, self.cfg.combo_h),
Point(width, height),
Point(self.cfg.key_rx, self.cfg.key_ry),
classes=["combo", combo.type],
)
Expand Down
2 changes: 2 additions & 0 deletions keymap_drawer/keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class ComboSpec(BaseModel, allow_population_by_field_name=True):
slide: float | None = Field(alias="s", default=None)
arc_scale: float = 1.0
type: str = ""
width: float | None = Field(alias="w", default=None)
height: float | None = Field(alias="h", default=None)

@classmethod
def normalize_fields(cls, spec_dict: dict) -> dict:
Expand Down

0 comments on commit 91fe5ec

Please sign in to comment.