Lazily add a triangle to indicate the Zoom submenu

This commit is contained in:
Isaiah Odhner 2023-04-23 01:03:52 -04:00
parent f106cc5c35
commit 1a6bfb5b90

View File

@ -130,11 +130,23 @@ class Menu(Container):
# Find the widest label
max_width = 0
# any_submenus = False
for item in self.items:
if isinstance(item, MenuItem):
assert isinstance(item.label, Text)
if len(item.label.plain) > max_width:
max_width = len(item.label.plain)
if item.submenu:
# any_submenus = True
# Add a right pointing triangle to the label
# TODO: Make this work generally. Right now I've just spaced it for View > Zoom in English.
# Also, all this layout stuff should ideally use the width, not the length, of text.
# And it's stupid that this code applies multiple times to the same menu,
# and has to be idempotent.
# Basically I should rewrite this whole thing.
# I'd like to try using the built-in ListView widget for menus.
if not item.label.plain.endswith(""):
item.label = item.label.markup + "\t"
# Split on tab character and align the shortcuts
for item in self.items:
if isinstance(item, MenuItem):