feat(icon): optimize & bundle icons with crabtime for non-unix platforms

This commit is contained in:
Michael Aaron Murphy 2025-11-11 23:02:57 +01:00 committed by Michael Murphy
parent ce0868582b
commit 639326fcc3
27 changed files with 128 additions and 189 deletions

View file

@ -115,7 +115,7 @@ where
}
}
fn increment<T>(value: T, step: T, min: T, max: T) -> T
fn increment<T>(value: T, step: T, _min: T, max: T) -> T
where
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
{
@ -126,7 +126,7 @@ where
}
}
fn decrement<T>(value: T, step: T, min: T, max: T) -> T
fn decrement<T>(value: T, step: T, min: T, _max: T) -> T
where
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
{
@ -149,25 +149,25 @@ 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 make_button<'a, T, Message>(
spin_button: &SpinButton<'a, T, Message>,
icon: &'static str,
operation: fn(T, T, T, T) -> T,
) -> Element<'a, Message>
where
Message: Clone + 'static,
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
{
icon::from_name(icon)
.apply(button::icon)
.on_press((spin_button.on_press)(operation(
spin_button.value,
spin_button.step,
spin_button.min,
spin_button.max,
)))
.into()
}
fn horizontal_variant<T, Message>(spin_button: SpinButton<'_, T, Message>) -> Element<'_, Message>
@ -175,8 +175,8 @@ where
Message: Clone + 'static,
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
{
let decrement_button = make_button!(spin_button, "list-remove-symbolic", decrement);
let increment_button = make_button!(spin_button, "list-add-symbolic", increment);
let decrement_button = make_button(&spin_button, "list-remove-symbolic", decrement);
let increment_button = make_button(&spin_button, "list-add-symbolic", increment);
let label = text::body(spin_button.label)
.apply(container)
@ -198,8 +198,8 @@ where
Message: Clone + 'static,
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
{
let decrement_button = make_button!(spin_button, "list-remove-symbolic", decrement);
let increment_button = make_button!(spin_button, "list-add-symbolic", increment);
let decrement_button = make_button(&spin_button, "list-remove-symbolic", decrement);
let increment_button = make_button(&spin_button, "list-add-symbolic", increment);
let label = text::body(spin_button.label)
.apply(container)