Crate flo_draw[][src]

Expand description

flo_draw provides a simple API for rendering 2D graphics into a window

It’s part of a set of companion crates that provide a very flexible 2D graphics rendering system.

  • flo_canvas provides a way to describe 2D rendering operations without requiring any particular implementation
  • flo_render describes how to render to modern graphics hardware via the OpenGL and Metal APIs
  • flo_render_canvas translates between instructions for flo_canvas and flo_render, using lyon for tessellation. It also provides facilities for offscreen rendering
  • flo_draw is this crate, and it provides an easy way to render 2D vector graphics to screen using glutin and OpenGL.

Why use these crates?

The main reason to use flo_draw or the offscreen renderer in flo_render_canvas is that they provide a very straightforward API: the setup needed to start drawing graphics to a window or a byte buffer is almost nonexistent. In spite of this they are also very flexible, capable of being used to create fully interactive applications which can run on any system supported by glutin and OpenGL 3.3.

The rendering system is very flexible and easily ported to a different target, so if you outgrow the glutin-based windowing system and want to integrate your algorithms into another application, the architecture supplied by flo_canvas and flo_render makes it easy to intercept the underlying rendering operations and integrate them into any other system. Additional renderers are already available in FlowBetween to render flo_canvas instructions to HTML canvases, OS X Quartz render contexts and to Cairo. flo_render has native support for both OpenGL 3.3 and Metal.

The 2D graphics model used here has a few interesting features that are not present in many other rendering libraries. In particular, there is a layer system which is very useful for simplifying the design of interactive graphics applications by reducing the amount of work involved in a redraw, and it’s possible to both draw and erase shapes. With the hardware renderers in flo_render, the number of layers is effectively unlimited. There’s also a ‘sprite’ system, which makes it possible to easily re-render complicated shapes.

Getting started

Start your application by calling with_2d_graphics(|| {}) with a function to perform whatever drawing operations you want. In that function, let canvas = create_drawing_window("Canvas window"); will create a window with a 2D graphics canvas that you can draw on using canvas.draw(|gc| { });. Finally, create_drawing_window_with_events() is a way to create a graphics window that supplies events allowing interactivity.

The documentation for flo_canvas shows what can be done in a drawing routine.

See the example for the basic setup for an application that renders 2D graphics and for a basic example with event handling.



pub use flo_canvas as canvas;
pub use flo_canvas_events as events;
pub use flo_render_canvas as render_canvas;
pub use flo_binding as binding;


A unique identifier assigned to a specific pointer on the system (a device that has a mouse and touch input might be tracking multiple pointer devices)

Describes the state of a pointer device

The window properties struct provides a copy of all of the bindings for a window, and is a good way to provide custom bindings (for example, if you want to be able to toggle the window betwen fullscreen and a normal display)


The button on a mouse or other device

Events that can arrive from a flo_draw window

Represents a key

The types of mouse pointer that can be displayed in a window

The action associated with a pointer event


Trait implemented by objects that can provide properties for creating/updating a flo_draw window


Creates a canvas that will render to a window

Creates a drawing target that will render to a window, along with a stream of events from that window

Creates a drawing target that will render to a window

Creates a drawing window that will render a stream of drawing instructions

Creates a drawing target that will render to a window, along with a stream of events from that window

Creates a window that can be rendered to by sending groups of render actions

Creates a window that renders a stream of actions

Performs on-startup initialisation steps for offscreen rendering

Renders a canvas in an offscreen context, returning the resulting bitmap

Steals the current thread to run the UI event loop and calls the application function back to continue execution