use super::Task;
use iced::widget::{self, scrollable};
use iced::{advanced, window};
use iced_runtime::Action;
use std::convert::Infallible;
pub fn clipboard_write<T>(contents: String) -> Task<T> {
#[cfg(not(any(test, feature = "testing")))]
let task = iced::clipboard::write(contents);
#[cfg(any(test, feature = "testing"))]
let task = {
let _ = contents;
Task::none()
};
task
}
pub fn effect<T>(action: impl Into<Action<Infallible>>) -> Task<T> {
#[cfg(not(any(test, feature = "testing")))]
let task = iced_runtime::task::effect(action);
#[cfg(any(test, feature = "testing"))]
let task = {
let _ = action;
Task::none()
};
task
}
pub fn scroll_by<T>(
id: impl Into<widget::Id>,
offset: scrollable::AbsoluteOffset,
) -> Task<T> {
#[cfg(not(any(test, feature = "testing")))]
let task = widget::operation::scroll_by(id, offset);
#[cfg(any(test, feature = "testing"))]
let task = {
let _ = (id, offset);
Task::none()
};
task
}
pub fn scroll_to<T>(
id: impl Into<widget::Id>,
offset: scrollable::AbsoluteOffset,
) -> Task<T> {
#[cfg(not(any(test, feature = "testing")))]
let task = widget::operation::scroll_to(id, offset);
#[cfg(any(test, feature = "testing"))]
let task = {
let _ = (id, offset);
Task::none()
};
task
}
pub fn widget_focus_next<T>() -> Task<T> {
#[cfg(not(any(test, feature = "testing")))]
let task = widget::operation::focus_next();
#[cfg(any(test, feature = "testing"))]
let task = Task::none();
task
}
pub fn widget_focus_previous<T>() -> Task<T> {
#[cfg(not(any(test, feature = "testing")))]
let task = widget::operation::focus_previous();
#[cfg(any(test, feature = "testing"))]
let task = Task::none();
task
}
pub fn widget_operate<T>(
operation: impl advanced::widget::Operation<T> + 'static,
) -> Task<T>
where
T: Send + 'static,
{
#[cfg(not(any(test, feature = "testing")))]
let task = advanced::widget::operate(operation);
#[cfg(any(test, feature = "testing"))]
let task = {
let _ = operation;
Task::none()
};
task
}
pub fn window_open(
settings: window::Settings,
) -> (window::Id, Task<window::Id>) {
#[cfg(not(any(test, feature = "testing")))]
let (window_id, task) = window::open(settings);
#[cfg(any(test, feature = "testing"))]
let (window_id, task) = {
let _ = settings;
let id = window::Id::unique();
(id, Task::done(id))
};
(window_id, task)
}
pub fn window_set_icon<T>(window_id: window::Id, icon_bytes: Vec<u8>) -> Task<T>
where
T: Send + 'static,
{
#[cfg(not(any(test, feature = "testing")))]
let set_icon_task = Task::future(async move {
use image::ImageFormat;
window::icon::from_file_data(&icon_bytes, Some(ImageFormat::Png))
.unwrap_or_else(|err| {
panic!("unable to decode PNG icon bytes: {err:?}",)
})
})
.then(move |icon| window::set_icon(window_id, icon));
#[cfg(any(test, feature = "testing"))]
let set_icon_task = {
let _ = (window_id, icon_bytes);
Task::none()
};
set_icon_task
}