1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! Cancel: Escape and the pad's B back out of a dialog or a screen.
use QueryData;
use Traversal;
use ;
use *;
use crate;
/// The player asked to back out: Escape, or any gamepad's East button (B on Xbox, Circle on
/// PlayStation), pressed once. Nothing is closed for you; say what leaving means by observing it
/// on the dialog or the screen the player is in.
///
/// It starts at the focused widget and bubbles up through its parents (Bevy's own event
/// propagation), so an observer on the [`dialog`](crate::dialog) or the [`screen`](crate::screen)
/// hears it, and the innermost layer hears it first. An observer that handled it calls
/// `cancel.propagate(false)`, so a layer above does not also act. It never leaves a
/// [`dialog`](crate::dialog): a modal dialog is its own scope, so a Back inside it does not reach
/// the screen under it, even one the dialog was spawned beneath. With no widget focused, an open
/// dialog still hears it; with no dialog open and nothing focused, nothing is sent, and Escape is
/// the game's own.
///
/// ```
/// # use bevy::prelude::*;
/// # use bevy_gooey::*;
/// # fn ui(mut commands: Commands) {
/// commands.spawn((
/// dialog(),
/// observe(|cancel: On<Cancel>, mut commands: Commands| {
/// commands.entity(cancel.entity).despawn();
/// }),
/// children![(panel(), children![label("Leave?"), button("Stay")])],
/// ));
/// # }
/// ```
///
/// The keyboard and the pad are one path, so a game handles one event. Draw the pad's prompt
/// yourself ("B Back"); with it on screen a Back button is not also needed.
/// How a [`Cancel`] travels: to the parent, and no further than a [`dialog`](crate::dialog).
/// Sends a [`Cancel`] when Escape or any gamepad's East button is just pressed, and shows focus
/// (`InputFocusVisible`). Runs in [`crate::GooeySystems::Navigate`].
///
/// It is sent to the focused widget when that is a live, visible tab stop in the scope the player
/// sees (the open [`dialog`](crate::dialog) on top, or the screen when none is open); otherwise to
/// the open dialog, so a dialog can always be dismissed; otherwise nowhere, and a press does
/// nothing here. The window Bevy focuses at start-up is not a widget. A press repeated by the
/// keyboard does not send another.