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

[Feature Request] Make IntoDrawingArea more flexible #536

Open
ecton opened this issue Jan 12, 2024 · 0 comments
Open

[Feature Request] Make IntoDrawingArea more flexible #536

ecton opened this issue Jan 12, 2024 · 0 comments

Comments

@ecton
Copy link

ecton commented Jan 12, 2024

What is the feature ?

IntoDrawingArea::into_drawing_area() has a return type that utilizes Self. This restricts into_drawing_area() from being used to only types that implement DrawingBackend. I propose using an associated type instead:

pub trait IntoDrawingArea: Sized {
  type Backend: DrawingBackend;

   fn into_drawing_area(self) -> DrawingArea<Self::Backend, Shift>;
}

This definition would enable implementations on any type that contains or can create a DrawingBackend type.

(Optional) Why this feature is useful and how people would use the feature ?

When adding support for plotters in both Kludgine and Cushy, I realized I can't implement IntoDrawingArea for my types, because the types that implement DrawingBackend aren't the types exposed to the end-user for rendering. The reasons vary by crate:

  • In Kludgine, [Feature Request] Change estimate_text_size to take &mut self #535 required creating a wrapper that utilizes a RefCell. This wrapper type, not the renderer type, is what implements DrawingBackend.
  • In Cushy, I purposely hide direct access to the renderer type to provide a limited API surface. Even if 535 were changed, Cushy would still have to provide a passthrough DrawingBackend implementation instead of being able to implement IntoDrawingArea to provide compatibility.

The current workaround in both of my situations is to have my own crate-specific as_plot_area() functions that return a DrawingArea. I would prefer to replace these APIs with implementations of IntoDrawingArea.

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

No branches or pull requests

1 participant