web_sys_main_loop/lib.rs
1// Copyright 2024 arongeo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! web-sys-main-loop provides a main loop (or game loop),
16//! and input handling, for a web_sys window.
17//!
18//! Example:
19//! ```
20//! use web_sys_main_loop::FrameState;
21//!
22//! let window = web_sys::window().unwrap();
23//!
24//! web_sys_main_loop::start(&window, move |frame_state: FrameState| {
25//! ...
26//! // Gets the position (X, Y) of the cursor in the window
27//! // context
28//! let curr_position = frame_state.mouse_state.get_position();
29//! ...
30//! });
31//!
32//! ```
33
34mod frame_state;
35mod input_handler;
36mod main_loop;
37
38pub use crate::frame_state::FrameState;
39pub use crate::input_handler::mouse_state::MouseButton;
40pub use crate::input_handler::mouse_state::MouseState;
41pub use crate::main_loop::start;