#[macro_export]
macro_rules! layout {
[ $ui:expr ,
let $ctl:ident = Button ( $text:expr )
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Button::new($text);
];
[ $ui:expr ,
let $ctl:ident = Checkbox ( $text:expr $( , checked: $checked:expr )? )
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Checkbox::new($text);
$( $ctl.set_checked($checked); )?
];
[ $ui:expr ,
let $ctl:ident = ColorButton ()
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::ColorButton::new();
];
[ $ui:expr ,
let $ctl:ident = Combobox ( $( selected: $selected:expr )? )
{ $( $option:expr ),* }
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Combobox::new();
$( $ctl.append($option); )*
$( $ctl.set_selected($selected); )?
];
[ $ui:expr ,
let $ctl:ident = DateTimePicker ( $kind:ident )
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::DateTimePicker::new(
libui::controls::DateTimePickerKind::$kind);
];
[ $ui:expr ,
let $ctl:ident = EditableCombobox ()
{ $( $option:expr ),* }
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::EditableCombobox::new();
$( $ctl.append($option); )*
];
[ $ui:expr ,
let $ctl:ident = Entry ()
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Entry::new();
];
[ $ui:expr ,
let $ctl:ident = FontButton ()
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::FontButton::new();
];
[ $ui:expr ,
let $ctl:ident = HorizontalSeparator ()
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::HorizontalSeparator::new();
];
[ $ui:expr ,
let $ctl:ident = Label ( $text:expr )
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Label::new($text);
];
[ $ui:expr ,
let $ctl:ident = MultilineEntry ()
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::MultilineEntry::new();
];
[ $ui:expr ,
let $ctl:ident = MultilineEntry ( wrapping: $wrapping:expr )
] => [
#[allow(unused_mut)]
let mut $ctl = if $wrapping {
libui::controls::MultilineEntry::new()
} else {
libui::controls::MultilineEntry::new_nonwrapping()
};
];
[ $ui:expr ,
let $ctl:ident = PasswordEntry ()
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::PasswordEntry::new();
];
[ $ui:expr ,
let $ctl:ident = RadioButtons ( $( selected: $selected:expr )? )
{ $( $option:expr ),* }
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::RadioButtons::new();
$( $ctl.append($option); )*
$( $ctl.set_selected($selected); )?
];
[ $ui:expr ,
let $ctl:ident = SearchEntry ()
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::SearchEntry::new();
];
[ $ui:expr ,
let $ctl:ident = Slider ( $min:expr , $max:expr )
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Slider::new($min, $max);
];
[ $ui:expr ,
let $ctl:ident = Spacer ()
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Spacer::new();
];
[ $ui:expr ,
let $ctl:ident = Spinbox ( $min:expr , $max:expr )
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Spinbox::new($min, $max);
];
[ $ui:expr ,
let $ctl:ident = Spinbox ()
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Spinbox::new_unlimited();
];
[ $ui:expr ,
let $ctl:ident = ProgressBar ()
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::ProgressBar::new();
];
[ $ui:expr ,
let $ctl:ident = Form ( $( padded: $padded:expr )? )
{ $(
( $strategy:ident, $name:expr ) :
let $child:ident = $type:ident ($($opt:tt)*) $({$($body:tt)*})?
)* }
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Form::new();
$( $ctl.set_padded($padded); )?
$(
libui::layout! { $ui, let $child = $type ($($opt)*) $({$($body)*})? }
$ctl.append($name, $child.clone(),
libui::controls::LayoutStrategy::$strategy);
)*
];
[ $ui:expr ,
let $ctl:ident = Group ( $title:expr $( , margined: $margined:expr )? )
{ $(
let $child:ident = $type:ident ($($opt:tt)*) $({$($body:tt)*})?
)? }
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::Group::new($title);
$( $ctl.set_margined($margined); )?
$(
libui::layout! { $ui, let $child = $type ($($opt)*) $({$($body)*})? }
$ctl.set_child($child.clone());
)?
];
[ $ui:expr ,
let $ctl:ident = HorizontalBox ( $( padded: $padded:expr )? )
{ $(
$strategy:ident :
let $child:ident = $type:ident ($($opt:tt)*) $({$($body:tt)*})?
)* }
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::HorizontalBox::new();
$( $ctl.set_padded($padded); )?
$(
libui::layout! { $ui, let $child = $type ($($opt)*) $({$($body)*})? }
$ctl.append($child.clone(),
libui::controls::LayoutStrategy::$strategy);
)*
];
[ $ui:expr ,
let $ctl:ident = LayoutGrid ( $( padded: $padded:expr )? )
{ $(
( $x:expr , $y:expr ) ( $xspan:expr , $yspan:expr )
$expand:ident ( $halign:ident , $valign:ident ) :
let $child:ident = $type:ident ($($opt:tt)*) $({$($body:tt)*})?
)* }
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::LayoutGrid::new();
$( $ctl.set_padded($padded); )?
$(
libui::layout! { $ui, let $child = $type ($($opt)*) $({$($body)*})? }
$ctl.append($child.clone(), $x, $y, $xspan, $yspan,
libui::controls::GridExpand::$expand,
libui::controls::GridAlignment::$halign,
libui::controls::GridAlignment::$valign);
)*
];
[ $ui:expr ,
let $ctl:ident = TabGroup ()
{ $(
( $name:expr $( , margined: $margined:expr )? ) :
let $child:ident = $type:ident ($($opt:tt)*) $({$($body:tt)*})?
)* }
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::TabGroup::new();
$(
libui::layout! { $ui, let $child = $type ($($opt)*) $({$($body)*})? }
let __tab_n = $ctl.append($name, $child.clone());
$( $ctl.set_margined(__tab_n - 1, $margined); )?
)*
];
[ $ui:expr ,
let $ctl:ident = VerticalBox ( $( padded: $padded:expr )? )
{ $(
$strategy:ident :
let $child:ident = $type:ident ($($opt:tt)*) $({$($body:tt)*})?
)* }
] => [
#[allow(unused_mut)]
let mut $ctl = libui::controls::VerticalBox::new();
$( $ctl.set_padded($padded); )?
$(
libui::layout! { $ui, let $child = $type ($($opt)*) $({$($body)*})? }
$ctl.append($child.clone(),
libui::controls::LayoutStrategy::$strategy);
)*
];
}
#[macro_export]
macro_rules! menu {
[@impl $parent:ident,] => [];
[@impl $parent:ident,
let $item:ident = MenuItem ( $text:expr )
$($tail:tt)*
] => [
#[allow(unused_mut)]
let mut $item = $parent.append_item($text);
libui::menu! { @impl $parent, $($tail)* }
];
[@impl $parent:ident,
let $item:ident = MenuItem ( $text:expr, checked: $checked:expr )
$($tail:tt)*
] => [
#[allow(unused_mut)]
let mut $item = $parent.append_check_item($text);
$item.set_checked($checked);
libui::menu! { @impl $parent, $($tail)* }
];
[@impl $parent:ident,
let $item:ident = AboutItem ( )
$($tail:tt)*
] => [
#[allow(unused_mut)]
let mut $item = $parent.append_about_item();
libui::menu! { @impl $parent, $($tail)* }
];
[@impl $parent:ident,
let $item:ident = QuitItem ( )
$($tail:tt)*
] => [
#[allow(unused_mut)]
let mut $item = $parent.append_quit_item();
libui::menu! { @impl $parent, $($tail)* }
];
[@impl $parent:ident,
let $item:ident = PreferencesItem ( )
$($tail:tt)*
] => [
#[allow(unused_mut)]
let mut $item = $parent.append_preferences_item();
libui::menu! { @impl $parent, $($tail)* }
];
[@impl $parent:ident,
Separator ( )
$($tail:tt)*
] => [
$parent.append_separator();
libui::menu! { @impl $parent, $($tail)* }
];
[ $ui:expr ,
$(
let $menu:ident = Menu ( $name:expr )
{
$($tail:tt)*
}
)+
] => [
$(
#[allow(unused_mut)]
let mut $menu = libui::menus::Menu::new( $name );
libui::menu! { @impl $menu, $($tail)* }
)+
];
}