pub struct Context<'a> {
pub dt: f64,
pub mouse_x: f64,
pub mouse_y: f64,
/* private fields */
}Fields§
§dt: f64§mouse_x: f64§mouse_y: f64Implementations§
Source§impl<'a> Context<'a>
impl<'a> Context<'a>
Sourcepub fn width(&self) -> f64
pub fn width(&self) -> f64
Examples found in repository?
examples/mouse.rs (line 9)
3fn main() {
4 jp::create_window("Test", 150, 150)
5 .draw(|mut g, c| {
6 g.rectangle(
7 c.state()
8 .fill([1.0, 1.0, 1.0, 1.0]),
9 c.width(),
10 c.height()
11 );
12 g.rectangle(
13 c.state()
14 .translate(c.mouse_x, c.mouse_y)
15 .fill([1.0, 0.0, 0.0, 1.0]),
16 50.0, 50.0);
17 })
18 .run();
19}More examples
examples/most_basic.rs (line 8)
3fn main() {
4 jp::create_window("Test", 150, 150)
5 .draw(|mut g, c| {
6 g.rectangle(
7 c.state()
8 .translate(c.width() / 2.0, c.height() / 2.0)
9 .fill([1.0, 0.0, 0.0, 1.0]),
10 50, 50);
11 g.ellipse(
12 c.state()
13 .translate(c.width() / 2.0, c.height() / 2.0)
14 .fill([0.0, 1.0, 0.0, 1.0]),
15 50, 50);
16 })
17 .run();
18}examples/spinning.rs (line 12)
5fn main() {
6 let mut angle = 0.0;
7 jp::create_window("Test", 150, 150)
8 .draw(move |mut g, c| {
9 g.rectangle(
10 c.state()
11 .fill([1.0, 1.0, 1.0, 1.0]),
12 c.width(),
13 c.height()
14 );
15 g.rectangle(
16 c.state()
17 .translate(c.width() / 2.0, c.height() / 2.0)
18 .rotate(angle)
19 .translate(-RADIUS, -RADIUS)
20 .fill([1.0, 0.0, 0.0, 1.0])
21 .stroke([0.0, 1.0, 0.0, 1.0]),
22 RADIUS * 2.0, RADIUS * 2.0);
23 angle += c.dt * 3.0;
24 })
25 .run();
26}examples/keyboard.rs (line 11)
3fn main() {
4 let mut pos_x = 75.0;
5 let mut pos_y = 75.0;
6 jp::create_window("Test", 150, 150)
7 .draw(move |mut g, c| {
8 g.rectangle(
9 c.state()
10 .fill([1.0, 1.0, 1.0, 1.0]),
11 c.width(),
12 c.height()
13 );
14 g.rectangle(
15 c.state()
16 .translate(pos_x, pos_y)
17 .fill([1.0, 0.0, 0.0, 1.0]),
18 50.0, 50.0);
19 let speed = c.dt * 40.0;
20 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Left)) {
21 pos_x -= speed;
22 }
23 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Right)) {
24 pos_x += speed;
25 }
26 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Up)) {
27 pos_y -= speed;
28 }
29 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Down)) {
30 pos_y += speed;
31 }
32 })
33 .run();
34}Sourcepub fn height(&self) -> f64
pub fn height(&self) -> f64
Examples found in repository?
examples/mouse.rs (line 10)
3fn main() {
4 jp::create_window("Test", 150, 150)
5 .draw(|mut g, c| {
6 g.rectangle(
7 c.state()
8 .fill([1.0, 1.0, 1.0, 1.0]),
9 c.width(),
10 c.height()
11 );
12 g.rectangle(
13 c.state()
14 .translate(c.mouse_x, c.mouse_y)
15 .fill([1.0, 0.0, 0.0, 1.0]),
16 50.0, 50.0);
17 })
18 .run();
19}More examples
examples/most_basic.rs (line 8)
3fn main() {
4 jp::create_window("Test", 150, 150)
5 .draw(|mut g, c| {
6 g.rectangle(
7 c.state()
8 .translate(c.width() / 2.0, c.height() / 2.0)
9 .fill([1.0, 0.0, 0.0, 1.0]),
10 50, 50);
11 g.ellipse(
12 c.state()
13 .translate(c.width() / 2.0, c.height() / 2.0)
14 .fill([0.0, 1.0, 0.0, 1.0]),
15 50, 50);
16 })
17 .run();
18}examples/spinning.rs (line 13)
5fn main() {
6 let mut angle = 0.0;
7 jp::create_window("Test", 150, 150)
8 .draw(move |mut g, c| {
9 g.rectangle(
10 c.state()
11 .fill([1.0, 1.0, 1.0, 1.0]),
12 c.width(),
13 c.height()
14 );
15 g.rectangle(
16 c.state()
17 .translate(c.width() / 2.0, c.height() / 2.0)
18 .rotate(angle)
19 .translate(-RADIUS, -RADIUS)
20 .fill([1.0, 0.0, 0.0, 1.0])
21 .stroke([0.0, 1.0, 0.0, 1.0]),
22 RADIUS * 2.0, RADIUS * 2.0);
23 angle += c.dt * 3.0;
24 })
25 .run();
26}examples/keyboard.rs (line 12)
3fn main() {
4 let mut pos_x = 75.0;
5 let mut pos_y = 75.0;
6 jp::create_window("Test", 150, 150)
7 .draw(move |mut g, c| {
8 g.rectangle(
9 c.state()
10 .fill([1.0, 1.0, 1.0, 1.0]),
11 c.width(),
12 c.height()
13 );
14 g.rectangle(
15 c.state()
16 .translate(pos_x, pos_y)
17 .fill([1.0, 0.0, 0.0, 1.0]),
18 50.0, 50.0);
19 let speed = c.dt * 40.0;
20 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Left)) {
21 pos_x -= speed;
22 }
23 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Right)) {
24 pos_x += speed;
25 }
26 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Up)) {
27 pos_y -= speed;
28 }
29 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Down)) {
30 pos_y += speed;
31 }
32 })
33 .run();
34}Sourcepub fn state(&self) -> DrawState
pub fn state(&self) -> DrawState
Examples found in repository?
examples/mouse.rs (line 7)
3fn main() {
4 jp::create_window("Test", 150, 150)
5 .draw(|mut g, c| {
6 g.rectangle(
7 c.state()
8 .fill([1.0, 1.0, 1.0, 1.0]),
9 c.width(),
10 c.height()
11 );
12 g.rectangle(
13 c.state()
14 .translate(c.mouse_x, c.mouse_y)
15 .fill([1.0, 0.0, 0.0, 1.0]),
16 50.0, 50.0);
17 })
18 .run();
19}More examples
examples/most_basic.rs (line 7)
3fn main() {
4 jp::create_window("Test", 150, 150)
5 .draw(|mut g, c| {
6 g.rectangle(
7 c.state()
8 .translate(c.width() / 2.0, c.height() / 2.0)
9 .fill([1.0, 0.0, 0.0, 1.0]),
10 50, 50);
11 g.ellipse(
12 c.state()
13 .translate(c.width() / 2.0, c.height() / 2.0)
14 .fill([0.0, 1.0, 0.0, 1.0]),
15 50, 50);
16 })
17 .run();
18}examples/spinning.rs (line 10)
5fn main() {
6 let mut angle = 0.0;
7 jp::create_window("Test", 150, 150)
8 .draw(move |mut g, c| {
9 g.rectangle(
10 c.state()
11 .fill([1.0, 1.0, 1.0, 1.0]),
12 c.width(),
13 c.height()
14 );
15 g.rectangle(
16 c.state()
17 .translate(c.width() / 2.0, c.height() / 2.0)
18 .rotate(angle)
19 .translate(-RADIUS, -RADIUS)
20 .fill([1.0, 0.0, 0.0, 1.0])
21 .stroke([0.0, 1.0, 0.0, 1.0]),
22 RADIUS * 2.0, RADIUS * 2.0);
23 angle += c.dt * 3.0;
24 })
25 .run();
26}examples/keyboard.rs (line 9)
3fn main() {
4 let mut pos_x = 75.0;
5 let mut pos_y = 75.0;
6 jp::create_window("Test", 150, 150)
7 .draw(move |mut g, c| {
8 g.rectangle(
9 c.state()
10 .fill([1.0, 1.0, 1.0, 1.0]),
11 c.width(),
12 c.height()
13 );
14 g.rectangle(
15 c.state()
16 .translate(pos_x, pos_y)
17 .fill([1.0, 0.0, 0.0, 1.0]),
18 50.0, 50.0);
19 let speed = c.dt * 40.0;
20 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Left)) {
21 pos_x -= speed;
22 }
23 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Right)) {
24 pos_x += speed;
25 }
26 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Up)) {
27 pos_y -= speed;
28 }
29 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Down)) {
30 pos_y += speed;
31 }
32 })
33 .run();
34}Sourcepub fn is_pressed(&self, button: Button) -> bool
pub fn is_pressed(&self, button: Button) -> bool
Examples found in repository?
examples/keyboard.rs (line 20)
3fn main() {
4 let mut pos_x = 75.0;
5 let mut pos_y = 75.0;
6 jp::create_window("Test", 150, 150)
7 .draw(move |mut g, c| {
8 g.rectangle(
9 c.state()
10 .fill([1.0, 1.0, 1.0, 1.0]),
11 c.width(),
12 c.height()
13 );
14 g.rectangle(
15 c.state()
16 .translate(pos_x, pos_y)
17 .fill([1.0, 0.0, 0.0, 1.0]),
18 50.0, 50.0);
19 let speed = c.dt * 40.0;
20 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Left)) {
21 pos_x -= speed;
22 }
23 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Right)) {
24 pos_x += speed;
25 }
26 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Up)) {
27 pos_y -= speed;
28 }
29 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Down)) {
30 pos_y += speed;
31 }
32 })
33 .run();
34}Auto Trait Implementations§
impl<'a> Freeze for Context<'a>
impl<'a> RefUnwindSafe for Context<'a>
impl<'a> Send for Context<'a>
impl<'a> Sync for Context<'a>
impl<'a> Unpin for Context<'a>
impl<'a> UnwindSafe for Context<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more