-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the 'input' module to replace 'lifecycle' (#604)
First, the 'lifecycle' concept is less important than in previous versions. There is just a single 'run' function that takes a Settings instance and a closure, instead of a whole mess of behind-the-scenes work. Most of the 'lifecycle' module (with the exception of a few Window functions) is just about receiving input from the user. The new name makes this more clear. Additionally, there were some ergonomic issues with re-exporting blinds structures rather than wrapping them in new code. Primarily, this required understanding "what is the mint crate" and "why do I care" and "how do I use it." End users of Quicksilver shouldn't have to concern themselves with this, so these parts of the blinds API have been wrapped over. The Settings struct also needed to be decoupled from blinds. There are more settings than just window management (for example, disable searching for 'static/' assets) so there are now Quicksilver-specific Settings. The old module and its members have been left around for convenience, because the alpha frequently requires updating for new features or critical bugfixes. However, they are strongly deprecated and will be subject to removal before beta. Also, re-export Graphics and Input at the top level. They are needed in literally every Quicksilver application, because you need to name the types to run 'app.'
- Loading branch information
1 parent
4c0cb68
commit d105757
Showing
20 changed files
with
633 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Example 8: Input | ||
// Respond to user keyboard and mouse input onscreen | ||
use quicksilver::{ | ||
geom::{Circle, Rectangle, Vector}, | ||
graphics::Color, | ||
input::Key, | ||
run, Graphics, Input, Result, Settings, Window, | ||
}; | ||
|
||
fn main() { | ||
run( | ||
Settings { | ||
title: "Input Example", | ||
..Settings::default() | ||
}, | ||
app, | ||
); | ||
} | ||
|
||
async fn app(window: Window, mut gfx: Graphics, mut input: Input) -> Result<()> { | ||
// Keep track of the position of the square | ||
let mut square_position = Vector::new(300, 300); | ||
loop { | ||
while let Some(_) = input.next_event().await {} | ||
// Check the state of the keys, and move the square accordingly | ||
const SPEED: f32 = 2.0; | ||
if input.key_down(Key::A) { | ||
square_position.x -= SPEED; | ||
} | ||
if input.key_down(Key::D) { | ||
square_position.x += SPEED; | ||
} | ||
if input.key_down(Key::W) { | ||
square_position.y -= SPEED; | ||
} | ||
if input.key_down(Key::S) { | ||
square_position.y += SPEED; | ||
} | ||
|
||
gfx.clear(Color::WHITE); | ||
// Paint a blue square at the given position | ||
gfx.fill_rect( | ||
&Rectangle::new(square_position, Vector::new(64.0, 64.0)), | ||
Color::BLUE, | ||
); | ||
// Paint a red square at the mouse position | ||
gfx.fill_circle(&Circle::new(input.mouse().location(), 32.0), Color::RED); | ||
gfx.present(&window)?; | ||
} | ||
} |
Oops, something went wrong.