diff options
Diffstat (limited to 'winit/src/application')
| -rw-r--r-- | winit/src/application/state.rs | 19 | 
1 files changed, 18 insertions, 1 deletions
diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs index b54d3aed..f60f09be 100644 --- a/winit/src/application/state.rs +++ b/winit/src/application/state.rs @@ -1,5 +1,5 @@  use crate::conversion; -use crate::{Application, Color, Debug, Mode, Point, Size, Viewport}; +use crate::{Application, Color, Debug, Menu, Mode, Point, Size, Viewport};  use std::marker::PhantomData;  use winit::event::{Touch, WindowEvent}; @@ -9,6 +9,7 @@ use winit::window::Window;  #[derive(Debug, Clone)]  pub struct State<A: Application> {      title: String, +    menu: Menu<A::Message>,      mode: Mode,      background_color: Color,      scale_factor: f64, @@ -23,6 +24,7 @@ impl<A: Application> State<A> {      /// Creates a new [`State`] for the provided [`Application`] and window.      pub fn new(application: &A, window: &Window) -> Self {          let title = application.title(); +        let menu = application.menu();          let mode = application.mode();          let background_color = application.background_color();          let scale_factor = application.scale_factor(); @@ -38,6 +40,7 @@ impl<A: Application> State<A> {          Self {              title, +            menu,              mode,              background_color,              scale_factor, @@ -50,6 +53,11 @@ impl<A: Application> State<A> {          }      } +    /// Returns the current [`Menu`] of the [`State`]. +    pub fn menu(&self) -> &Menu<A::Message> { +        &self.menu +    } +      /// Returns the current background [`Color`] of the [`State`].      pub fn background_color(&self) -> Color {          self.background_color @@ -203,5 +211,14 @@ impl<A: Application> State<A> {              self.scale_factor = new_scale_factor;          } + +        // Update menu +        let new_menu = application.menu(); + +        if self.menu != new_menu { +            window.set_menu(Some(conversion::menu(&new_menu))); + +            self.menu = new_menu; +        }      }  }  | 
