Fetch bounds on window resize in visible_bounds example

This commit is contained in:
Héctor Ramón Jiménez 2023-07-27 01:29:20 +02:00
parent 34851c9c39
commit cbb5fcc882
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -5,6 +5,7 @@ use iced::theme::{self, Theme};
use iced::widget::{
column, container, horizontal_space, row, scrollable, text, vertical_space,
};
use iced::window;
use iced::{
Alignment, Application, Color, Command, Element, Event, Font, Length,
Point, Rectangle, Settings,
@ -23,6 +24,7 @@ struct Example {
#[derive(Debug, Clone, Copy)]
enum Message {
MouseMoved(Point),
WindowResized,
Scrolled(scrollable::Viewport),
OuterBoundsFetched(Option<Rectangle>),
InnerBoundsFetched(Option<Rectangle>),
@ -56,12 +58,14 @@ impl Application for Example {
Command::none()
}
Message::Scrolled(_) => Command::batch(vec![
Message::Scrolled(_) | Message::WindowResized => {
Command::batch(vec![
container::visible_bounds(OUTER_CONTAINER.clone())
.map(Message::OuterBoundsFetched),
container::visible_bounds(INNER_CONTAINER.clone())
.map(Message::InnerBoundsFetched),
]),
])
}
Message::OuterBoundsFetched(outer_bounds) => {
self.outer_bounds = outer_bounds;
@ -163,6 +167,9 @@ impl Application for Example {
Event::Mouse(mouse::Event::CursorMoved { position }) => {
Some(Message::MouseMoved(position))
}
Event::Window(window::Event::Resized { .. }) => {
Some(Message::WindowResized)
}
_ => None,
})
}