Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cope better with long package names #216

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions esp32/modules/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def show_description(active):
text.text(packages[options.selected_index()]["description"])
ugfx.flush()

def move_sel(active,dir_):
if active:
sel = options.selected_index()
while sel > 0 and sel < len(packages) and packages[sel] is None:
sel += dir_
if sel > 0 and sel < len(packages):
options.selected_index(sel)
show_description(True)

def select_category(active):
if active:
global categories
Expand Down Expand Up @@ -85,12 +94,46 @@ def list_apps(slug):
gc.collect()
return

for package in packages:
options.add_item("%s rev. %s" % (package["name"], package["revision"]))
# Based on ugfx_widgets.c, it's
# width - (LST_SCROLLWIDTH+3) - LST_HORIZ_PAD
# which works out to width - 20
maxwidth = int(ugfx.width()/2) - 20
i = 0
for package in packages.copy():
item = "%s rev. %s" % (package["name"], package["revision"])
width = ugfx.get_string_width(item, "Roboto_Regular12")
if width <= maxwidth:
options.add_item(item)
else:
s = ""
width = 0
count = 0
for c in item:
cw = ugfx.get_char_width(ord(c), "Roboto_Regular12")
if width == 0 or width + cw <= maxwidth:
s += c
width += cw
else:
options.add_item(s)
if count:
i += 1
packages.insert(i, None)
count += 1
if count == 3: # Cut off the rest
s = ""
break
s = c
width = cw
if s:
options.add_item(s)
if count: # Should be unneeded, defensive
i += 1
packages.insert(i, None)
i += 1
options.selected_index(0)

ugfx.input_attach(ugfx.JOY_UP, show_description)
ugfx.input_attach(ugfx.JOY_DOWN, show_description)
ugfx.input_attach(ugfx.JOY_UP, lambda pushed: move_sel(pushed, -1))
ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: move_sel(pushed, 1))
ugfx.input_attach(ugfx.BTN_A, install_app)
ugfx.input_attach(ugfx.BTN_B, lambda pushed: list_categories() if pushed else False)
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app('') if pushed else False)
Expand Down