From 245aeea7f49b6959b019cf0285a88ce7c57c4a60 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 28 Dec 2023 12:11:57 +0000 Subject: [PATCH] Don't let menu items go way over to the right. The allocation of 3/4 of padding space to the left-hand side is intended for cases where there isn't room to put the = signs in the middle. When there is, we should do it. --- src/text.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/text.rs b/src/text.rs index db1d3cf..8ce0cf6 100644 --- a/src/text.rs +++ b/src/text.rs @@ -1427,6 +1427,7 @@ impl TextFragment for MenuKeypressLine { let ourwidth = self.lmaxwid + self.rmaxwid + 3; // " = " in the middle let space = width - min(width, ourwidth + 1); let leftpad = min(space * 3 / 4, width - min(width, self.lmaxwid + 2)); + let leftpad = min(leftpad, (width - min(width, self.lmaxwid + 8)) / 2); let lspace = self.lmaxwid - self.lwid; let llspace = lspace / 2; @@ -1453,6 +1454,12 @@ fn test_menu_keypress() { "Something or other", "K ")); + assert_eq!(mk.render(80), vec! { + ColouredString::general( + " [S] = Something or other", + " k K "), + }); + assert_eq!(mk.render(40), vec! { ColouredString::general( " [S] = Something or other", -- 2.30.2