Struct ActiveEventLoop

Source
pub struct ActiveEventLoop { /* private fields */ }
Expand description

Target that associates windows with an EventLoop.

This type exists to allow you to create new windows while Winit executes your callback.

Implementations§

Source§

impl ActiveEventLoop

Source

pub fn create_window( &self, window_attributes: WindowAttributes, ) -> Result<Window, OsError>

Create the window.

Possible causes of error include denied permission, incompatible system, and lack of memory.

§Platform-specific
  • Web: The window is created but not inserted into the web page automatically. Please see the web platform module for more information.
Source

pub fn create_custom_cursor( &self, custom_cursor: CustomCursorSource, ) -> CustomCursor

Create custom cursor.

Source

pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle>

Returns the list of all the monitors available on the system.

Source

pub fn primary_monitor(&self) -> Option<MonitorHandle>

Returns the primary monitor of the system.

Returns None if it can’t identify any monitor as a primary one.

§Platform-specific

Wayland / Web: Always returns None.

Source

pub fn listen_device_events(&self, allowed: DeviceEvents)

Change if or when DeviceEvents are captured.

Since the DeviceEvent capture can lead to high CPU usage for unfocused windows, winit will ignore them by default for unfocused windows on Linux/BSD. This method allows changing this at runtime to explicitly capture them again.

§Platform-specific
  • Wayland / macOS / iOS / Android / Orbital: Unsupported.
Source

pub fn system_theme(&self) -> Option<Theme>

Returns the current system theme.

Returns None if it cannot be determined on the current platform.

§Platform-specific
  • iOS / Android / Wayland / x11 / Orbital: Unsupported.
Source

pub fn set_control_flow(&self, control_flow: ControlFlow)

Sets the ControlFlow.

Source

pub fn control_flow(&self) -> ControlFlow

Gets the current ControlFlow.

Source

pub fn exit(&self)

This exits the event loop.

See LoopExiting.

Examples found in repository?
examples/simple.rs (line 96)
9fn main() {
10    use Action::*;
11    let event_loop = EventLoop::new().unwrap();
12    event_loop.set_control_flow(ControlFlow::Poll);
13    
14    let input = { use base_input_codes::*; input_map!(
15        (Jump,    Space,  GamepadInput::South),
16        (Exit,    Escape, GamepadInput::Start),
17        (Left,    ArrowLeft,  KeyA,  LeftStickLeft ),
18        (Right,   ArrowRight, KeyD,  LeftStickRight),
19        (Forward, ArrowUp,    KeyW,  LeftStickUp   ),
20        (Back,    ArrowDown,  KeyS,  LeftStickDown ),
21        (LookRight, MouseMoveRight, RightStickRight),
22        (LookLeft,  MouseMoveLeft,  RightStickLeft ),
23        (LookUp,    MouseMoveUp,    RightStickUp   ),
24        (LookDown,  MouseMoveDown,  RightStickDown )
25    )};
26
27    struct Graphics {
28        program: Program,
29        indices: IndexBuffer<u16>,
30        vertices: VertexBuffer<Vertex>,
31        normals: VertexBuffer<Normal>
32    }
33    let graphics: Rc<RefCell<Option<Graphics>>> = Rc::new(RefCell::new(None));
34    let graphics_setup = graphics.clone();
35    
36    let draw_parameters = DrawParameters {
37        backface_culling: draw_parameters::BackfaceCullingMode::CullClockwise,
38        ..params::alias_3d()
39    };
40
41    let mut pos = vec3(0.0, 0.0, -30.0);
42    let mut rot = vec2(0.0, 0.0);
43    let mut gravity = 0.0;
44
45    let mut frame_start = Instant::now();
46
47    thin_engine::builder(input).with_setup(|display, window, _| {
48        let _ = window.set_cursor_grab(CursorGrabMode::Confined);
49        let _ = window.set_cursor_grab(CursorGrabMode::Locked);
50        window.set_cursor_visible(false);
51        window.set_title("Walk Test");
52
53        let (indices, vertices, normals) = mesh!(
54            display, &teapot::INDICES, &teapot::VERTICES, &teapot::NORMALS
55        );
56        let program = Program::from_source(
57            display, shaders::VERTEX,
58            "#version 140
59            out vec4 colour;
60            in vec3 v_normal;
61            uniform vec3 light;
62            const vec3 albedo = vec3(0.1, 1.0, 0.3);
63            void main(){
64                float light_level = dot(light, v_normal);
65                colour = vec4(albedo * light_level, 1.0);
66            }", None,
67        ).unwrap();
68        graphics_setup.replace(Some(Graphics { program, indices, vertices, normals }));
69    }).with_update(|input, display, _, target, _| {
70        let graphics = graphics.borrow();
71        let Graphics { vertices, indices, normals, program } = graphics.as_ref().unwrap();
72        let delta_time = frame_start.elapsed().as_secs_f32();
73        frame_start = Instant::now();
74
75        let mut frame = display.draw();
76        let view = Mat4::view_matrix_3d(frame.get_dimensions(), 1.0, 1024.0, 0.1);
77
78        //handle gravity and jump
79        gravity += delta_time * 9.5;
80        if input.pressed(Jump) { gravity = -10.0 }
81
82        //set camera rotation
83        let look_move = input.dir(LookLeft, LookRight, LookUp, LookDown);
84        rot += look_move.scale(delta_time * 20.0);
85        rot.y = rot.y.clamp(-PI / 2.0, PI / 2.0);
86        let rx = Quat::from_y_rot(rot.x);
87        let ry = Quat::from_x_rot(rot.y);
88        let rot = rx * ry;
89
90        //move player based on view and gravity
91        let dir = input.dir_max_len_1(Right, Left, Forward, Back);
92        let move_dir = vec3(dir.x, 0.0, dir.y).scale(5.0*delta_time);
93        pos += move_dir.transform(&Mat3::from_rot(rx));
94        pos.y = (pos.y - gravity * delta_time).max(0.0);
95
96        if input.pressed(Exit) { target.exit() }
97
98        frame.clear_color_and_depth((0.0, 0.0, 0.0, 1.0), 1.0);
99        //draw teapot
100        frame.draw(
101            (vertices, normals), indices,
102            program, &uniform! {
103                view: view,
104                model: Mat4::from_scale(Vec3::splat(0.1)),
105                camera: Mat4::from_inverse_transform(pos, Vec3::ONE, rot),
106                light: vec3(1.0, -0.9, -1.0).normalise()
107            },
108            &draw_parameters,
109        ).unwrap();
110
111        frame.finish().unwrap();
112    }).build(event_loop).unwrap();
113}
Source

pub fn exiting(&self) -> bool

Returns if the EventLoop is about to stop.

See exit().

Source

pub fn owned_display_handle(&self) -> OwnedDisplayHandle

Gets a persistent reference to the underlying platform display.

See the OwnedDisplayHandle type for more information.

Trait Implementations§

Source§

impl ActiveEventLoopExtWayland for ActiveEventLoop

Source§

fn is_wayland(&self) -> bool

True if the ActiveEventLoop uses Wayland.
Source§

impl ActiveEventLoopExtX11 for ActiveEventLoop

Source§

fn is_x11(&self) -> bool

True if the ActiveEventLoop uses X11.
Source§

impl Debug for ActiveEventLoop

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl EventLoopExtStartupNotify for ActiveEventLoop

Source§

fn read_token_from_env(&self) -> Option<ActivationToken>

Read the token from the environment. Read more
Source§

impl GliumEventLoop for ActiveEventLoop

Source§

fn build<Picker>( &self, display_builder: DisplayBuilder, template_builder: ConfigTemplateBuilder, config_picker: Picker, ) -> Result<(Option<Window>, Config), Box<dyn Error>>
where Picker: FnOnce(Box<dyn Iterator<Item = Config> + '_>) -> Config,

Calls display_builder.build(self, template_builder, config_picker).
Source§

impl HasDisplayHandle for ActiveEventLoop

Source§

fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>

Get a handle to the display controller of the windowing system.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HasRawDisplayHandle for T
where T: HasDisplayHandle + ?Sized,

Source§

fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>

👎Deprecated: Use HasDisplayHandle instead
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more