[squeak-dev] The Inbox: Graphics-nice.425.mcz

Marcel Taeumel marcel.taeumel at hpi.de
Mon Feb 17 16:03:36 UTC 2020


What about "0.0" instead of "0" for fractions to indicate the expected value?

Best,
Marcel
Am 17.02.2020 16:45:50 schrieb commits at source.squeak.org <commits at source.squeak.org>:
Nicolas Cellier uploaded a new version of Graphics to project The Inbox:
http://source.squeak.org/inbox/Graphics-nice.425.mcz

==================== Summary ====================

Name: Graphics-nice.425
Author: nice
Time: 17 February 2020, 4:44:09.459532 pm
UUID: 39f72c43-38db-9344-857e-1a109cbedfa2
Ancestors: Graphics-pre.424

Expunge the nil protection out of the LayoutFrame.

Those additional states (to be or not to be nil...) are gratuitous complexifications. YAGNI.
Let's initialize all inst var to zero instead.
This will provide a reasonable default (the least surprising one).

leftOffset = rightOffset = 0 ==> pure proportional layout (no nil offset required).

leftFraction = rightFraction ==> pure absolute layout (no nil fraction required)

all zero ==> empty layout.

Every other combination is possible.

=============== Diff against Graphics-pre.424 ===============

Item was added:
+ ----- Method: LayoutFrame>>fixup (in category 'initialize-release') -----
+ fixup
+ "Set-up default value for un-initialized layout frames"
+
+ "LayoutFrame allInstancesDo: [:e | e fixup]."
+
+ leftFraction ifNil: [leftFraction := 0].
+ leftOffset ifNil: [leftOffset := 0].
+ topFraction ifNil: [topFraction := 0].
+ topOffset ifNil: [topOffset := 0].
+ rightFraction ifNil: [rightFraction := 0].
+ rightOffset ifNil: [rightOffset := 0].
+ bottomFraction ifNil: [bottomFraction := 0].
+ bottomOffset ifNil: [bottomOffset := 0].!

Item was added:
+ ----- Method: LayoutFrame>>initialize (in category 'initialize-release') -----
+ initialize
+ "By defalut, let the frame be empty"
+
+ leftFraction := leftOffset := topFraction := topOffset := rightFraction := rightOffset := bottomFraction := bottomOffset := 0!

Item was changed:
----- Method: LayoutFrame>>layout:in: (in category 'layout') -----
layout: oldBounds in: newBounds
"Return the proportional rectangle insetting the given bounds"
+ | left right top bottom |
+ left := newBounds left + (newBounds width * leftFraction).
+ left := left + leftOffset.
+ right := newBounds right - (newBounds width * (1.0 - rightFraction)).
+ right := right + rightOffset.
+ top := newBounds top + (newBounds height * topFraction).
+ top := top + topOffset.
+ bottom := newBounds bottom - (newBounds height * (1.0 - bottomFraction)).
+ bottom := bottom + bottomOffset.
- | left right top bottom |
- leftFraction ifNotNil:[
- left := newBounds left + (newBounds width * leftFraction).
- leftOffset ifNotNil:[left := left + leftOffset]].
- rightFraction ifNotNil:[
- right := newBounds right - (newBounds width * (1.0 - rightFraction)).
- rightOffset ifNotNil:[right := right + rightOffset]].
- topFraction ifNotNil:[
- top := newBounds top + (newBounds height * topFraction).
- topOffset ifNotNil:[top := top + topOffset]].
- bottomFraction ifNotNil:[
- bottom := newBounds bottom - (newBounds height * (1.0 - bottomFraction)).
- bottomOffset ifNotNil:[bottom := bottom + bottomOffset]].
- left ifNil:[ right
- ifNil:[left := oldBounds left. right := oldBounds right]
- ifNotNil:[left := right - oldBounds width]].
- right ifNil:[right := left + oldBounds width].
- top ifNil:[ bottom
- ifNil:[top := oldBounds top. bottom := oldBounds bottom]
- ifNotNil:[top := bottom - oldBounds height]].
- bottom ifNil:[bottom := top + oldBounds height].
^(left rounded @ top rounded) corner: (right rounded @ bottom rounded)!

Item was changed:
----- Method: LayoutFrame>>minHeightFrom: (in category 'layout') -----
minHeightFrom: minHeight
"Return the minimal extent the given bounds can be represented in"
+ | height |
+ height := bottomFraction = topFraction
- | height top bottom |
- top := topFraction ifNil: [0.0].
- bottom := bottomFraction ifNil: [1.0].
- height := bottom = top
ifTrue: [0]
+ ifFalse: [minHeight / (bottomFraction - topFraction)].
+ height := height + topOffset + bottomOffset.
- ifFalse: [minHeight / (bottom - top)].
- topOffset ifNotNil:[height := height + topOffset].
- bottomOffset ifNotNil:[height := height + bottomOffset].
^ height truncated!

Item was changed:
----- Method: LayoutFrame>>minWidthFrom: (in category 'layout') -----
minWidthFrom: minWidth
"Return the minimal extent the given bounds can be represented in"
+ | width |
+ width := leftFraction = rightFraction
- | width left right |
- left := leftFraction ifNil: [0.0].
- right := rightFraction ifNil: [1.0].
- width := left = right
ifTrue: [0]
+ ifFalse: [minWidth / (rightFraction - leftFraction)].
+ width := width + leftOffset + rightOffset.
- ifFalse: [minWidth / (right - left)].
- leftOffset ifNotNil:[width := width + leftOffset].
- rightOffset ifNotNil:[width := width + rightOffset].
^width truncated!

Item was changed:
----- Method: LayoutFrame>>printOn: (in category 'printing') -----
printOn: aStream

super printOn: aStream.

aStream nextPutAll: '( '.

{ {'l'. self leftFraction. self leftOffset}. {'t'. self topFraction. self topOffset}. {'r'. self rightFraction. self rightOffset}. {'b'. self bottomFraction. self bottomOffset} } do: [:spec |
aStream nextPutAll: spec first; space.

spec second printOn: aStream maxDecimalPlaces: 2.

+ aStream nextPutAll: (spec third >= 0 ifTrue: ['+'] ifFalse: ['-']).
+ spec third abs printOn: aStream maxDecimalPlaces: 0]
- aStream nextPutAll: ((spec third ifNil: [0]) >= 0 ifTrue: ['+'] ifFalse: ['-']).
- (spec third ifNil: [0]) abs printOn: aStream maxDecimalPlaces: 0]
separatedBy: [aStream space].

aStream nextPutAll: ' )'.!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200217/65cb2f01/attachment.html>


More information about the Squeak-dev mailing list