chiark / gitweb /
Don't let menu items go way over to the right.
authorSimon Tatham <anakin@pobox.com>
Thu, 28 Dec 2023 12:11:57 +0000 (12:11 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 28 Dec 2023 12:11:57 +0000 (12:11 +0000)
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

index db1d3cf9547d6422d50401a6a455b640db9cabe1..8ce0cf6a6206b8d5dd987d42724f3d9bb700c0bc 100644 (file)
@@ -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",