Commit e0146533 authored by Felix Häcker's avatar Felix Häcker

Merge branch 'cdavis/add-style-class-macro' into 'master'

lib: Add `add_style_class` macro

See merge request !5
parents 675d2dab 4ad626ef
Pipeline #209430 passed with stages
in 8 minutes and 37 seconds
......@@ -248,3 +248,53 @@ macro_rules! get_action {
.unwrap();
};
}
/// Add a style class or list of style classes to a widget
///
/// - Before:
///
/// Example 1:
///
/// ```no_run
/// let button = gtk::Button::new();
/// let ctx = button.get_style_context();
/// ctx.add_class("foo");
/// ```
///
/// Example 2:
///
/// ```no_run
/// let button = gtk::Button::new();
/// let ctx = button.get_style_context();
/// ctx.add_class("foo");
/// ctx.add_class("bar");
/// ```
///
/// - After:
///
/// Example 1:
///
/// ```no_run
/// let button = gtk::Button::new();
/// add_style_class!(button, @foo);
/// ```
///
/// Example 2:
///
/// ```no_run
/// let button = gtk::Button::new();
/// add_style_class!(button, &["foo", "bar"]);
/// ```
#[macro_export]
macro_rules! add_style_class {
($widget:expr, @$name:ident) => {{
let ctx = $widget.get_style_context();
ctx.add_class(stringify!($name));
}};
($widget:expr, $names:expr) => {{
let ctx = $widget.get_style_context();
for name in $names {
ctx.add_class(name);
}
}};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment