48 releases (13 breaking)

new 0.21.0 Mar 14, 2023
0.20.3 Dec 13, 2022
0.11.7 Oct 17, 2022
0.11.2 Jul 29, 2022
0.0.8 Jun 26, 2021

#79 in Graphics APIs

Download history 28/week @ 2022-12-01 87/week @ 2022-12-08 53/week @ 2022-12-15 6/week @ 2022-12-22 4/week @ 2022-12-29 6/week @ 2023-01-05 8/week @ 2023-01-12 5/week @ 2023-01-19 13/week @ 2023-01-26 6/week @ 2023-02-02 126/week @ 2023-02-09 122/week @ 2023-02-16 1/week @ 2023-02-23 3/week @ 2023-03-02 23/week @ 2023-03-09

177 downloads per month

MIT license

9.5MB
2K SLoC

mltg

mltg at crates.io mltg at docs.rs

Direct2D wrapper library

Usage overview

1. Create a mltg::Context and a mltg::Factory

let ctx = mltg::Context::new(mltg::Direct2D::new()?)?;
let factory = ctx.create_factory();

2. Create a render target

In the case of using winit.

let window_size = window.inner_size().to_logical::<f32>(window.scale_factor());
let mut render_target = ctx.create_render_target(
    window.raw_window_handle(), // winit window
    (window_size.width, window_size.height),
)?;

3. Create resources

For example, create the solid color brush.

let brush = factory.create_solid_color_brush((1.0, 1.0, 1.0, 1.0))?;

4. Draw

For example, draw the rectangle of filled color.

ctx.set_scale_factor(window.scale_factor() as _);
ctx.draw(&render_target, |cmd| {
    cmd.clear((0.0, 0.0, 0.3, 0.0));
    cmd.fill(
        &mltg::Rect::from_points((10.0, 10.0), (100.0, 100.0)),
        &brush,
    );
});

Copyright (c) 2021 LNSEAB

Dependencies

~172MB
~3M SLoC