diff options
author | 2019-10-03 00:08:16 +0200 | |
---|---|---|
committer | 2019-10-03 00:08:16 +0200 | |
commit | 63294088ad6e1523c6b7623c08f82af2812a5531 (patch) | |
tree | 50e0c34562426c139354ccf765ef19bd523ed17e /src | |
parent | e1b9d42bf1443ae4958aa9303255ef19c635debb (diff) | |
download | iced-63294088ad6e1523c6b7623c08f82af2812a5531.tar.gz iced-63294088ad6e1523c6b7623c08f82af2812a5531.tar.bz2 iced-63294088ad6e1523c6b7623c08f82af2812a5531.zip |
Open a window using `winit`
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -1,7 +1,7 @@ pub use iced_wgpu::Renderer; pub use iced_winit::{ - button, slider, text, Align, Button, Checkbox, Color, Image, Justify, - Length, Radio, Slider, Text, + button, slider, text, winit, Align, Button, Checkbox, Color, Image, + Justify, Length, Radio, Slider, Text, }; pub type Element<'a, Message> = iced_winit::Element<'a, Message, Renderer>; @@ -19,5 +19,32 @@ pub trait UserInterface { where Self: Sized, { + use winit::{ + event::{Event, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + window::WindowBuilder, + }; + + let event_loop = EventLoop::new(); + + // TODO: Ask for window settings and configure this properly + let window = WindowBuilder::new() + .build(&event_loop) + .expect("Open window"); + + event_loop.run(move |event, _, control_flow| match event { + Event::EventsCleared => { + window.request_redraw(); + } + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } => { + *control_flow = ControlFlow::Exit; + } + _ => { + *control_flow = ControlFlow::Poll; + } + }) } } |