From ec718cac81a798486a09d2b1af6436a82bbf51d4 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Thu, 4 May 2023 16:01:10 -0400 Subject: [PATCH] Make submenu positioning more reliable --- README.md | 3 ++- src/textual_paint/menus.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cb16714..a5b2449 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,8 @@ cat samples/ship.ans - Pressing both mouse buttons stops the current tool, but doesn't undo the current action. - Due to limitations of the terminal, shortcuts using Shift or Alt might not work. - Menus are not keyboard navigable. -- Clicking the Zoom submenu doesn't always work. You just have to click it a few times before it opens. +- The Zoom submenu flickers as it opens, and may not always open in the right place. +- The canvas flickers when zooming in with the Magnifier tool. - Some languages don't display correctly. - Large files can make the program very slow, as can magnifying the canvas. - The program may crash or freeze up randomly, and there's no auto-save feature. diff --git a/src/textual_paint/menus.py b/src/textual_paint/menus.py index 341526a..d63bd3c 100644 --- a/src/textual_paint/menus.py +++ b/src/textual_paint/menus.py @@ -123,6 +123,17 @@ class Menu(Container): else: self.styles.max_height = self.screen.size.height + # Needed to recompute self.region + # This makes it much more reliable to open and open in the correct spot, + # but unfortunately none of these things work to avoid flickering: + # self.styles.offset = (0, 0) + # self.refresh(layout=True) + # self.styles.visibility = "hidden" + # self.hidden = True + self.app.refresh(layout=True) + # self.styles.visibility = "visible" + # self.hidden = False + # I also tried call_after_refresh for the below. rect = parent_menu_item.region self.styles.offset = ( rect.x - self.region.width if get_direction() == "rtl" else rect.x + rect.width,