From ac23705c692e1ef337630944b3b0fccccce57499 Mon Sep 17 00:00:00 2001 From: Peter Lebbing Date: Tue, 8 Aug 2017 18:20:06 +0200 Subject: [PATCH 1/2] Cope better with long package names Remaining bugs; - If moving to a package below a long package, and the package moved to is partly out of view, the list does not scroll to get it fully in view. - Even though it appears that ugfx computes ugfx.get_string_width() the same way, adding the widths of ugfx.get_char_width() together still sometimes produces overly long strings, for instance for this package: ;;)''2303211-2194523023klfrsdkfdlk;df;;''''{}{}{[[]]]]])))(()_)}}./.,////\\\\ (No, that wasn't my cat on the keyboard, that's the name of the package! It's in "uncategorised") --- esp32/modules/installer.py | 58 +++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/esp32/modules/installer.py b/esp32/modules/installer.py index d4fe12e53..1976f8dbb 100644 --- a/esp32/modules/installer.py +++ b/esp32/modules/installer.py @@ -45,6 +45,18 @@ def show_description(active): text.text(packages[options.selected_index()]["description"]) ugfx.flush() +def move_sel(active,dir_): + if active: + sel = options.selected_index() + print("Ingoing:", sel) + while sel > 0 and sel < len(packages) and packages[sel] is None: + print("Dummy:", sel, packages[sel]) + sel += dir_ + if sel > 0 and sel < len(packages): + print("Final:", sel) + options.selected_index(sel) + show_description(True) + def select_category(active): if active: global categories @@ -85,12 +97,50 @@ 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) + print("Extra:", i, s) + else: + print("First:", i, s) + 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) + print("Extra:", i, s) + 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) From c4d5356c4209831c43dc4a09f3f2d660ea53deed Mon Sep 17 00:00:00 2001 From: Peter Lebbing Date: Sun, 13 Aug 2017 13:25:24 +0200 Subject: [PATCH 2/2] Remove debugging output --- esp32/modules/installer.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/esp32/modules/installer.py b/esp32/modules/installer.py index 1976f8dbb..f4f55d469 100644 --- a/esp32/modules/installer.py +++ b/esp32/modules/installer.py @@ -48,12 +48,9 @@ def show_description(active): def move_sel(active,dir_): if active: sel = options.selected_index() - print("Ingoing:", sel) while sel > 0 and sel < len(packages) and packages[sel] is None: - print("Dummy:", sel, packages[sel]) sel += dir_ if sel > 0 and sel < len(packages): - print("Final:", sel) options.selected_index(sel) show_description(True) @@ -121,9 +118,6 @@ def list_apps(slug): if count: i += 1 packages.insert(i, None) - print("Extra:", i, s) - else: - print("First:", i, s) count += 1 if count == 3: # Cut off the rest s = "" @@ -135,7 +129,6 @@ def list_apps(slug): if count: # Should be unneeded, defensive i += 1 packages.insert(i, None) - print("Extra:", i, s) i += 1 options.selected_index(0)