DrawState

Struct DrawState 

Source
pub struct DrawState { /* private fields */ }

Implementations§

Source§

impl DrawState

Source

pub fn fill(self, color: Color) -> Self

Examples found in repository?
examples/mouse.rs (line 8)
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
Hide additional examples
examples/most_basic.rs (line 9)
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 11)
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 10)
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}
Source

pub fn stroke(self, color: Color) -> Self

Examples found in repository?
examples/spinning.rs (line 21)
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}
Source

pub fn translate<X: Into<f64>, Y: Into<f64>>(self, x: X, y: Y) -> Self

Examples found in repository?
examples/mouse.rs (line 14)
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
Hide additional 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 17)
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 16)
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}
Source

pub fn rotate<A: Into<f64>>(self, angle: A) -> Self

Examples found in repository?
examples/spinning.rs (line 18)
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}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.