Skip to content

Conversation

@Vinci10
Copy link
Contributor

@Vinci10 Vinci10 commented Oct 9, 2025

Description:

As per #856, #2632 issues

This PR introduces a new canvas.Ellipse object to Fyne. The radii (X, Y) are set to half the width and height of the canvas size.

The Ellipse object supports:

  • Customizable fill and stroke (color and width)
  • Rotation (in degrees, positive is clockwise, negative is counter-clockwise)
    • the ellipse may be rotated so that its boundaries extend beyond the shorter dimension of the requested size

Examples:
ellipse

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

  • Public APIs match existing style and have Since: line.
  • Any breaking changes have a deprecation path or have been discussed.
  • Check for binary size increases when importing new modules.

Please review and provide feedback!

@coveralls
Copy link

coveralls commented Oct 9, 2025

Coverage Status

coverage: 60.878% (-0.1%) from 61.002%
when pulling 6d8ff8c on Vinci10:ellipse_canvas
into 5a5dd7b on fyne-io:develop.

@andydotxyz
Copy link
Member

The way this works to get size from the space and then rotates such that non-horizontal will probably be clipped doesn't seem intuitive.

Perhaps the rotation should always fit in the space - would that lead to the shape always fitting inside the space instead of being framed by the rotated rectangle?

From a mathematical point Ellipse has 2 focal points so the ratio of width to height can be customised - should that be here too perhaps?

I think all of those points inter-relate and the idea of exactly how the shape is defined may relate to how it fits in the space.

@Vinci10
Copy link
Contributor Author

Vinci10 commented Oct 30, 2025

Sorry, the example might be misleading - it may appear that the ellipse is being clipped, but it’s actually obscured by the gradient beneath it. I expand the rectangle’s frame with padding to ensure the entire rotated ellipse is visible but the canvas size remains the same. Customise the width/height ratio is possible but it won't change anything if radius > min(height, width).

The same apply to rotated horizontal ellipse (depends on the canvas size/height ratio):
ellipse2
ellipse3

@andydotxyz
Copy link
Member

Sorry, the example might be misleading - it may appear that the ellipse is being clipped, but it’s actually obscured by the gradient beneath it.

You're quire right sorry about that. However for consistency with the other graphical primitives that draw inside their space (with some documenting that they are clipped outside that area) it still seems a little unexpected.

If we compare directly with Polygon won't the size be specified as internal to the space and rotation not changing that result? Is that workable with ellipse?

(p.s. there is still the question of whether this truly is an ellipse based on the lack of focus points).

@Vinci10
Copy link
Contributor Author

Vinci10 commented Oct 31, 2025

Good question, currently the Polygon canvas only allows drawing regular polygons with a circumradius set to min(width, height) / 2 (larger dimension is ignored). The shape never exceeds the frame, even when rotated. However, if Polygon canvas will be enhanced by arbitrary polygons (vertices on larger frame edge) then the same issue will occur when rotating.

To keep Ellipse inside the requested size, larger radius cannot exceed min(width, height). It possible to configure but some additional ratio attribute will be needed to calculate shorter radius (like Aspect for rectangle).

(p.s. there is still the question of whether this truly is an ellipse based on the lack of focus points).

The two radii and focus points of an ellipse define the same shape, focus points can be calculated based on the radii (semi-major and semi-minor axis). The radii (X, Y) are set to half the width and height of the canvas size, software painter rasterx lib also requires radii (X, Y) to draw ellipse. OpenGl function is an approximation but the result is quite good imo.

@andydotxyz
Copy link
Member

Good question, currently the Polygon canvas only allows drawing [regular polygons] (https://en.wikipedia.org/wiki/Regular_polygon#Circumradius) with a circumradius set to min(width, height) / 2 (larger dimension is ignored). The shape never exceeds the frame, even when rotated. However, if Polygon canvas will be enhanced by arbitrary polygons (vertices on larger frame edge) then the same issue will occur when rotating.

That is a good point, thanks.

To keep Ellipse inside the requested size, larger radius cannot exceed min(width, height). It possible to configure but some additional ratio attribute will be needed to calculate shorter radius (like Aspect for rectangle).

Yes it could reflect how Rectangle works. However it seems that if we only allow the minimum then a wide, short ellipsis will not be possible I don't think. In the future Aspect could be useful for overriding the aspect to use a smaller area than the full (like Rectangle.Aspect now).

This is a thinker... I wonder, as a thought exercise, what would the expected behaviour be if we support rotation of a rectangle at some point... we can use that to set an expectation for rotation of non-square (boundary) items...

The two radii and focus points of an ellipse define the same shape, focus points can be calculated based on the radii (semi-major and semi-minor axis). The radii (X, Y) are set to half the width and height of the canvas size, software painter rasterx lib also requires radii (X, Y) to draw ellipse. OpenGl function is an approximation but the result is quite good imo.

Ah, OK - thanks for that.

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

Successfully merging this pull request may close these issues.

3 participants