Move make_button into a macro
This commit is contained in:
parent
e21c027a52
commit
929aa1e33f
1 changed files with 24 additions and 41 deletions
|
|
@ -149,32 +149,33 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
macro_rules! make_button {
|
||||||
|
($spin_button:expr, $icon:expr, $operation:expr) => {{
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
let button = icon::from_name($icon);
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
let button = icon::from_svg_bytes(
|
||||||
|
include_bytes!(concat!["../../res/icons/", $icon ,".svg"])
|
||||||
|
).symbolic(true);
|
||||||
|
|
||||||
|
button.apply(button::icon)
|
||||||
|
.on_press(($spin_button.on_press)($operation(
|
||||||
|
$spin_button.value,
|
||||||
|
$spin_button.step,
|
||||||
|
$spin_button.min,
|
||||||
|
$spin_button.max,
|
||||||
|
)))
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
fn horizontal_variant<T, Message>(spin_button: SpinButton<'_, T, Message>) -> Element<'_, Message>
|
fn horizontal_variant<T, Message>(spin_button: SpinButton<'_, T, Message>) -> Element<'_, Message>
|
||||||
where
|
where
|
||||||
Message: Clone + 'static,
|
Message: Clone + 'static,
|
||||||
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
|
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
|
||||||
{
|
{
|
||||||
let make_button = | icon, operation: fn(T,T,T,T)->T | {
|
let decrement_button = make_button!(spin_button, "list-remove-symbolic", decrement);
|
||||||
#[cfg(target_os = "linux")]
|
let increment_button = make_button!(spin_button, "list-add-symbolic", increment);
|
||||||
let button = icon::from_name(icon);
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
|
||||||
let button = icon::from_svg_bytes(
|
|
||||||
include_bytes!(concat!["../../res/icons/", icon ,".svg"])
|
|
||||||
).symbolic(true);
|
|
||||||
|
|
||||||
button.apply(button::icon)
|
|
||||||
.on_press((spin_button.on_press)(operation(
|
|
||||||
spin_button.value,
|
|
||||||
spin_button.step,
|
|
||||||
spin_button.min,
|
|
||||||
spin_button.max,
|
|
||||||
)))
|
|
||||||
};
|
|
||||||
|
|
||||||
let decrement_button = make_button("list-remove-symbolic", decrement);
|
|
||||||
let increment_button = make_button("list-add-symbolic", increment);
|
|
||||||
|
|
||||||
let label = text::title4(spin_button.label)
|
let label = text::title4(spin_button.label)
|
||||||
.apply(container)
|
.apply(container)
|
||||||
|
|
@ -196,26 +197,8 @@ where
|
||||||
Message: Clone + 'static,
|
Message: Clone + 'static,
|
||||||
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
|
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
|
||||||
{
|
{
|
||||||
let make_button = | icon, operation: fn(T,T,T,T)->T | {
|
let decrement_button = make_button!(spin_button, "list-remove-symbolic", decrement);
|
||||||
#[cfg(target_os = "linux")]
|
let increment_button = make_button!(spin_button, "list-add-symbolic", increment);
|
||||||
let button = icon::from_name(icon);
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
|
||||||
let button = icon::from_svg_bytes(
|
|
||||||
include_bytes!(concat!["../../res/icons/", icon ,".svg"])
|
|
||||||
).symbolic(true);
|
|
||||||
|
|
||||||
button.apply(button::icon)
|
|
||||||
.on_press((spin_button.on_press)(operation(
|
|
||||||
spin_button.value,
|
|
||||||
spin_button.step,
|
|
||||||
spin_button.min,
|
|
||||||
spin_button.max,
|
|
||||||
)))
|
|
||||||
};
|
|
||||||
|
|
||||||
let decrement_button = make_button("list-remove-symbolic", decrement);
|
|
||||||
let increment_button = make_button("list-add-symbolic", increment);
|
|
||||||
|
|
||||||
let label = text::title4(spin_button.label)
|
let label = text::title4(spin_button.label)
|
||||||
.apply(container)
|
.apply(container)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue