-
Notifications
You must be signed in to change notification settings - Fork 78
/
_01_basic.rs
81 lines (81 loc) · 2.27 KB
/
_01_basic.rs
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
//! Our first tutorial is simple: Just create a blank window.
//!
//! Here's the full source:
//!
//! ```no_run
//! extern crate quicksilver;
//!
//! use quicksilver::{
//! Result,
//! geom::Vector,
//! lifecycle::{State, run}
//! };
//!
//! struct Screen;
//!
//! impl State for Screen {
//! fn new() -> Result<Screen> {
//! Ok(Screen)
//! }
//! }
//!
//! fn main() {
//! run::<Screen>("Hello World", Vector::new(800, 600), Default::default());
//! }
//! ```
//! Let's start with importing what we need from Quicksilver:
//! ```no_run
//! extern crate quicksilver;
//!
//! use quicksilver::{
//! Result,
//! geom::Vector,
//! lifecycle::{State, run}
//! };
//! ```
//!
//! Quicksilver has its own `Result` type, which is just the same as `std::result::Result<T, quicksilver::Error>`.
//! We use `Vector` for anything 2-dimensional: position, speed, or size, for example.
//! `State` is the trait that defines how we handle the core loop of Quicksilver
//! `run` is the function that kicks off the core loop.
//!
//! Next we declare our `State` handler:
//! ```no_run
//! struct Screen;
//! ```
//! It's a unit struct (a struct with no fields) because we don't need to store anything.
//!
//! Now we implement `State` for our handler:
//!
//! ```no_run
//! # use quicksilver::{
//! # Result,
//! # geom::Vector,
//! # lifecycle::{State, run}
//! # };
//! # struct Screen;
//! impl State for Screen {
//! fn new() -> Result<Screen> {
//! Ok(Screen)
//! }
//! }
//! ```
//! All we have to do is implement the `new` function, and Quicksilver will take care of all the other functions.
//! The other functions we could override are `draw`, `update`, and `event`, which will be covered in later tutorials.
//! ```no_run
//! # use quicksilver::{
//! # Result,
//! # geom::Vector,
//! # lifecycle::{State, run}
//! # };
//! # struct Screen;
//! # impl State for Screen {
//! # fn new() -> Result<Screen> {
//! # Ok(Screen)
//! # }
//! # }
//! fn main() {
//! run::<Screen>("Hello World", Vector::new(800, 600), Default::default());
//! }
//! ```
//! Lastly, we create a main that calls `run`, starting the event loop and showing our window