Hello! I am trying to create a button that resets the window to its default size, however, to get the window ID seems confusing. How can I run a task? I have tried to use:
enum MessageWindow
{
CheckLatestWindowId,
LatestWindowIdRetrieved(Option<iced::window::Id>),
}
Task::perform(iced::window::get_oldest(), MessageWindow::LatestWindowIdRetrieved);
But I get Task<Option<iced::window::Id>>
is not a future` error.
1 Like
You don’t even need an interim message at all, just create a task like this:
window::get_latest().and_then(move |id| window::resize(id, (400.0, 500.0).into())
The way I intuitively think about it is I’m having the result of the first task be processed by some other function within the runtime rather than sending it back to my app for processing it via an fn update
. It’s a bit of an “a-ha” moment at first, because it’s a different concept from what you’re used to encounter in the basic view-emits-message-update-handles-message rinse-and-repeat cycle.
More info here: Task in iced - Rust
Some other iced::window
examples in this toy repo:
1 Like
Thank you, that worked! There is an issue however, that all elements on the window seem to be warped when it is resized by the window::resize
function (it gets fixed when I resize it manually again). Is there an explicit method to request a redraw or a refresh of the UI? I’ve found this RedrawRequest in iced::window - Rust but no idea how to use it.
I don’t think you can manually request a redraw without having access to the Shell
, which to my knowledge is only available in Widget
implementations (but I haven’t explored the entire codebase so I could be wrong!)
That may be a bug. Are you running 0.13
, master
or something older?
It is 0.13, here is my Cargo.toml:
iced = { version = "0.13", default-features = false, features = [
"wgpu",
"tiny-skia",
"image",
"svg",
"fira-sans",
"tokio",
"lazy",
"advanced",
"multi-window",
"tokio",
"async-std",
"smol",
]}
I’ll open an issue about this, thanks again for taking the time to help!