1use alloc::string::String;
2use bevy_ecs::{entity::Entity, message::Message};
3use bevy_input::{
4 gestures::*,
5 keyboard::{KeyboardFocusLost, KeyboardInput},
6 mouse::{MouseButtonInput, MouseMotion, MouseWheel},
7 touch::TouchInput,
8};
9use bevy_math::{IVec2, Vec2};
10
11#[cfg(feature = "std")]
12use std::path::PathBuf;
13
14#[cfg(not(feature = "std"))]
15use alloc::string::String as PathBuf;
16
17#[cfg(feature = "bevy_reflect")]
18use bevy_reflect::Reflect;
19
20#[cfg(feature = "serialize")]
21use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
22
23use crate::WindowTheme;
24
25#[derive(Message, Debug, Clone, PartialEq)]
27#[cfg_attr(
28 feature = "bevy_reflect",
29 derive(Reflect),
30 reflect(Debug, PartialEq, Clone)
31)]
32#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
33#[cfg_attr(
34 all(feature = "serialize", feature = "bevy_reflect"),
35 reflect(Serialize, Deserialize)
36)]
37pub struct WindowResized {
38 pub window: Entity,
40 pub width: f32,
42 pub height: f32,
44}
45
46#[derive(Message, Debug, Clone, PartialEq, Eq)]
49#[cfg_attr(
50 feature = "bevy_reflect",
51 derive(Reflect),
52 reflect(Debug, PartialEq, Clone)
53)]
54#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
55#[cfg_attr(
56 all(feature = "serialize", feature = "bevy_reflect"),
57 reflect(Serialize, Deserialize)
58)]
59pub struct RequestRedraw;
60
61#[derive(Message, Debug, Clone, PartialEq, Eq)]
65#[cfg_attr(
66 feature = "bevy_reflect",
67 derive(Reflect),
68 reflect(Debug, PartialEq, Clone)
69)]
70#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
71#[cfg_attr(
72 all(feature = "serialize", feature = "bevy_reflect"),
73 reflect(Serialize, Deserialize)
74)]
75pub struct WindowCreated {
76 pub window: Entity,
78}
79
80#[derive(Message, Debug, Clone, PartialEq, Eq)]
91#[cfg_attr(
92 feature = "bevy_reflect",
93 derive(Reflect),
94 reflect(Debug, PartialEq, Clone)
95)]
96#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
97#[cfg_attr(
98 all(feature = "serialize", feature = "bevy_reflect"),
99 reflect(Serialize, Deserialize)
100)]
101pub struct WindowCloseRequested {
102 pub window: Entity,
104}
105
106#[derive(Message, Debug, Clone, PartialEq, Eq)]
109#[cfg_attr(
110 feature = "bevy_reflect",
111 derive(Reflect),
112 reflect(Debug, PartialEq, Clone)
113)]
114#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
115#[cfg_attr(
116 all(feature = "serialize", feature = "bevy_reflect"),
117 reflect(Serialize, Deserialize)
118)]
119pub struct WindowClosed {
120 pub window: Entity,
125}
126
127#[derive(Message, Debug, Clone, PartialEq, Eq)]
130#[cfg_attr(
131 feature = "bevy_reflect",
132 derive(Reflect),
133 reflect(Debug, PartialEq, Clone)
134)]
135#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
136#[cfg_attr(
137 all(feature = "serialize", feature = "bevy_reflect"),
138 reflect(Serialize, Deserialize)
139)]
140pub struct WindowClosing {
141 pub window: Entity,
143}
144
145#[derive(Message, Debug, Clone, PartialEq, Eq)]
150#[cfg_attr(
151 feature = "bevy_reflect",
152 derive(Reflect),
153 reflect(Debug, PartialEq, Clone)
154)]
155#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
156#[cfg_attr(
157 all(feature = "serialize", feature = "bevy_reflect"),
158 reflect(Serialize, Deserialize)
159)]
160pub struct WindowDestroyed {
161 pub window: Entity,
166}
167
168#[derive(Message, Debug, Clone, PartialEq)]
180#[cfg_attr(
181 feature = "bevy_reflect",
182 derive(Reflect),
183 reflect(Debug, PartialEq, Clone)
184)]
185#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
186#[cfg_attr(
187 all(feature = "serialize", feature = "bevy_reflect"),
188 reflect(Serialize, Deserialize)
189)]
190pub struct CursorMoved {
191 pub window: Entity,
193 pub position: Vec2,
195 pub delta: Option<Vec2>,
201}
202
203#[derive(Message, Debug, Clone, PartialEq, Eq)]
205#[cfg_attr(
206 feature = "bevy_reflect",
207 derive(Reflect),
208 reflect(Debug, PartialEq, Clone)
209)]
210#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
211#[cfg_attr(
212 all(feature = "serialize", feature = "bevy_reflect"),
213 reflect(Serialize, Deserialize)
214)]
215pub struct CursorEntered {
216 pub window: Entity,
218}
219
220#[derive(Message, Debug, Clone, PartialEq, Eq)]
222#[cfg_attr(
223 feature = "bevy_reflect",
224 derive(Reflect),
225 reflect(Debug, PartialEq, Clone)
226)]
227#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
228#[cfg_attr(
229 all(feature = "serialize", feature = "bevy_reflect"),
230 reflect(Serialize, Deserialize)
231)]
232pub struct CursorLeft {
233 pub window: Entity,
235}
236
237#[derive(Message, Debug, Clone, PartialEq, Eq)]
243#[cfg_attr(
244 feature = "bevy_reflect",
245 derive(Reflect),
246 reflect(Debug, PartialEq, Clone)
247)]
248#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
249#[cfg_attr(
250 all(feature = "serialize", feature = "bevy_reflect"),
251 reflect(Serialize, Deserialize)
252)]
253pub enum Ime {
254 Preedit {
256 window: Entity,
258 value: String,
260 cursor: Option<(usize, usize)>,
264 },
265 Commit {
267 window: Entity,
269 value: String,
271 },
272 Enabled {
276 window: Entity,
278 },
279 Disabled {
281 window: Entity,
283 },
284}
285
286#[derive(Message, Debug, Clone, PartialEq, Eq)]
288#[cfg_attr(
289 feature = "bevy_reflect",
290 derive(Reflect),
291 reflect(Debug, PartialEq, Clone)
292)]
293#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
294#[cfg_attr(
295 all(feature = "serialize", feature = "bevy_reflect"),
296 reflect(Serialize, Deserialize)
297)]
298pub struct WindowFocused {
299 pub window: Entity,
301 pub focused: bool,
303}
304
305#[derive(Message, Debug, Clone, PartialEq, Eq)]
315#[cfg_attr(
316 feature = "bevy_reflect",
317 derive(Reflect),
318 reflect(Debug, PartialEq, Clone)
319)]
320#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
321#[cfg_attr(
322 all(feature = "serialize", feature = "bevy_reflect"),
323 reflect(Serialize, Deserialize)
324)]
325pub struct WindowOccluded {
326 pub window: Entity,
328 pub occluded: bool,
330}
331
332#[derive(Message, Debug, Clone, PartialEq)]
334#[cfg_attr(
335 feature = "bevy_reflect",
336 derive(Reflect),
337 reflect(Debug, PartialEq, Clone)
338)]
339#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
340#[cfg_attr(
341 all(feature = "serialize", feature = "bevy_reflect"),
342 reflect(Serialize, Deserialize)
343)]
344pub struct WindowScaleFactorChanged {
345 pub window: Entity,
347 pub scale_factor: f64,
349}
350
351#[derive(Message, Debug, Clone, PartialEq)]
353#[cfg_attr(
354 feature = "bevy_reflect",
355 derive(Reflect),
356 reflect(Debug, PartialEq, Clone)
357)]
358#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
359#[cfg_attr(
360 all(feature = "serialize", feature = "bevy_reflect"),
361 reflect(Serialize, Deserialize)
362)]
363pub struct WindowBackendScaleFactorChanged {
364 pub window: Entity,
366 pub scale_factor: f64,
368}
369
370#[derive(Message, Debug, Clone, PartialEq, Eq)]
372#[cfg_attr(
373 feature = "bevy_reflect",
374 derive(Reflect),
375 reflect(Debug, PartialEq, Clone)
376)]
377#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
378#[cfg_attr(
379 all(feature = "serialize", feature = "bevy_reflect"),
380 reflect(Serialize, Deserialize)
381)]
382pub enum FileDragAndDrop {
383 DroppedFile {
385 window: Entity,
387 path_buf: PathBuf,
389 },
390
391 HoveredFile {
393 window: Entity,
395 path_buf: PathBuf,
397 },
398
399 HoveredFileCanceled {
401 window: Entity,
403 },
404}
405
406#[derive(Message, Debug, Clone, PartialEq, Eq)]
408#[cfg_attr(
409 feature = "bevy_reflect",
410 derive(Reflect),
411 reflect(Debug, PartialEq, Clone)
412)]
413#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
414#[cfg_attr(
415 all(feature = "serialize", feature = "bevy_reflect"),
416 reflect(Serialize, Deserialize)
417)]
418pub struct WindowMoved {
419 pub window: Entity,
421 pub position: IVec2,
423}
424
425#[derive(Message, Debug, Clone, PartialEq, Eq)]
430#[cfg_attr(
431 feature = "bevy_reflect",
432 derive(Reflect),
433 reflect(Debug, PartialEq, Clone)
434)]
435#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
436#[cfg_attr(
437 all(feature = "serialize", feature = "bevy_reflect"),
438 reflect(Serialize, Deserialize)
439)]
440pub struct WindowThemeChanged {
441 pub window: Entity,
443 pub theme: WindowTheme,
445}
446
447#[derive(Message, Debug, Clone, Copy, PartialEq, Eq)]
449#[cfg_attr(
450 feature = "bevy_reflect",
451 derive(Reflect),
452 reflect(Debug, PartialEq, Clone)
453)]
454#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
455#[cfg_attr(
456 all(feature = "serialize", feature = "bevy_reflect"),
457 reflect(Serialize, Deserialize)
458)]
459pub enum AppLifecycle {
460 Idle,
462 Running,
464 WillSuspend,
467 Suspended,
469 WillResume,
472}
473
474impl AppLifecycle {
475 #[inline]
477 pub fn is_active(&self) -> bool {
478 match self {
479 Self::Idle | Self::Suspended => false,
480 Self::Running | Self::WillSuspend | Self::WillResume => true,
481 }
482 }
483}
484
485#[derive(Message, Debug, Clone, PartialEq)]
492#[cfg_attr(
493 feature = "bevy_reflect",
494 derive(Reflect),
495 reflect(Debug, PartialEq, Clone)
496)]
497#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
498#[cfg_attr(
499 all(feature = "serialize", feature = "bevy_reflect"),
500 reflect(Serialize, Deserialize)
501)]
502pub enum WindowEvent {
503 AppLifecycle(AppLifecycle),
505 CursorEntered(CursorEntered),
507 CursorLeft(CursorLeft),
509 CursorMoved(CursorMoved),
511 FileDragAndDrop(FileDragAndDrop),
513 Ime(Ime),
515 RequestRedraw(RequestRedraw),
517 WindowBackendScaleFactorChanged(WindowBackendScaleFactorChanged),
519 WindowCloseRequested(WindowCloseRequested),
521 WindowCreated(WindowCreated),
523 WindowDestroyed(WindowDestroyed),
525 WindowFocused(WindowFocused),
527 WindowMoved(WindowMoved),
529 WindowOccluded(WindowOccluded),
531 WindowResized(WindowResized),
533 WindowScaleFactorChanged(WindowScaleFactorChanged),
535 WindowThemeChanged(WindowThemeChanged),
537
538 MouseButtonInput(MouseButtonInput),
540 MouseMotion(MouseMotion),
542 MouseWheel(MouseWheel),
544
545 PinchGesture(PinchGesture),
547 RotationGesture(RotationGesture),
549 DoubleTapGesture(DoubleTapGesture),
551 PanGesture(PanGesture),
553
554 TouchInput(TouchInput),
556
557 KeyboardInput(KeyboardInput),
559 KeyboardFocusLost(KeyboardFocusLost),
563}
564
565impl From<AppLifecycle> for WindowEvent {
566 fn from(e: AppLifecycle) -> Self {
567 Self::AppLifecycle(e)
568 }
569}
570
571impl From<CursorEntered> for WindowEvent {
572 fn from(e: CursorEntered) -> Self {
573 Self::CursorEntered(e)
574 }
575}
576
577impl From<CursorLeft> for WindowEvent {
578 fn from(e: CursorLeft) -> Self {
579 Self::CursorLeft(e)
580 }
581}
582
583impl From<CursorMoved> for WindowEvent {
584 fn from(e: CursorMoved) -> Self {
585 Self::CursorMoved(e)
586 }
587}
588
589impl From<FileDragAndDrop> for WindowEvent {
590 fn from(e: FileDragAndDrop) -> Self {
591 Self::FileDragAndDrop(e)
592 }
593}
594
595impl From<Ime> for WindowEvent {
596 fn from(e: Ime) -> Self {
597 Self::Ime(e)
598 }
599}
600
601impl From<RequestRedraw> for WindowEvent {
602 fn from(e: RequestRedraw) -> Self {
603 Self::RequestRedraw(e)
604 }
605}
606
607impl From<WindowBackendScaleFactorChanged> for WindowEvent {
608 fn from(e: WindowBackendScaleFactorChanged) -> Self {
609 Self::WindowBackendScaleFactorChanged(e)
610 }
611}
612
613impl From<WindowCloseRequested> for WindowEvent {
614 fn from(e: WindowCloseRequested) -> Self {
615 Self::WindowCloseRequested(e)
616 }
617}
618
619impl From<WindowCreated> for WindowEvent {
620 fn from(e: WindowCreated) -> Self {
621 Self::WindowCreated(e)
622 }
623}
624
625impl From<WindowDestroyed> for WindowEvent {
626 fn from(e: WindowDestroyed) -> Self {
627 Self::WindowDestroyed(e)
628 }
629}
630
631impl From<WindowFocused> for WindowEvent {
632 fn from(e: WindowFocused) -> Self {
633 Self::WindowFocused(e)
634 }
635}
636
637impl From<WindowMoved> for WindowEvent {
638 fn from(e: WindowMoved) -> Self {
639 Self::WindowMoved(e)
640 }
641}
642
643impl From<WindowOccluded> for WindowEvent {
644 fn from(e: WindowOccluded) -> Self {
645 Self::WindowOccluded(e)
646 }
647}
648
649impl From<WindowResized> for WindowEvent {
650 fn from(e: WindowResized) -> Self {
651 Self::WindowResized(e)
652 }
653}
654
655impl From<WindowScaleFactorChanged> for WindowEvent {
656 fn from(e: WindowScaleFactorChanged) -> Self {
657 Self::WindowScaleFactorChanged(e)
658 }
659}
660
661impl From<WindowThemeChanged> for WindowEvent {
662 fn from(e: WindowThemeChanged) -> Self {
663 Self::WindowThemeChanged(e)
664 }
665}
666
667impl From<MouseButtonInput> for WindowEvent {
668 fn from(e: MouseButtonInput) -> Self {
669 Self::MouseButtonInput(e)
670 }
671}
672
673impl From<MouseMotion> for WindowEvent {
674 fn from(e: MouseMotion) -> Self {
675 Self::MouseMotion(e)
676 }
677}
678
679impl From<MouseWheel> for WindowEvent {
680 fn from(e: MouseWheel) -> Self {
681 Self::MouseWheel(e)
682 }
683}
684
685impl From<PinchGesture> for WindowEvent {
686 fn from(e: PinchGesture) -> Self {
687 Self::PinchGesture(e)
688 }
689}
690
691impl From<RotationGesture> for WindowEvent {
692 fn from(e: RotationGesture) -> Self {
693 Self::RotationGesture(e)
694 }
695}
696
697impl From<DoubleTapGesture> for WindowEvent {
698 fn from(e: DoubleTapGesture) -> Self {
699 Self::DoubleTapGesture(e)
700 }
701}
702
703impl From<PanGesture> for WindowEvent {
704 fn from(e: PanGesture) -> Self {
705 Self::PanGesture(e)
706 }
707}
708
709impl From<TouchInput> for WindowEvent {
710 fn from(e: TouchInput) -> Self {
711 Self::TouchInput(e)
712 }
713}
714
715impl From<KeyboardInput> for WindowEvent {
716 fn from(e: KeyboardInput) -> Self {
717 Self::KeyboardInput(e)
718 }
719}
720
721impl From<KeyboardFocusLost> for WindowEvent {
722 fn from(e: KeyboardFocusLost) -> Self {
723 Self::KeyboardFocusLost(e)
724 }
725}