Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The border color specified in a stylesheet is not applied to an image presenter #1649

Open
koendehondt opened this issue Nov 13, 2024 · 3 comments

Comments

@koendehondt
Copy link
Contributor

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:

Screenshot 2024-11-13 at 12 46 18

Expected and ok:

  • Green background color
  • Border width of 3 pixels.

Expected, but not ok:

  • The border should be yellow. It is color B5B5B5.
@koendehondt
Copy link
Contributor Author

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.

@koendehondt
Copy link
Contributor Author

This is the result of the code snippet after removing ImageMorph>>#adoptPaneColor:, which is what we expect with the given stylesheet:

Screenshot 2024-11-29 at 15 01 54

@Ducasse
Copy link
Contributor

Ducasse commented Dec 1, 2024

Thanks Koen for the analysis and the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants