diff options
Diffstat (limited to 'examples/modal/src/main.rs')
-rw-r--r-- | examples/modal/src/main.rs | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs index 7fcbbfe4..acb14372 100644 --- a/examples/modal/src/main.rs +++ b/examples/modal/src/main.rs @@ -1,12 +1,14 @@ +use iced::event::{self, Event}; use iced::executor; use iced::keyboard; -use iced::subscription::{self, Subscription}; use iced::theme; use iced::widget::{ self, button, column, container, horizontal_space, pick_list, row, text, text_input, }; -use iced::{Alignment, Application, Command, Element, Event, Length, Settings}; +use iced::{ + Alignment, Application, Command, Element, Length, Settings, Subscription, +}; use modal::Modal; use std::fmt; @@ -49,7 +51,7 @@ impl Application for App { } fn subscription(&self) -> Subscription<Self::Message> { - subscription::events().map(Message::Event) + event::listen().map(Message::Event) } fn update(&mut self, message: Message) -> Command<Message> { @@ -203,7 +205,8 @@ enum Plan { } impl Plan { - pub const ALL: &[Self] = &[Self::Basic, Self::Pro, Self::Enterprise]; + pub const ALL: &'static [Self] = + &[Self::Basic, Self::Pro, Self::Enterprise]; } impl fmt::Display for Plan { @@ -226,7 +229,10 @@ mod modal { use iced::alignment::Alignment; use iced::event; use iced::mouse; - use iced::{Color, Element, Event, Length, Point, Rectangle, Size}; + use iced::{ + BorderRadius, Color, Element, Event, Length, Point, Rectangle, Size, + Vector, + }; /// A widget that centers a modal element over some base element pub struct Modal<'a, Message, Renderer> { @@ -285,10 +291,15 @@ mod modal { fn layout( &self, + tree: &mut widget::Tree, renderer: &Renderer, limits: &layout::Limits, ) -> layout::Node { - self.base.as_widget().layout(renderer, limits) + self.base.as_widget().layout( + &mut tree.children[0], + renderer, + limits, + ) } fn on_event( @@ -300,6 +311,7 @@ mod modal { renderer: &Renderer, clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, + viewport: &Rectangle, ) -> event::Status { self.base.as_widget_mut().on_event( &mut state.children[0], @@ -309,6 +321,7 @@ mod modal { renderer, clipboard, shell, + viewport, ) } @@ -397,16 +410,21 @@ mod modal { Message: Clone, { fn layout( - &self, + &mut self, renderer: &Renderer, _bounds: Size, position: Point, + _translation: Vector, ) -> layout::Node { let limits = layout::Limits::new(Size::ZERO, self.size) .width(Length::Fill) .height(Length::Fill); - let mut child = self.content.as_widget().layout(renderer, &limits); + let mut child = self + .content + .as_widget() + .layout(self.tree, renderer, &limits); + child.align(Alignment::Center, Alignment::Center, limits.max()); let mut node = layout::Node::with_children(self.size, vec![child]); @@ -446,6 +464,7 @@ mod modal { renderer, clipboard, shell, + &layout.bounds(), ) } @@ -460,7 +479,7 @@ mod modal { renderer.fill_quad( renderer::Quad { bounds: layout.bounds(), - border_radius: Default::default(), + border_radius: BorderRadius::default(), border_width: 0.0, border_color: Color::TRANSPARENT, }, |