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
impl ActiveEventLoop
Sourcepub fn create_window(
&self,
window_attributes: WindowAttributes,
) -> Result<Window, OsError>
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.
Sourcepub fn create_custom_cursor(
&self,
custom_cursor: CustomCursorSource,
) -> CustomCursor
pub fn create_custom_cursor( &self, custom_cursor: CustomCursorSource, ) -> CustomCursor
Create custom cursor.
Sourcepub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle>
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle>
Returns the list of all the monitors available on the system.
Sourcepub fn primary_monitor(&self) -> Option<MonitorHandle>
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
.
Sourcepub fn listen_device_events(&self, allowed: DeviceEvents)
pub fn listen_device_events(&self, allowed: DeviceEvents)
Change if or when DeviceEvent
s 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.
Sourcepub fn system_theme(&self) -> Option<Theme>
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.
Sourcepub fn set_control_flow(&self, control_flow: ControlFlow)
pub fn set_control_flow(&self, control_flow: ControlFlow)
Sets the ControlFlow
.
Sourcepub fn control_flow(&self) -> ControlFlow
pub fn control_flow(&self) -> ControlFlow
Gets the current ControlFlow
.
Sourcepub fn exit(&self)
pub fn exit(&self)
This exits the event loop.
See LoopExiting
.
Examples found in repository?
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 // square brackets mean that all input codes must be pressed for the bind to be pressed
17 (Exit, [ControlLeft, Escape], GamepadInput::Start),
18 (Left, ArrowLeft, KeyA, LeftStickLeft ),
19 (Right, ArrowRight, KeyD, LeftStickRight),
20 (Forward, ArrowUp, KeyW, LeftStickUp ),
21 (Back, ArrowDown, KeyS, LeftStickDown ),
22 (LookRight, MouseMoveRight, RightStickRight),
23 (LookLeft, MouseMoveLeft, RightStickLeft ),
24 (LookUp, MouseMoveUp, RightStickUp ),
25 (LookDown, MouseMoveDown, RightStickDown )
26 )};
27
28 struct Graphics {
29 program: Program,
30 indices: IndexBuffer<u16>,
31 vertices: VertexBuffer<Vertex>,
32 normals: VertexBuffer<Normal>
33 }
34 let graphics: Rc<RefCell<Option<Graphics>>> = Rc::new(RefCell::new(None));
35 let graphics_setup = graphics.clone();
36
37 let draw_parameters = DrawParameters {
38 backface_culling: draw_parameters::BackfaceCullingMode::CullClockwise,
39 ..params::alias_3d()
40 };
41
42 let mut pos = vec3(0.0, 0.0, -30.0);
43 let mut rot = vec2(0.0, 0.0);
44 let mut gravity = 0.0;
45
46 let mut frame_start = Instant::now();
47
48 thin_engine::builder(input).with_setup(|display, window, _| {
49 let _ = window.set_cursor_grab(CursorGrabMode::Confined);
50 let _ = window.set_cursor_grab(CursorGrabMode::Locked);
51 window.set_cursor_visible(false);
52 window.set_title("Walk Test");
53
54 let (indices, vertices, normals) = mesh!(
55 display, &teapot::INDICES, &teapot::VERTICES, &teapot::NORMALS
56 ).unwrap();
57 let program = Program::from_source(
58 display,
59 "#version 140
60 in vec3 position;
61 in vec3 normal;
62 out vec3 v_normal;
63
64 uniform mat4 camera;
65 uniform mat4 model;
66 uniform mat4 perspective;
67
68 void main() {
69 mat3 norm_mat = transpose(inverse(mat3(camera * model)));
70 v_normal = normalize(norm_mat * normal);
71 gl_Position = perspective * camera * model * vec4(position, 1);
72 }",
73 "#version 140
74 out vec4 colour;
75 in vec3 v_normal;
76
77 uniform vec3 light;
78 const vec3 albedo = vec3(0.1, 1.0, 0.3);
79
80 void main(){
81 float light_level = dot(light, v_normal);
82 colour = vec4(albedo * light_level, 1.0);
83 }", None,
84 ).unwrap();
85 graphics_setup.replace(Some(Graphics { program, indices, vertices, normals }));
86 }).with_update(|input, display, _, target, _| {
87 let graphics = graphics.borrow();
88 let Graphics { vertices, indices, normals, program } = graphics.as_ref().unwrap();
89 let delta_time = frame_start.elapsed().as_secs_f32();
90 frame_start = Instant::now();
91
92 let mut frame = display.draw();
93 let perspective = Mat4::perspective_3d(frame.get_dimensions(), 1.0, 1024.0, 0.1);
94
95 // handle gravity and jump
96 gravity += delta_time * 9.5;
97 if input.pressed(Jump) { gravity = -10.0 }
98
99 // set camera rotation
100 let look_move = input.dir(LookRight, LookLeft, LookUp, LookDown);
101 rot += look_move.scale(delta_time * 15.0);
102 rot.y = rot.y.clamp(-PI / 2.0, PI / 2.0);
103 let rx = Quat::from_y_rot(rot.x);
104 let ry = Quat::from_x_rot(-rot.y);
105 let rot = rx * ry;
106
107 // move player based on camera and gravity
108 let dir = input.dir_max_len_1(Right, Left, Forward, Back);
109 let move_dir = vec3(dir.x, 0.0, dir.y).scale(5.0*delta_time);
110 pos += Mat3::from_rot(rx) * move_dir;
111 pos.y = (pos.y - gravity * delta_time).max(0.0);
112
113 if input.pressed(Exit) { target.exit() }
114
115 frame.clear_color_and_depth((0.0, 0.0, 0.0, 1.0), 1.0);
116 //draw teapot
117 frame.draw(
118 (vertices, normals), indices,
119 program, &uniform! {
120 perspective: perspective,
121 model: Mat4::from_scale(Vec3::splat(0.1)),
122 camera: Mat4::from_inverse_transform(pos, Vec3::ONE, rot),
123 light: vec3(1.0, -0.9, -1.0).normalise()
124 },
125 &draw_parameters,
126 ).unwrap();
127
128 frame.finish().unwrap();
129 }).build(event_loop).unwrap();
130}
Sourcepub fn owned_display_handle(&self) -> OwnedDisplayHandle
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
impl ActiveEventLoopExtWayland for ActiveEventLoop
Source§fn is_wayland(&self) -> bool
fn is_wayland(&self) -> bool
ActiveEventLoop
uses Wayland.Source§impl ActiveEventLoopExtX11 for ActiveEventLoop
impl ActiveEventLoopExtX11 for ActiveEventLoop
Source§fn is_x11(&self) -> bool
fn is_x11(&self) -> bool
ActiveEventLoop
uses X11.Source§impl Debug for ActiveEventLoop
impl Debug for ActiveEventLoop
Source§impl EventLoopExtStartupNotify for ActiveEventLoop
impl EventLoopExtStartupNotify for ActiveEventLoop
Source§fn read_token_from_env(&self) -> Option<ActivationToken>
fn read_token_from_env(&self) -> Option<ActivationToken>
Source§impl GliumEventLoop for ActiveEventLoop
impl GliumEventLoop for ActiveEventLoop
Source§impl HasDisplayHandle for ActiveEventLoop
impl HasDisplayHandle for ActiveEventLoop
Source§fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>
Auto Trait Implementations§
impl !Freeze for ActiveEventLoop
impl !RefUnwindSafe for ActiveEventLoop
impl !Send for ActiveEventLoop
impl !Sync for ActiveEventLoop
impl Unpin for ActiveEventLoop
impl !UnwindSafe for ActiveEventLoop
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
impl<T> HasRawDisplayHandle for Twhere
T: HasDisplayHandle + ?Sized,
Source§fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>
HasDisplayHandle
instead