UI: move all items in menu to the right as if there was an icon jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 17 Jun 2019 11:25:19 +0100
branchjv
changeset 6070 a0e88386e17c
parent 6069 bc60050be743
child 6184 8c420069d4cb
UI: move all items in menu to the right as if there was an icon If there's no icon, just fraw empty space. This makes popup menus with no icons at all looks similar to popup menus with icons and also makes item labels more readable. In general, looks much better and fits better into modern desktops (GNOME & Windows behave the same).
MenuPanel.st
--- a/MenuPanel.st	Fri Jun 14 12:46:37 2019 +0100
+++ b/MenuPanel.st	Mon Jun 17 11:25:19 2019 +0100
@@ -2087,9 +2087,10 @@
 
     stringOffsetX isNil ifTrue:[
         stringOffsetX := 0.
-
         (self isPopUpView or:[self verticalLayout]) ifTrue:[
+            stringOffsetX := self font height + Item horizontalInset. 
             self do:[:el|
+                stringOffsetX := stringOffsetX max: el preferredExtent y.
                 el isVisible ifTrue:[
                     (    (label := el indicatorForm) notNil
                      or:[(label := el choiceForm) notNil]
@@ -2097,7 +2098,7 @@
                         stringOffsetX := stringOffsetX max:(label width + 2).
                     ] ifFalse:[
                         label := el displayLabel.
-                        label class == LabelAndIcon ifTrue:[
+                        label isLabelAndIcon ifTrue:[
                             stringOffsetX := stringOffsetX max:(label xOfString).
                         ].
                     ].
@@ -2118,13 +2119,13 @@
     w == 0 ifTrue:[
         label := anItem displayLabel.
 
-        label class == LabelAndIcon ifTrue:[
+        label isLabelAndIcon ifTrue:[
             ^ stringOffsetX - label xOfString
         ].
     ].
     ^ stringOffsetX.
 
-    "Modified: / 14-03-2018 / 10:55:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 17-06-2019 / 10:58:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 subMenuIndicationWidth
@@ -6463,12 +6464,12 @@
     |myFont prevFont w h|
 
     displayLabelExtent notNil ifTrue:[
-	^ displayLabelExtent
+        ^ displayLabelExtent
     ].
 
     displayLabel isNil ifTrue:[
-	displayLabelExtent := 0@0.
-	^ displayLabelExtent
+        displayLabelExtent := 0@0.
+        ^ displayLabelExtent
     ].
 
     myFont := self font.
@@ -6478,38 +6479,39 @@
     prevFont := menuPanel setFont:myFont.
 
     displayLabel isString ifTrue:[
-	w := displayLabel widthOn:menuPanel.
-	h := displayLabel heightOn:menuPanel.
+        w := displayLabel widthOn:menuPanel.
+        h := displayLabel heightOn:menuPanel.
 "/        w := myFont widthOf:displayLabel.
 "/        h := myFont heightOf:displayLabel.
     ] ifFalse:[
-	displayLabel isArray ifTrue:[
-	    w := h := 0.
-
-	    displayLabel do:[:aSubLabel|
-		aSubLabel notNil ifTrue:[
-		    w := w max:(aSubLabel widthOn:menuPanel).
-		    h := h + 1 + (aSubLabel heightOn:menuPanel).
-		] ifFalse:[
-		    h := h + (self spaceBetweenEmptyLines)
-		]
-	    ]
-	] ifFalse:[
-	    w := displayLabel widthOn:menuPanel.
-	    h := displayLabel heightOn:menuPanel.
-	].
+        displayLabel isArray ifTrue:[
+            w := h := 0.
+
+            displayLabel do:[:aSubLabel|
+                aSubLabel notNil ifTrue:[
+                    w := w max:(aSubLabel widthOn:menuPanel).
+                    h := h + 1 + (aSubLabel heightOn:menuPanel).
+                ] ifFalse:[
+                    h := h + (self spaceBetweenEmptyLines)
+                ]
+            ]
+        ] ifFalse:[
+            w := displayLabel widthOn:menuPanel.
+            h := displayLabel heightOn:menuPanel.
+        ].
     ].
 
     menuPanel setFont:prevFont.     "/ restore previous font
 
-    "/ care for italic fonts - give a few more pixels at the end
-    myFont italic ifTrue:[
-	w := w + 2.
-    ].
+    "/ Add some extra space at the end so the text does not end
+    "/ right before view's boundady (looks rather bad)
+    w := w + myFont width.
+
     displayLabelExtent := w@h.
     ^ displayLabelExtent
 
     "Modified: / 17-08-2010 / 10:46:06 / cg"
+    "Modified: / 17-06-2019 / 11:05:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 font
@@ -7072,12 +7074,12 @@
     isButton := menuItem isButton.
 
     isButton ifTrue:[
-	s := menuPanel maxAbsoluteButtonLevel ? 0.
-	x := s + HorizontalButtonInset.
-	y := s + VerticalButtonInset.
+        s := menuPanel maxAbsoluteButtonLevel ? 0.
+        x := s + HorizontalButtonInset.
+        y := s + VerticalButtonInset.
     ] ifFalse:[
-	x  := HorizontalInset.
-	y  := (menuPanel isPopUpView ifTrue:[VerticalPopUpInset] ifFalse:[VerticalInset]) ? 2.
+        x  := HorizontalInset.
+        y  := (menuPanel isPopUpView ifTrue:[VerticalPopUpInset] ifFalse:[VerticalInset]) ? 2.
     ].
     x := x * 2.
     y := y * 2.
@@ -7085,47 +7087,50 @@
     isVertical := menuPanel verticalLayout.
 
     self isSeparator ifTrue:[
-	s := self class separatorSize.
-	label = '' ifTrue:[
-	    s := self class halfSeparatorSize.
-	].
-
-	"width of doubleSeparator is 5 !!!!"
-	isVertical ifFalse:[
-	    x := x max:s.
-	    y := y + 5.
-	] ifTrue:[
-	    y := y max:s.
-	    x := x + 5.
-	].
+        s := self class separatorSize.
+        label = '' ifTrue:[
+            s := self class halfSeparatorSize.
+        ].
+
+        "width of doubleSeparator is 5 !!!!"
+        isVertical ifFalse:[
+            x := x max:s.
+            y := y + 5.
+        ] ifTrue:[
+            y := y max:s.
+            x := x + 5.
+        ].
     ] ifFalse:[
-	labelExtent := self displayLabelExtent.
-
-	x := x + labelExtent x.
-	y := y + labelExtent y.
-	x := x + (menuPanel stringOffsetXfor:self).
-
-	isButton ifFalse:[
-	    menuPanel showSeparatingLines ifTrue:[
-		"width of separator is 2 plus right offset 1 := 3"
-		isVertical ifFalse:[x := x + 3] ifTrue:[y := y + 3].
-	    ].
-	].
-	wIcon := 0.
-	self hasMenuIndicator ifTrue:[
-	    icon := MenuPanel menuIndicator.
-	    wIcon := MenuPanel menuIndicatorOffset + icon width.
-	] ifFalse:[
-	    self hasDelayedMenuIndicator ifTrue:[
-		icon := MenuPanel delayedMenuIndicator.
-		wIcon := MenuPanel delayedMenuIndicatorOffset + icon width.
-	    ]
-	].
-	x := x + wIcon.
+        labelExtent := self displayLabelExtent.
+
+        x := x + labelExtent x.
+        y := y + labelExtent y.
+        x := x + (menuPanel stringOffsetXfor:self).
+
+        isButton ifFalse:[
+            menuPanel showSeparatingLines ifTrue:[
+                "width of separator is 2 plus right offset 1 := 3"
+                isVertical ifFalse:[x := x + 3] ifTrue:[y := y + 3].
+            ].
+        ].
+        wIcon := 0.
+        self hasMenuIndicator ifTrue:[
+            icon := MenuPanel menuIndicator.
+            wIcon := MenuPanel menuIndicatorOffset + icon width.
+        ] ifFalse:[
+            self hasDelayedMenuIndicator ifTrue:[
+                icon := MenuPanel delayedMenuIndicator.
+                wIcon := MenuPanel delayedMenuIndicatorOffset + icon width.
+            ] ifFalse:[ 
+                x := x + (menuPanel font width // 2)
+            ].
+        ].
+        x := x + wIcon.
     ].
     ^ x@y
 
     "Modified: / 19-01-2011 / 21:20:35 / cg"
+    "Modified: / 17-06-2019 / 11:01:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 preferredHeight