MCPcopy Create free account
hub / github.com/DjDeveloperr/deno_desktop / serialize_event

Function serialize_event

src/event_loop.rs:61–176  ·  view source on GitHub ↗
(event: Event<'a, Blocker>)

Source from the content-addressed store, hash-verified

59}
60
61pub fn serialize_event<'a>(event: Event<'a, Blocker>) -> Value {
62 match event {
63 Event::NewEvents(cause) => {
64 let cause = match cause {
65 StartCause::ResumeTimeReached { start, requested_resume } => json!({ "type": "resumeTimeReached", "start": start.elapsed().as_millis().to_string(), "requestedResume": requested_resume.elapsed().as_millis().to_string() }),
66 StartCause::WaitCancelled { start, requested_resume } => json!({ "type": "waitCancelled", "start": start.elapsed().as_millis().to_string(), "requestedResume": if let Some(requested_resume) = requested_resume { Some(requested_resume.elapsed().as_millis().to_string()) } else { None }}),
67 StartCause::Poll => json!({ "type": "poll" }),
68 StartCause::Init => json!({ "type": "init" }),
69 };
70 json!({ "type": "newEvents", "cause": cause })
71 },
72 Event::WindowEvent { window_id, event } => {
73 let event = match event {
74 WindowEvent::Resized(size) => json!({ "type": "resized", "size": serialize_physical_size(size) }),
75 WindowEvent::Moved(pos) => json!({ "type": "moved", "position": serialize_physical_position(pos) }),
76 WindowEvent::CloseRequested => json!({ "type": "closeRequested" }),
77 WindowEvent::Destroyed => json!({ "type": "destroyed" }),
78 WindowEvent::DroppedFile(path) => json!({ "type": "droppedFile", "path": path.into_os_string().into_string() }),
79 WindowEvent::HoveredFile(path) => json!({ "type": "hoveredFile", "path": path.into_os_string().into_string() }),
80 WindowEvent::HoveredFileCancelled => json!({ "type": "hoveredFileCancelled" }),
81 WindowEvent::ReceivedCharacter(ch) => json!({ "type": "receivedCharacter", "char": ch }),
82 WindowEvent::Focused(focused) => json!({ "type": "focused", "focused": focused }),
83 WindowEvent::KeyboardInput { device_id, input, is_synthetic } => json!({
84 "type": "keyboardInput",
85 "deviceID": hash(device_id),
86 "isSynthetic": is_synthetic,
87 "input": serialize_keyboard_input(input)
88 }),
89 WindowEvent::ModifiersChanged(state) => json!({ "type": "modifiersChanged", "state": state.bits() }),
90 WindowEvent::CursorMoved { device_id, position, .. } => json!({
91 "type": "cursorMoved",
92 "deviceID": hash(device_id),
93 "position": serialize_physical_position(position)
94 }),
95 WindowEvent::CursorEntered { device_id } => json!({
96 "type": "cursorEntered",
97 "deviceID": hash(device_id)
98 }),
99 WindowEvent::CursorLeft { device_id } => json!({ "type": "cursorLeft", "deviceID": hash(device_id) }),
100 WindowEvent::MouseWheel { device_id, delta, phase, .. } => json!({
101 "type": "mouseWheel",
102 "deviceID": hash(device_id),
103 "delta": serialize_mouse_scroll_delta(delta),
104 "phase": serialize_touch_phase(phase),
105 }),
106 WindowEvent::MouseInput { device_id, state, button, .. } => json!({
107 "type": "mouseInput",
108 "deviceID": hash(device_id),
109 "state": match state {
110 ElementState::Pressed => "pressed",
111 ElementState::Released => "released"
112 },
113 "button": match button {
114 MouseButton::Left => json!("left"),
115 MouseButton::Right => json!("right"),
116 MouseButton::Middle => json!("middle"),
117 MouseButton::Other(n) => json!(n),
118 },

Callers 1

op_next_eventFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected