quicksilver/lib.rs
1//! # quicksilver
2//! 
3//!
4//! [](https://crates.io/crates/quicksilver)
5//! [](https://docs.rs/quicksilver)
6//! [](https://deps.rs/repo/github/ryanisaacg/quicksilver)
7//!
8//! A simple 2D game framework written in pure Rust, for both the Web and Desktop
9//!
10//! ## Maintenance Status
11//!
12//! I've [posted an update on my website](https://ryanisaacg.com/posts/quicksilver-goodbye) about Quicksilver.
13//! To keep a long story short: **Quicksilver is no longer actively developed.**
14//! For now I will continue to triage bugs and pull requests and (maybe) fix small bugs.
15//!
16//! ## Alpha Notice
17//!
18//! This version of Quicksilver is currently working its way through alpha! There is still work to do
19//! on the API and on bugfixes, as well as waiting on an upstream library for audio support.
20//! Please feel free to use this version and **provide feedback!** If you run into bugs or want to
21//! give feedback on API decisions, please open an issue.
22//!
23//! ## A quick example
24//!
25//! Create a rust project and add this line to your `Cargo.toml` file under `[dependencies]`:
26//! ```text
27//! quicksilver = "0.4.0-alpha5"
28//! ```
29//! Then replace `src/main.rs` with the following (the contents of quicksilver's
30//! `examples/01_square.rs`):
31//!
32//! ```no_run
33//! // Example 1: The Square
34//! // Open a window, and draw a colored square in it
35//! use quicksilver::{
36//! geom::{Rectangle, Vector},
37//! graphics::{Color, Graphics},
38//! Input, Window, Result, Settings, run,
39//! };
40//!
41//! fn main() {
42//! run(
43//! Settings {
44//! title: "Square Example",
45//! ..Settings::default()
46//! },
47//! app,
48//! );
49//! }
50//!
51//! async fn app(window: Window, mut gfx: Graphics, mut input: Input) -> Result<()> {
52//! // Clear the screen to a blank, white color
53//! gfx.clear(Color::WHITE);
54//! // Paint a blue square with a red outline in the center of our screen
55//! // It should have a top-left of (350, 100) and a size of (150, 100)
56//! let rect = Rectangle::new(Vector::new(350.0, 100.0), Vector::new(100.0, 100.0));
57//! gfx.fill_rect(&rect, Color::BLUE);
58//! gfx.stroke_rect(&rect, Color::RED);
59//! // Send the data to be drawn
60//! gfx.present(&window)?;
61//! loop {
62//! while let Some(_) = input.next_event().await {}
63//! }
64//! }
65//! ```
66//!
67//! Run this with `cargo run` or, if you have the wasm32 toolchain installed, you can build for the
68//! web (instructions below).
69//!
70//! ## Learning Quicksilver
71//!
72//! A good way to get started with Quicksilver is to
73//! [read and run the examples](https://github.com/ryanisaacg/quicksilver/tree/master/examples)
74//! which also serve as tutorials. If you have any questions, feel free to open an issue or ask for
75//! help in the [Rust Community Discord](https://discord.gg/aVESxV8) from other Quicksilver users
76//! and developers.
77//!
78//! ## Building and Deploying a Quicksilver application
79//!
80//! Quicksilver should always compile and run on the latest stable version of Rust, for both web and
81//! desktop.
82//!
83//! Make sure to put all your assets in a top-level folder of your crate called `static/`. *All*
84//! Quicksilver file loading-APIs will expect paths that originate in the static folder, so
85//! `static/image.png` should be referenced as `image.png`.
86//!
87//! ### Linux dependencies
88//!
89//! On Windows and Mac, all you'll need to build Quicksilver is a recent stable version of `rustc`
90//! and `cargo`. A few of Quicksilver's dependencies require Linux packages to build, namely
91//! `libudev`, `zlib`, and `alsa`. To install these on Ubuntu or Debian, run the command
92//! `sudo apt install libudev-dev zlib1g-dev alsa libasound2-dev`.
93//!
94//! ### Deploying for desktop
95//!
96//! If you're deploying for desktop platforms, build in release mode (`cargo build --release`)
97//! and copy the executable file produced (found at "target/release/") and any assets you used
98//! (image files, etc.) and create an archive (on Windows a zip file, on Unix a tar file). You
99//! should be able to distribute this archive with no problems; if there are any, please open an
100//! issue.
101//!
102//! ### Deploying for the web
103//!
104//! If you're deploying for the web, first make sure you've
105//! [installed the cargo web tool](https://github.com/koute/cargo-web). Then use `cargo web deploy`
106//! to build your application for distribution (located at `target/deploy`).
107//!
108//! If you want to test your application locally, use `cargo web start --features quicksilver/stdweb` and open your
109//! favorite browser to the port it provides.
110//!
111//! #### wasm-bindgen support
112//!
113//! Quicksilver has recently gained experimental support for `wasm-bindgen`, under the `web-sys`
114//! feature. The workflow is not currently documented here, but it should be the same as using any other
115//! library with `wasm-bindgen`.
116//!
117//! ## Optional Features
118//!
119//! Quicksilver by default tries to provide all features a 2D application may need, but not all
120//! applications need these features.
121//!
122//! The optional features available are:
123//! - easy logging (via [log](https://github.com/rust-lang/log),
124//! [simple_logger](https://github.com/borntyping/rust-simple_logger), and
125//! [web_logger](https://github.com/yewstack/web_logger))
126//! - gamepad event generation (via [gilrs](https://gitlab.com/gilrs-project/gilrs))
127//! - saving (via [gestalt](https://github.com/ryanisaacg/golem))
128//! - font rendering (via [elefont](https://github.com/ryanisaacg/elefont)) and TTF parsing (via [rusttype](https://gitlab.redox-os.org/redox-os/rusttype))
129//!
130//! Each are enabled by default, but you can
131//! [specify which features](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#choosing-features)
132//! you actually want to use.
133//!
134//! ## Supported Platforms
135//!
136//! The engine is supported on Windows, macOS, Linux, and the web via WebAssembly.
137//!
138//! Mobile support would be a future possibility, but likely only through external contributions.
139
140#![deny(
141 bare_trait_objects,
142 unused_extern_crates,
143 unused_import_braces,
144 unused_qualifications
145)]
146#![allow(clippy::needless_doctest_main)]
147
148// Re-export every library that appears in the public API
149pub use blinds;
150#[cfg(feature = "font")]
151pub use elefont;
152pub use golem;
153pub use log;
154pub use mint;
155
156mod error;
157
158pub mod geom;
159pub mod graphics;
160pub mod input;
161#[cfg(feature = "saving")]
162pub mod saving {
163 //! A module to manage cross-platform save data via the [`gestalt`] library
164 pub use gestalt::*;
165}
166pub use crate::error::QuicksilverError;
167
168mod run;
169mod timer;
170mod window;
171pub use blinds::CursorIcon;
172pub use run::{run, Settings};
173pub use timer::Timer;
174pub use window::Window;
175
176pub use graphics::Graphics;
177pub use input::Input;
178
179/// Load a file as a [`Future`]
180///
181/// Within an `async` function (like the one passed to [`run`]), you can use `.await`:
182///
183/// ```no_run
184/// # use platter::load_file;
185/// # async fn test() {
186/// load_file("my_file_path").await.expect("The file was not found!");
187/// # }
188/// ```
189///
190/// [`Future`]: std::future::Future
191/// [`run`]: crate::ran
192pub use platter::load_file;
193
194/// A Result that returns either success or a [`QuicksilverError`]
195pub type Result<T> = std::result::Result<T, QuicksilverError>;
196
197// Evil hack to preserve docs from Blinds
198// The events from Blinds want to link to crate::event::*,
199// so this creates those links
200mod event {
201 pub use crate::input::*;
202}