fix: embed spin button and warning icons on non-linux systems
This commit is contained in:
parent
c42b8ff5a5
commit
d4a87bd394
4 changed files with 40 additions and 35 deletions
3
res/icons/list-add-symbolic.svg
Normal file
3
res/icons/list-add-symbolic.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M8 3C7.73478 3 7.48043 3.10536 7.29289 3.29289C7.10536 3.48043 7 3.73478 7 4V6.996L4 7C3.73478 7 3.48043 7.10536 3.29289 7.29289C3.10536 7.48043 3 7.73478 3 8C3 8.26522 3.10536 8.51957 3.29289 8.70711C3.48043 8.89464 3.73478 9 4 9L7 8.996V12C7 12.2652 7.10536 12.5196 7.29289 12.7071C7.48043 12.8946 7.73478 13 8 13C8.26522 13 8.51957 12.8946 8.70711 12.7071C8.89464 12.5196 9 12.2652 9 12V8.996L12 9C12.2652 9 12.5196 8.89464 12.7071 8.70711C12.8946 8.51957 13 8.26522 13 8C13 7.73478 12.8946 7.48043 12.7071 7.29289C12.5196 7.10536 12.2652 7 12 7L9 6.996V4C9 3.73478 8.89464 3.48043 8.70711 3.29289C8.51957 3.10536 8.26522 3 8 3Z" fill="#232323"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 762 B |
3
res/icons/list-remove-symbolic.svg
Normal file
3
res/icons/list-remove-symbolic.svg
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M4 7C3.73478 7 3.48043 7.10536 3.29289 7.29289C3.10536 7.48043 3 7.73478 3 8C3 8.26522 3.10536 8.51957 3.29289 8.70711C3.48043 8.89464 3.73478 9 4 9H12C12.2652 9 12.5196 8.89464 12.7071 8.70711C12.8946 8.51957 13 8.26522 13 8C13 7.73478 12.8946 7.48043 12.7071 7.29289C12.5196 7.10536 12.2652 7 12 7H4Z" fill="#232323"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 433 B |
|
|
@ -149,29 +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 decrement_button = icon::from_name("list-remove-symbolic")
|
let decrement_button = make_button!(spin_button, "list-remove-symbolic", decrement);
|
||||||
.apply(button::icon)
|
let increment_button = make_button!(spin_button, "list-add-symbolic", increment);
|
||||||
.on_press((spin_button.on_press)(decrement::<T>(
|
|
||||||
spin_button.value,
|
|
||||||
spin_button.step,
|
|
||||||
spin_button.min,
|
|
||||||
spin_button.max,
|
|
||||||
)));
|
|
||||||
|
|
||||||
let increment_button = icon::from_name("list-add-symbolic")
|
|
||||||
.apply(button::icon)
|
|
||||||
.on_press((spin_button.on_press)(increment::<T>(
|
|
||||||
spin_button.value,
|
|
||||||
spin_button.step,
|
|
||||||
spin_button.min,
|
|
||||||
spin_button.max,
|
|
||||||
)));
|
|
||||||
|
|
||||||
let label = text::title4(spin_button.label)
|
let label = text::title4(spin_button.label)
|
||||||
.apply(container)
|
.apply(container)
|
||||||
|
|
@ -193,23 +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 decrement_button = icon::from_name("list-remove-symbolic")
|
let decrement_button = make_button!(spin_button, "list-remove-symbolic", decrement);
|
||||||
.apply(button::icon)
|
let increment_button = make_button!(spin_button, "list-add-symbolic", increment);
|
||||||
.on_press((spin_button.on_press)(decrement::<T>(
|
|
||||||
spin_button.value,
|
|
||||||
spin_button.step,
|
|
||||||
spin_button.min,
|
|
||||||
spin_button.max,
|
|
||||||
)));
|
|
||||||
|
|
||||||
let increment_button = icon::from_name("list-add-symbolic")
|
|
||||||
.apply(button::icon)
|
|
||||||
.on_press((spin_button.on_press)(increment::<T>(
|
|
||||||
spin_button.value,
|
|
||||||
spin_button.step,
|
|
||||||
spin_button.min,
|
|
||||||
spin_button.max,
|
|
||||||
)));
|
|
||||||
|
|
||||||
let label = text::title4(spin_button.label)
|
let label = text::title4(spin_button.label)
|
||||||
.apply(container)
|
.apply(container)
|
||||||
|
|
@ -263,4 +252,4 @@ mod tests {
|
||||||
fn decrement() {
|
fn decrement() {
|
||||||
assert_eq!(super::decrement(0i32, 10, 15, 35), 15);
|
assert_eq!(super::decrement(0i32, 10, 15, 35), 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -33,11 +33,21 @@ impl<'a, Message: 'static + Clone> Warning<'a, Message> {
|
||||||
pub fn into_widget(self) -> widget::Container<'a, Message, crate::Theme, Renderer> {
|
pub fn into_widget(self) -> widget::Container<'a, Message, crate::Theme, Renderer> {
|
||||||
let label = widget::container(crate::widget::text(self.message)).width(Length::Fill);
|
let label = widget::container(crate::widget::text(self.message)).width(Length::Fill);
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
let close_button = icon::from_name("window-close-symbolic")
|
let close_button = icon::from_name("window-close-symbolic")
|
||||||
.size(16)
|
.size(16)
|
||||||
.apply(widget::button::icon)
|
.apply(widget::button::icon)
|
||||||
.on_press_maybe(self.on_close);
|
.on_press_maybe(self.on_close);
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
let close_button = icon::from_svg_bytes(
|
||||||
|
include_bytes!("../../res/icons/window-close-symbolic.svg")
|
||||||
|
)
|
||||||
|
.symbolic(true)
|
||||||
|
.apply(widget::button::icon)
|
||||||
|
.icon_size(16)
|
||||||
|
.on_press_maybe(self.on_close);
|
||||||
|
|
||||||
widget::row::with_capacity(2)
|
widget::row::with_capacity(2)
|
||||||
.push(label)
|
.push(label)
|
||||||
.push(close_button)
|
.push(close_button)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue