15 unstable releases (3 breaking)

0.3.0-alpha1 Feb 24, 2019
0.2.0 Oct 23, 2018
0.1.4 Sep 26, 2018
0.1.2 Apr 27, 2018
0.0.2 Dec 13, 2015

#234 in Graphics APIs

Download history 370/week @ 2023-10-19 327/week @ 2023-10-26 226/week @ 2023-11-02 189/week @ 2023-11-09 254/week @ 2023-11-16 231/week @ 2023-11-23 167/week @ 2023-11-30 183/week @ 2023-12-07 303/week @ 2023-12-14 224/week @ 2023-12-21 121/week @ 2023-12-28 159/week @ 2024-01-04 205/week @ 2024-01-11 213/week @ 2024-01-18 172/week @ 2024-01-25 116/week @ 2024-02-01

732 downloads per month
Used in 7 crates (via druid-win-shell)

MIT/Apache

145KB
4.5K SLoC

Safe abstractions for drawing on Windows using Direct2D

Example

extern crate direct2d;

use direct2d::{DeviceContext, RenderTarget};
use direct2d::brush::SolidColorBrush;
use direct2d::image::Bitmap;

fn draw(context: &mut DeviceContext, target: &Bitmap) {
    let brush = SolidColorBrush::create(&context)
        .with_color(0xFF_7F_7F)
        .build().unwrap();

    context.begin_draw();
    context.set_target(target);
    context.clear(0xFF_FF_FF);
    
    context.draw_line((10.0, 10.0), (20.0, 20.0), &brush, 2.0, None);
    context.draw_line((10.0, 20.0), (20.0, 10.0), &brush, 2.0, None);

    match context.end_draw() {
        Ok(_) => {/* cool */},
        Err(_) => panic!("Uh oh, rendering failed!"),
    }
}

Dependencies

~0–770KB
~13K SLoC