The border color specified in a stylesheet is not applied to an image presenter
Try this in a Playground:
application := SpApplication new
addStyleSheetFromString: '.application [
.yellowBorder [
Draw { #backgroundColor: #green},
Container { #borderColor: #yellow, #borderWidth: 3 } ]
]';
yourself.
presenter := SpPresenter newApplication: application.
image := presenter newImage
image: (self iconNamed: #grayCircle);
addStyle: 'yellowBorder';
yourself.
layout := SpBoxLayout newTopToBottom
vAlignCenter;
hAlignCenter;
add: image;
yourself.
presenter layout: layout.
presenter open
This snippet opens this window:
Expected and ok:
- Green background color
- Border width of 3 pixels.
Expected, but not ok:
- The border should be yellow. It is color B5B5B5.
The root cause of the issue is the implementation of ImageMorph>>#adoptPaneColor::
adoptPaneColor: paneColor
"Change our border color too."
super adoptPaneColor: paneColor.
paneColor ifNil: [^self].
self borderStyle baseColor: paneColor twiceDarker
This method sets the baseColor of self borderStyle. Let's look at Morph>>#borderStyle:
borderStyle
^ extension
ifNil: [BorderStyle default trackColorFrom: self]
ifNotNil: [:ext | (ext borderStyle ifNil: [BorderStyle default]) trackColorFrom: self]
Note that this method answers a new BorderStyle if there is no extension or if the extension does not have a borderStyle. In those situations, self borderStyle baseColor: paneColor twiceDarker in ImageMorph>>#adoptPaneColor: has no visual effect (because the new border style is not set in the morph).
However, if the morph does have an extension with a borderStyle, then self borderStyle baseColor: paneColor twiceDarker changes the baseColor, which will be used when drawing the morph. That is what we see in the screenshot: the border is gray. In the example code of the reported issue, the morph has a borderStyle which holds a width of 3 pixels and a yellow baseColor because the style Container { #borderColor: #yellow, #borderWidth: 3 } defines the border style.
So the implementation of ImageMorph>>#adoptPaneColor: is wrong. In case no style has been applied to a SpImagePresenter, the method has no effect. In case a style applies a borderColor, the method does not apply the style's borderColor, but changes it to paneColor twiceDarker instead.
In conclusion, the method can be removed. It will fix the issue and it has no consequences if no style has been applied.
This is the result of the code snippet after removing ImageMorph>>#adoptPaneColor:, which is what we expect with the given stylesheet:
Thanks Koen for the analysis and the fix!