summaryrefslogtreecommitdiffstats
path: root/examples/visible_bounds
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-07-27 01:29:20 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-07-27 01:29:20 +0200
commitcbb5fcc8829e6fbe60f97cad8597c86ffd4f5b1a (patch)
treedb1d0c010ef6a2f02b17ff0daee204658488e21d /examples/visible_bounds
parent34851c9c394f1200be613c3947acc418ed69f2a7 (diff)
downloadiced-cbb5fcc8829e6fbe60f97cad8597c86ffd4f5b1a.tar.gz
iced-cbb5fcc8829e6fbe60f97cad8597c86ffd4f5b1a.tar.bz2
iced-cbb5fcc8829e6fbe60f97cad8597c86ffd4f5b1a.zip
Fetch bounds on window resize in `visible_bounds` example
Diffstat (limited to 'examples/visible_bounds')
-rw-r--r--examples/visible_bounds/src/main.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/examples/visible_bounds/src/main.rs b/examples/visible_bounds/src/main.rs
index 8bc645b7..8b684514 100644
--- a/examples/visible_bounds/src/main.rs
+++ b/examples/visible_bounds/src/main.rs
@@ -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![
- container::visible_bounds(OUTER_CONTAINER.clone())
- .map(Message::OuterBoundsFetched),
- container::visible_bounds(INNER_CONTAINER.clone())
- .map(Message::InnerBoundsFetched),
- ]),
+ 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,
})
}