Fetch bounds on window resize in visible_bounds example
This commit is contained in:
parent
34851c9c39
commit
cbb5fcc882
1 changed files with 13 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ use iced::theme::{self, Theme};
|
||||||
use iced::widget::{
|
use iced::widget::{
|
||||||
column, container, horizontal_space, row, scrollable, text, vertical_space,
|
column, container, horizontal_space, row, scrollable, text, vertical_space,
|
||||||
};
|
};
|
||||||
|
use iced::window;
|
||||||
use iced::{
|
use iced::{
|
||||||
Alignment, Application, Color, Command, Element, Event, Font, Length,
|
Alignment, Application, Color, Command, Element, Event, Font, Length,
|
||||||
Point, Rectangle, Settings,
|
Point, Rectangle, Settings,
|
||||||
|
|
@ -23,6 +24,7 @@ struct Example {
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum Message {
|
enum Message {
|
||||||
MouseMoved(Point),
|
MouseMoved(Point),
|
||||||
|
WindowResized,
|
||||||
Scrolled(scrollable::Viewport),
|
Scrolled(scrollable::Viewport),
|
||||||
OuterBoundsFetched(Option<Rectangle>),
|
OuterBoundsFetched(Option<Rectangle>),
|
||||||
InnerBoundsFetched(Option<Rectangle>),
|
InnerBoundsFetched(Option<Rectangle>),
|
||||||
|
|
@ -56,12 +58,14 @@ impl Application for Example {
|
||||||
|
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
Message::Scrolled(_) => Command::batch(vec![
|
Message::Scrolled(_) | Message::WindowResized => {
|
||||||
container::visible_bounds(OUTER_CONTAINER.clone())
|
Command::batch(vec![
|
||||||
.map(Message::OuterBoundsFetched),
|
container::visible_bounds(OUTER_CONTAINER.clone())
|
||||||
container::visible_bounds(INNER_CONTAINER.clone())
|
.map(Message::OuterBoundsFetched),
|
||||||
.map(Message::InnerBoundsFetched),
|
container::visible_bounds(INNER_CONTAINER.clone())
|
||||||
]),
|
.map(Message::InnerBoundsFetched),
|
||||||
|
])
|
||||||
|
}
|
||||||
Message::OuterBoundsFetched(outer_bounds) => {
|
Message::OuterBoundsFetched(outer_bounds) => {
|
||||||
self.outer_bounds = outer_bounds;
|
self.outer_bounds = outer_bounds;
|
||||||
|
|
||||||
|
|
@ -163,6 +167,9 @@ impl Application for Example {
|
||||||
Event::Mouse(mouse::Event::CursorMoved { position }) => {
|
Event::Mouse(mouse::Event::CursorMoved { position }) => {
|
||||||
Some(Message::MouseMoved(position))
|
Some(Message::MouseMoved(position))
|
||||||
}
|
}
|
||||||
|
Event::Window(window::Event::Resized { .. }) => {
|
||||||
|
Some(Message::WindowResized)
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue