[−][src]Macro vgtk::gtk_if
Generate a virtual component tree only if a condition is true.
You'll very often want to insert a widget only if a certain condition is true,
and insert nothing at all otherwise. This macro automates this common pattern.
It will validate your condition, and if true, it will return a VNodeIterator
containing the widget tree you specify. If false, it will use VNode::empty()
to make an empty iterator.
Examples
let buttons = 2; gtk! { <Box> <Button label="Button 1" /> { gtk_if!(buttons == 2 => { <Button label="Button 2" /> }) } </Box> }
This generates code equivalent to the following, which is how you'd do it without the macro:
let buttons = 2; gtk! { <Box> <Button label="Button 1" /> { if buttons == 2 { gtk!(<Button label="Button 2" />).into_iter() } else { VNode::empty() } } </Box> }