Skip to content

Context API: support multiple types of contexts #119

@nikochiko

Description

@nikochiko

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 *)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions