Skip to content

[Feature Request] Make IntoDrawingArea more flexible #536

Open
@ecton

Description

@ecton

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ecton

        Issue actions

          [Feature Request] Make IntoDrawingArea more flexible · Issue #536 · plotters-rs/plotters