Skip to main content

dear_imgui_winit/platform/
event_outcome.rs

1use dear_imgui_rs::{Context, NativeWindowTarget};
2use winit::window::WindowId;
3
4/// Input streams actually updated while handling one native event.
5#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
6pub struct WinitEventForwarding {
7    pub keyboard: bool,
8    pub text: bool,
9    pub pointer: bool,
10    pub focus: bool,
11}
12
13/// Dear ImGui's capture intent at event-dispatch time, from the most recent UI frame.
14///
15/// These are routing hints, not a consumption verdict for this event. Engines should preserve the
16/// recipient selected for a press until its matching release, even if capture intent changes.
17#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
18pub struct WinitCaptureIntent {
19    pub keyboard: bool,
20    pub pointer: bool,
21    pub text_input: bool,
22}
23
24impl WinitCaptureIntent {
25    pub(crate) fn snapshot(context: &Context) -> Self {
26        let io = context.io();
27        Self {
28            keyboard: io.want_capture_keyboard(),
29            pointer: io.want_capture_mouse(),
30            text_input: io.want_text_input(),
31        }
32    }
33}
34
35/// Exact native registration selected by WindowId-first event routing.
36#[derive(Clone, Copy, Debug, Eq, PartialEq)]
37pub struct WinitEventTarget {
38    pub window_id: WindowId,
39    pub native: NativeWindowTarget,
40}
41
42/// Native platform action distinguished from Dear ImGui input forwarding.
43#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
44pub enum WinitPlatformAction {
45    #[default]
46    None,
47    /// The host should decide whether to close its main window/application.
48    MainCloseRequested,
49    /// The backend set this secondary viewport's PlatformRequestClose flag.
50    ViewportCloseRequested,
51    GeometryChanged,
52    NativeDestroyed,
53}
54
55/// Facts observed while routing one event, without conflating ownership and capture intent.
56#[derive(Clone, Debug, Default, PartialEq)]
57pub struct WinitEventOutcome {
58    /// `None` for a foreign WindowId or a non-window event.
59    pub target: Option<WinitEventTarget>,
60    pub forwarded: WinitEventForwarding,
61    /// `None` when the event did not belong to this platform.
62    pub capture: Option<WinitCaptureIntent>,
63    /// Native input/state changed and a new UI frame was requested.
64    pub needs_frame: bool,
65    pub platform_action: WinitPlatformAction,
66    pub pointer_release: Option<super::WinitPointerReleaseReport>,
67}
68
69impl WinitEventOutcome {
70    /// Returns whether this event was associated with a currently owned native registration.
71    pub fn is_owned(&self) -> bool {
72        self.target.is_some()
73    }
74}