Some example libaries that do this in Python
I found this curated list where either GUI or games might be a good fit but its hard to tell what a library's canvas can do without digging into it.
get keyboard and mouse input
Most 2d graphic libs do not support that. Cairo does not, cairo on linux uses gtkdrawingarea for that.
Maybe you want SDL2, I think it supports input.
Or maybe Raylib?
Note, when people say canvas, some have graphic object handling in mind. But Cairo just draws shapes, it does not store whole objects internally.
Maybe you want Nim Pixi of treeform. Pixi is similar to cairo.
Most 2d graphic libs do not support that. Cairo does not, cairo on linux uses gtkdrawingarea for that.
Ah, I'm on Linux and that might be why I was able to get input. I just had a look and I'm using the Python C FFI for both XCB and Cairo, calling connection = xcffib.connect() and then connection.poll_for_event() to get input events.
The drawing area is a cairocffi.XCBSurface (initialized here). I think that doesn't have any GTK in it (but I haven't looked inside the wrappers) but the events are definitely coming from X.
In any case, I don't mind using two different libraries for drawing and input if I can get the coordinates to match.
Note, when people say canvas, some have graphic object handling in mind. But Cairo just draws shapes, it does not store whole objects internally.
Good question. I don't need managed object and prefer to have an easy way to route around existing management if the library offers this (I think that's what I did for Tk but don't quite remember). This is because I want to write my own object layer on top.
Maybe you want Nim Pixi of treeform. Pixi is similar to cairo.
Looks like this is the second mention of Pixie so I'll definitely have a look.
Is Raylib good for 2d? I'm remember trying to use OpenGL at some point (with Python, not Nim) and while it worked, I was always fighting the abstraction layer a bit.
I think both Raylib and SDL2 are not bad, and Nim bindings are available.
But Pixie should be the most fun, when you do not need highest performance and can accept that it is still in an early development stage.
For highest performance we may consider blend2d, but that one has no real docs yet and no Nim bindings:
I may later use blend2d myself, but for now I use GTK4 with cairo: https://github.com/StefanSalewski/SDT