Attribute Macro glib_macros::flags

source · []
#[flags]
Expand description

Attribute macro for defining flags using the bitflags crate. This macro will also define a GFlags::type_ function and the glib::Value traits.

The expected GType name has to be passed as macro attribute. The name and nick of each flag can also be optionally defined. Default name is the flag identifier in CamelCase and default nick is the identifier in kebab-case. Combined flags should not be registered with the GType system and so needs to be tagged with the #[flags_value(skip)] attribute.

Example

use glib::prelude::*;
use glib::subclass::prelude::*;

#[glib::flags(name = "MyFlags")]
enum MyFlags {
    #[flags_value(name = "Flag A", nick = "nick-a")]
    A = 0b00000001,
    #[flags_value(name = "Flag B")]
    B = 0b00000010,
    #[flags_value(skip)]
    AB = Self::A.bits() | Self::B.bits(),
    C = 0b00000100,
}