Native Windows Derive: Partials

Native-windows-derive fully supports partials UI. It works the same way as NwgUi.

Deriving a Partial

Deriving a partial from a structure is done using the NwgPartial derive:
#[derive(NwgPartial)]
pub struct MyPartial {
    #[nwg_layout(max_size: [1000, 150], min_size: [100, 120])]
    layout: nwg::GridLayout,

    #[nwg_control(text: "Name:", h_align: HTextAlign::Right)]
    #[nwg_layout_item(layout: layout, col: 0, row: 0)]
    #[nwg_events(OnLabelClick: [MyPartial::test])]
    label1: nwg::Label,
}

NwgPartials accepts the same tag as NwgUi: nwg_control, nwg_resource, nwg_events, nwg_layout, nwg_layout_item, and nwg_partial.

Adding a partial to another UI

If a partial is added as a field in another UI struct, it must be tagged using nwg_partial. Optionally, a parent parameter can be passed to send the partial parent.
#[derive(NwgUi)]
pub struct MyUi {
    #[nwg_control]
    frame: nwg::Frame,

    #[nwg_partial(parent: frame)]
    partial: MyPartial
}

Hooking events in partial from their parent

Partials are self contained, this means that it's impossible to propagate an event "up" to the parent. To fix this, the nwg_events tag can accepts a struct field name, allowing you to catch an event raised in a partial from the parent.

This works by extending the nwg_events this way:
nwg_events((FIELD_NAME, EVENT): [CALLBACK_LIST,])

#[derive(NwgUi)]
pub struct MyUi {
    #[nwg_control]
    frame: nwg::Frame,

    #[nwg_partial(parent: frame)]
    #[nwg_events((button, OnButtonClick): [MyUi::save])]
    partial: MyPartial
}

#[derive(NwgPartial)]
pub struct MyPartial {
    #[nwg_control]
    button: nwg::Button,
}