[][src]Macro conrod::widget_ids

macro_rules! widget_ids {
    ($(#[$attr:meta])*     struct $Ids:ident { $($id:tt)* }) => { ... };
    ($(#[$attr:meta])* pub struct $Ids:ident { $($id:tt)* }) => { ... };
    (implement $(#[$attr:meta])* [$($public:tt)*] $Ids:ident { $($id:tt)* }) => { ... };
    (define_struct $(#[$attr:meta])* [$($public:tt)*] $Ids:ident {
        { $($id_field:ident: $T:path,)* } $id:ident[], $($rest:tt)*
    }) => { ... };
    (define_struct $(#[$attr:meta])* [$($public:tt)*] $Ids:ident {
        { $($id_field:ident: $T:path,)* } $id:ident, $($rest:tt)*
    }) => { ... };
    (define_struct $(#[$attr:meta])* [$($public:tt)*] $Ids:ident {
        { $($id_field:ident: $T:path,)* } $id:ident[]
    }) => { ... };
    (define_struct $(#[$attr:meta])* [$($public:tt)*] $Ids:ident {
        { $($id_field:ident: $T:path,)* } $id:ident
    }) => { ... };
    (define_struct $(#[$attr:meta])* [pub] $Ids:ident { { $($id:ident: $T:path,)* } }) => { ... };
    (define_struct $(#[$attr:meta])* [] $Ids:ident { { $($id:ident: $T:path,)* } }) => { ... };
    (constructor $Ids:ident, $generator:ident {
        { $($id_field:ident: $new:expr,)* } $id:ident[], $($rest:tt)*
    }) => { ... };
    (constructor $Ids:ident, $generator:ident {
        { $($id_field:ident: $new:expr,)* } $id:ident, $($rest:tt)*
    }) => { ... };
    (constructor $Ids:ident, $generator:ident {
        { $($id_field:ident: $new:expr,)* } $id:ident[]
    }) => { ... };
    (constructor $Ids:ident, $generator:ident {
        { $($id_field:ident: $new:expr,)* } $id:ident
    }) => { ... };
    (constructor $Ids:ident, $generator:ident { { $($id:ident: $new:expr,)* } }) => { ... };
}

A macro used to generate a struct with a field for each unique identifier given. Each field can then be used to generate unique widget::Ids.

For example, given the following invocation:

#[macro_use]
extern crate conrod;

widget_ids! {
    struct Ids {
        button,
        toggles[],
    }
}

The following will be produced:

struct Ids {
    button: conrod::widget::Id,
    toggles: conrod::widget::id::List,
}

impl Ids {
    pub fn new(mut generator: conrod::widget::id::Generator) -> Self {
        Ids {
            button: generator.next(),
            toggles: conrod::widget::id::List::new(),
        }
    }
}

In the example above, the generated Ids type can be used as follows.

This example is not tested
widget::Button::new().set(ids.button, ui);
 
ids.toggles.resize(5, &mut ui.widget_id_generator());
for &id in &ids.toggles {
    widget::Toggle::new(true).set(id, ui);
}