Skip to content

Commit

Permalink
Fix: Alignment of modifier keys when align option is 'CENTER' or 'RIG…
Browse files Browse the repository at this point in the history
…HT' (#107)
  • Loading branch information
nutti committed Jun 12, 2022
1 parent 6655e66 commit 86652b8
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/screencast_keys/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,11 +882,15 @@ def _calc_draw_area_size_mouse_and_hold_modifier_keys_layer(cls, context, font_i
mouse_width = prefs.mouse_size
mouse_height = prefs.mouse_size * cls.HEIGHT_RATIO_FOR_MOUSE_HOLD_STATUS
if cls.hold_modifier_keys:
if show_mouse_hold_status(prefs) and cls.hold_modifier_keys:
separator_width = mouse_width * cls.WIDTH_RATIO_FOR_SEPARATOR_BETWEEN_MOUSE_AND_MODIFIER_KEYS + prefs.margin
hold_modifier_keys_width = cls.calc_draw_text_area_width(modifier_keys_text, font_id) + modifier_keys_box_margin * 2
hold_modifier_keys_height = cls.calc_draw_text_area_height(font_id) + modifier_keys_box_margin * 2

if prefs.align == 'CENTER':
hold_modifier_keys_width = max(hold_modifier_keys_width, prefs.font_size * 8)
separator_width = mouse_width * cls.WIDTH_RATIO_FOR_SEPARATOR_BETWEEN_MOUSE_AND_MODIFIER_KEYS + prefs.margin
if show_mouse_hold_status(prefs) and cls.hold_modifier_keys:
separator_width = mouse_width * cls.WIDTH_RATIO_FOR_SEPARATOR_BETWEEN_MOUSE_AND_MODIFIER_KEYS + prefs.margin

layer_width = mouse_width + separator_width + hold_modifier_keys_width + prefs.margin * 2
layer_height = max(mouse_height, hold_modifier_keys_height) + prefs.margin * 2

Expand Down Expand Up @@ -1158,15 +1162,23 @@ def _draw_mouse_and_hold_modifier_keys_layer(cls, context, font_id, x, y):
mouse_width = mouse_icon_width
mouse_height = mouse_icon_height
if cls.hold_modifier_keys:
if show_mouse_hold_status(prefs) and cls.hold_modifier_keys:
separator_width = mouse_width * cls.WIDTH_RATIO_FOR_SEPARATOR_BETWEEN_MOUSE_AND_MODIFIER_KEYS + prefs.margin
hold_modifier_keys_start_x = x + mouse_icon_width + separator_width
hold_modifier_keys_start_x = x
hold_modifier_keys_start_y = y
hold_modifier_keys_text_width = cls.calc_draw_text_area_width(modifier_keys_text, font_id) + modifier_keys_box_margin * 2
hold_modifier_keys_text_height = cls.calc_draw_text_area_height(font_id) + modifier_keys_box_margin * 2
hold_modifier_keys_width = hold_modifier_keys_text_width
hold_modifier_keys_height = hold_modifier_keys_text_height

if prefs.align == 'CENTER':
hold_modifier_keys_width = max(hold_modifier_keys_width, prefs.font_size * 8)
separator_width = mouse_width * cls.WIDTH_RATIO_FOR_SEPARATOR_BETWEEN_MOUSE_AND_MODIFIER_KEYS + prefs.margin
if show_mouse_hold_status(prefs) and cls.hold_modifier_keys:
separator_width = mouse_width * cls.WIDTH_RATIO_FOR_SEPARATOR_BETWEEN_MOUSE_AND_MODIFIER_KEYS + prefs.margin
if prefs.align == 'RIGHT':
mouse_start_x += hold_modifier_keys_width + separator_width
elif prefs.align == 'LEFT' or prefs.align == 'CENTER':
hold_modifier_keys_start_x += mouse_icon_width + separator_width

layer_width = mouse_width + separator_width + hold_modifier_keys_width + prefs.margin * 2
layer_height = max(mouse_height, hold_modifier_keys_height) + prefs.margin * 2

Expand Down

0 comments on commit 86652b8

Please sign in to comment.