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

Context API: support multiple types of contexts #119

Open
nikochiko opened this issue Mar 11, 2024 · 1 comment
Open

Context API: support multiple types of contexts #119

nikochiko opened this issue Mar 11, 2024 · 1 comment

Comments

@nikochiko
Copy link
Collaborator

We should be able to support multiple types of context.

So far, the API is restricted to the Cairo backend and assumes that it will be the only one.

I suggest that we:

  • separate the backend logic and the rendering API by putting in another layer of abstraction between then
  • make show add to global context - whose actual behaviour will be different depending on the actual backend
  • let each backend define its own context type
  • have each backend loosely conform to an interface

e.g. the context type that is as of now a record that immediately stores the cairo context and surface, will change to a sum type:

type context =
    CairoContext of Backends.Cairo.context
  | SVGContext of Backends.SVG.context

The global context will be of context type, then we change the rendering logic to do a match-case on the context before we pass it to the actual backend.

The interface for each backend should be something like:

type context = anything_at_all

val show: (?ctx: context) -> Joy.shape list -> unit  (* ctx defaults to the global context *)
@nikochiko
Copy link
Collaborator Author

We can also do a LazyContext that only stores the list of shapes that are show-n.
At the end, depending on the function that the user calls (writePNG or writeSVG or whatever), and from introspecting the environment, we can smartly guess the context and give the user what they probably want.

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

1 participant