qmk info: nicer rendering of ISO enter (#16466)

This commit is contained in:
Ryan 2022-03-06 09:54:32 +11:00 committed by GitHub
parent b202e59322
commit 8e9d45d270
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -162,13 +162,12 @@ def render_layout(layout_data, render_ascii, key_labels=None):
""" """
textpad = [array('u', ' ' * 200) for x in range(100)] textpad = [array('u', ' ' * 200) for x in range(100)]
style = 'ascii' if render_ascii else 'unicode' style = 'ascii' if render_ascii else 'unicode'
box_chars = BOX_DRAWING_CHARACTERS[style]
for key in layout_data: for key in layout_data:
x = ceil(key.get('x', 0) * 4) x = key.get('x', 0)
y = ceil(key.get('y', 0) * 3) y = key.get('y', 0)
w = ceil(key.get('w', 1) * 4) w = key.get('w', 1)
h = ceil(key.get('h', 1) * 3) h = key.get('h', 1)
if key_labels: if key_labels:
label = key_labels.pop(0) label = key_labels.pop(0)
@ -177,26 +176,10 @@ def render_layout(layout_data, render_ascii, key_labels=None):
else: else:
label = key.get('label', '') label = key.get('label', '')
label_len = w - 2 if x >= 0.25 and w == 1.25 and h == 2:
label_leftover = label_len - len(label) render_key_isoenter(textpad, x, y, w, h, label, style)
else:
if len(label) > label_len: render_key_rect(textpad, x, y, w, h, label, style)
label = label[:label_len]
label_blank = ' ' * label_len
label_border = box_chars['h'] * label_len
label_middle = label + ' '*label_leftover # noqa: yapf insists there be no whitespace around *
top_line = array('u', box_chars['tl'] + label_border + box_chars['tr'])
lab_line = array('u', box_chars['v'] + label_middle + box_chars['v'])
mid_line = array('u', box_chars['v'] + label_blank + box_chars['v'])
bot_line = array('u', box_chars['bl'] + label_border + box_chars['br'])
textpad[y][x:x + w] = top_line
textpad[y + 1][x:x + w] = lab_line
for i in range(h - 3):
textpad[y + i + 2][x:x + w] = mid_line
textpad[y + h - 1][x:x + w] = bot_line
lines = [] lines = []
for line in textpad: for line in textpad:
@ -216,3 +199,64 @@ def render_layouts(info_json, render_ascii):
layouts[layout] = render_layout(layout_data, render_ascii) layouts[layout] = render_layout(layout_data, render_ascii)
return layouts return layouts
def render_key_rect(textpad, x, y, w, h, label, style):
box_chars = BOX_DRAWING_CHARACTERS[style]
x = ceil(x * 4)
y = ceil(y * 3)
w = ceil(w * 4)
h = ceil(h * 3)
label_len = w - 2
label_leftover = label_len - len(label)
if len(label) > label_len:
label = label[:label_len]
label_blank = ' ' * label_len
label_border = box_chars['h'] * label_len
label_middle = label + ' '*label_leftover # noqa: yapf insists there be no whitespace around *
top_line = array('u', box_chars['tl'] + label_border + box_chars['tr'])
lab_line = array('u', box_chars['v'] + label_middle + box_chars['v'])
mid_line = array('u', box_chars['v'] + label_blank + box_chars['v'])
bot_line = array('u', box_chars['bl'] + label_border + box_chars['br'])
textpad[y][x:x + w] = top_line
textpad[y + 1][x:x + w] = lab_line
for i in range(h - 3):
textpad[y + i + 2][x:x + w] = mid_line
textpad[y + h - 1][x:x + w] = bot_line
def render_key_isoenter(textpad, x, y, w, h, label, style):
box_chars = BOX_DRAWING_CHARACTERS[style]
x = ceil(x * 4)
y = ceil(y * 3)
w = ceil(w * 4)
h = ceil(h * 3)
label_len = w - 1
label_leftover = label_len - len(label)
if len(label) > label_len:
label = label[:label_len]
label_blank = ' ' * (label_len-1) # noqa: yapf insists there be no whitespace around - and *
label_border_top = box_chars['h'] * label_len
label_border_bottom = box_chars['h'] * (label_len-1) # noqa
label_middle = label + ' '*label_leftover # noqa
top_line = array('u', box_chars['tl'] + label_border_top + box_chars['tr'])
lab_line = array('u', box_chars['v'] + label_middle + box_chars['v'])
crn_line = array('u', box_chars['bl'] + box_chars['tr'] + label_blank + box_chars['v'])
mid_line = array('u', box_chars['v'] + label_blank + box_chars['v'])
bot_line = array('u', box_chars['bl'] + label_border_bottom + box_chars['br'])
textpad[y][x - 1:x + w] = top_line
textpad[y + 1][x - 1:x + w] = lab_line
textpad[y + 2][x - 1:x + w] = crn_line
textpad[y + 3][x:x + w] = mid_line
textpad[y + 4][x:x + w] = mid_line
textpad[y + h - 1][x:x + w] = bot_line