Native Windows Derive: Resources

The derive macro for the NWG resources works the exact same way as nwg_control, with a few less features because resources are much less complicated than controls.

Attributes

Just like controls, NWD translates the builder API of resources into a list of

nwg_resources(builder_field: builder_value,*)

Example:
pub struct App {
    #[nwg_resource(source_file: Some("./pencil.ico"), size: Some((16, 16)), strict: true )]
    pen_icon: nwg::Icon,
}


Unlike controls, resources cannot have a parent nor can they trigger events.

Self referencing

NWD will always initialize the resources before the controls. This means that it is possible to load resources and use them in a control using only the NWD attributes.

By appending the following format: data.{field}, it's possible to use the resources in the controls. As an example, here's how to load and display an image using only NWD.
#[derive(Default, NwgUi)]
pub struct ImageDisplay {
    #[nwg_resource(source_file: Some("dog.bmp"))]
    dog: nwg::Bitmap,

    #[nwg_control(size: (300, 300))]
    window: nwg::Window,

    #[nwg_control(bitmap: Some(&data.dog), size: (300, 300))]
    frame: nwg::ImageFrame
}