#canvas #egui #graphics #tkinter

egui_canvas

A TKinter-like canvas widget for egui

1 unstable release

0.1.0 Feb 22, 2025

#283 in GUI

MIT license

32KB
309 lines

egui_canvas: a TKinter-like canvas widget for the egui crate.

MIT License


This crate implements a Canvas struct, which implements egui's Widget trait while aiming to be as similar to TKinter (python) Canvas widget as possible.

In practise, this means it is an global state holder for egui::Shape objects and a click handler closure.

This is a hobby project and will not be regularly updated/maintained.

If you find out something is not working / could be made better, open an issue.

Check out the examples.


Cargo features

  • click - enables click handler functionality. Enabled by default.
  • image - enables image functionality. Not yet implemented.

TODOs

  • crates.io
  • Badges
  • Tests
  • Image support (the feature does nothing yet)
  • GitLab pipelines

Known limitations

  • For click handler to be able to mutate the canvas object itself (or an overlying object which owns the canvas object), it needs to have a mutable pointer to said object moved into it at definition, because a reference couldn't be guaranteed to live long enough. This makes mutating (or even accessing) the canvas object from the click handler unsafe. For now, safety is ensured by the fact that dropping the canvas object needs to wait for a lock on the Mutex of the click handler, which is locked if the click handler is running.
  • Shapes need to be wrapped in std::rc::Rc.
  • Full-sized canvas can't cover the whole window (egui::Ui::available_size doesn't return the whole size of the window)

Dependencies / Companion crates

  • This crate needs to be used together with the eframe and egui crates (because it only implements a widget)
  • You may find it useful to use crate native-dialog together with this one

Dependencies

~4.5–9MB
~89K SLoC