#UI_ENHANCEMENT by cg
class: Label
comment/format in: #rawLabelSizeOf:
changed:
#initialize
#preferredExtent
geometry
--- a/Label.st Wed Nov 02 16:22:46 2016 +0100
+++ b/Label.st Wed Nov 02 16:45:22 2016 +0100
@@ -1441,8 +1441,8 @@
labelWidth := labelHeight := 0.
logo := nil.
fixSize := false.
- hSpace := (self horizontalPixelPerMillimeter:0.5) rounded.
- vSpace := (self verticalPixelPerMillimeter:0.25) rounded
+ hSpace := ((self horizontalPixelPerMillimeter:0.5) max:2) rounded.
+ vSpace := ((self verticalPixelPerMillimeter:0.5) max:2) rounded
!
recreate
@@ -1643,75 +1643,6 @@
^ nil
! !
-!Label methodsFor:'others'!
-
-rawLabelSizeOf:aLogo
- "compute the extent needed to hold aLogo; aForm or aString"
-
- |logoUsed numberOfLines w h textHeight textWidth bounds|
-
- logoUsed := aLogo.
- aLogo isString ifTrue:[
- numberOfLines := 1 + (aLogo occurrencesOf:(Character cr)).
- (numberOfLines ~~ 1) ifTrue:[
- logoUsed := aLogo asStringCollection
- ]
- ] ifFalse:[
- (aLogo isStringCollection) ifTrue:[
- numberOfLines := aLogo size.
- (numberOfLines <= 1) ifTrue:[
- logoUsed := aLogo asString
- ]
- ]
- ].
-
- numberOfLines isNil ifTrue:[
- "logoUsed is neither a String nor a StringCollection"
- (logoUsed respondsTo:#preferredBounds) ifTrue:[
- bounds := logoUsed preferredBounds.
- w := bounds width.
- h := bounds height.
- ] ifFalse:[
- w := logoUsed widthOn:self.
- h := logoUsed heightOn:self.
- ].
-
-"/ b := logoUsed bounds.
-"/ labelWidth := b right.
-"/ labelHeight := b bottom.
- logoUsed isImageOrForm ifFalse:[
- w := w + (hSpace * 2).
- h := h + (vSpace * 2).
- ].
- ^ w@h
- ].
-
- logoUsed isString ifTrue:[
- "/ a string or Text
- textHeight := logoUsed heightOn:self.
- textWidth := logoUsed widthOn:self.
- ] ifFalse:[
- "/ a StringCollection
- textHeight := (gc font height) * numberOfLines.
-
- textWidth := 0.
- logoUsed do:[:line |
- |thisWidth|
-
- line notNil ifTrue:[
- thisWidth := line asString widthOn:self.
- textWidth := textWidth max:thisWidth
- ]
- ].
- ].
-
- w := textWidth + (hSpace * 2).
- h := textHeight + (vSpace * 2).
- ^ w@h
-
- "Modified: / 05-12-2011 / 22:35:44 / cg"
-! !
-
!Label methodsFor:'private'!
computeLabelOrigin
@@ -1830,6 +1761,73 @@
self invalidate
"Modified: / 6.6.1998 / 19:23:45 / cg"
+!
+
+rawLabelSizeOf:aLogo
+ "compute the extent needed to hold aLogo; aForm or aString"
+
+ |logoUsed numberOfLines w h textHeight textWidth bounds|
+
+ logoUsed := aLogo.
+ aLogo isString ifTrue:[
+ numberOfLines := 1 + (aLogo occurrencesOf:(Character cr)).
+ (numberOfLines ~~ 1) ifTrue:[
+ logoUsed := aLogo asStringCollection
+ ]
+ ] ifFalse:[
+ (aLogo isStringCollection) ifTrue:[
+ numberOfLines := aLogo size.
+ (numberOfLines <= 1) ifTrue:[
+ logoUsed := aLogo asString
+ ]
+ ]
+ ].
+
+ numberOfLines isNil ifTrue:[
+ "logoUsed is neither a String nor a StringCollection"
+ (logoUsed respondsTo:#preferredBounds) ifTrue:[
+ bounds := logoUsed preferredBounds.
+ w := bounds width.
+ h := bounds height.
+ ] ifFalse:[
+ w := logoUsed widthOn:self.
+ h := logoUsed heightOn:self.
+ ].
+
+"/ b := logoUsed bounds.
+"/ labelWidth := b right.
+"/ labelHeight := b bottom.
+ logoUsed isImageOrForm ifFalse:[
+ w := w + (hSpace * 2).
+ h := h + (vSpace * 2).
+ ].
+ ^ w@h
+ ].
+
+ logoUsed isString ifTrue:[
+ "/ a string or Text
+ textHeight := logoUsed heightOn:self.
+ textWidth := logoUsed widthOn:self.
+ ] ifFalse:[
+ "/ a StringCollection
+ textHeight := (gc font height) * numberOfLines.
+
+ textWidth := 0.
+ logoUsed do:[:line |
+ |thisWidth|
+
+ line notNil ifTrue:[
+ thisWidth := line asString widthOn:self.
+ textWidth := textWidth max:thisWidth
+ ]
+ ].
+ ].
+
+ w := textWidth + (hSpace * 2).
+ h := textHeight + (vSpace * 2).
+ ^ w@h
+
+ "Modified: / 05-12-2011 / 22:35:44 / cg"
! !
!Label methodsFor:'queries'!
@@ -1841,7 +1839,7 @@
preferredExtent
"return my preferred extent - this is the minimum size I would like to have"
- |ext m|
+ |ext m2|
"/ If I have an explicit preferredExtent...
explicitExtent notNil ifTrue:[
@@ -1860,8 +1858,8 @@
self label:''
].
ext := self rawLabelSizeOf:logo.
- m := (margin + self extraMarginForBorder) * 2.
- ^ (m + ext x + hSpace) @ (m + ext y + vSpace)
+ m2 := (margin + self extraMarginForBorder) * 2.
+ ^ (m2 + ext x + hSpace) @ (m2 + vSpace + ext y)
"Modified: 19.7.1996 / 20:44:41 / cg"
!