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