Skip to main content

DrawHandle

Struct DrawHandle 

Source
pub struct DrawHandle<'a> {
    pub draw: RaylibDrawHandle<'a>,
}
Expand description

Handle de dibujo (Raylib = Pincel)

Se obtiene de RyditGfx::begin_draw() y se usa para dibujar. Al salir de scope, automáticamente finaliza el dibujo.

Fields§

§draw: RaylibDrawHandle<'a>

Implementations§

Source§

impl<'a> DrawHandle<'a>

Source

pub fn clear(&mut self, color: ColorRydit)

Limpiar con color

Examples found in repository?
examples/demo.rs (line 29)
6fn main() {
7    println!("=== RYDIT-GFX v0.1.0 ===");
8    println!("Rust = Arquitecto, Raylib = Pincel\n");
9
10    // Crear ventana (Rust controla)
11    let mut gfx = RyditGfx::new("RyDit v0.0.7 - rydit-gfx", 800, 600);
12    gfx.set_target_fps(60);
13
14    println!("[RUST] Ventana creada, iniciando game loop...\n");
15
16    // Game loop controlado por Rust
17    let mut frame = 0;
18    while !gfx.should_close() {
19        frame += 1;
20
21        // Rust decide input PRIMERO (antes de dibujar)
22        let escape_pressed = gfx.is_key_pressed(Key::Escape);
23
24        // Iniciar dibujo (toma &mut self, no podemos usar gfx después)
25        {
26            let mut d = gfx.begin_draw();
27
28            // Limpiar pantalla
29            d.clear(ColorRydit::Negro);
30
31            // Dibujar círculo rojo en el centro (animado)
32            let radius = 50 + (frame % 20);
33            d.draw_circle(400, 300, radius, ColorRydit::Rojo);
34
35            // Dibujar rectángulo verde
36            d.draw_rectangle(100, 100, 100, 100, ColorRydit::Verde);
37
38            // Dibujar línea azul
39            d.draw_line(0, 0, 800, 600, ColorRydit::Azul);
40
41            // Dibujar texto
42            d.draw_text(
43                "RyDit v0.0.7 - rydit-gfx",
44                250,
45                50,
46                20,
47                ColorRydit::Amarillo,
48            );
49            d.draw_text(
50                "Rust = Arquitecto, Raylib = Pincel",
51                220,
52                80,
53                16,
54                ColorRydit::Blanco,
55            );
56            d.draw_text("Presiona ESC para salir", 280, 550, 16, ColorRydit::Blanco);
57
58            // d se va de scope aquí, finaliza dibujo
59        }
60
61        // Rust decide después de dibujar
62        if escape_pressed {
63            println!("\n[RUST] Decidiendo cerrar en frame {}...", frame);
64            break;
65        }
66    }
67
68    println!("\n[RUST] Juego terminado. ¡Éxito!");
69}
Source

pub fn draw_circle(&mut self, x: i32, y: i32, radius: i32, color: ColorRydit)

Dibujar círculo

Examples found in repository?
examples/demo.rs (line 33)
6fn main() {
7    println!("=== RYDIT-GFX v0.1.0 ===");
8    println!("Rust = Arquitecto, Raylib = Pincel\n");
9
10    // Crear ventana (Rust controla)
11    let mut gfx = RyditGfx::new("RyDit v0.0.7 - rydit-gfx", 800, 600);
12    gfx.set_target_fps(60);
13
14    println!("[RUST] Ventana creada, iniciando game loop...\n");
15
16    // Game loop controlado por Rust
17    let mut frame = 0;
18    while !gfx.should_close() {
19        frame += 1;
20
21        // Rust decide input PRIMERO (antes de dibujar)
22        let escape_pressed = gfx.is_key_pressed(Key::Escape);
23
24        // Iniciar dibujo (toma &mut self, no podemos usar gfx después)
25        {
26            let mut d = gfx.begin_draw();
27
28            // Limpiar pantalla
29            d.clear(ColorRydit::Negro);
30
31            // Dibujar círculo rojo en el centro (animado)
32            let radius = 50 + (frame % 20);
33            d.draw_circle(400, 300, radius, ColorRydit::Rojo);
34
35            // Dibujar rectángulo verde
36            d.draw_rectangle(100, 100, 100, 100, ColorRydit::Verde);
37
38            // Dibujar línea azul
39            d.draw_line(0, 0, 800, 600, ColorRydit::Azul);
40
41            // Dibujar texto
42            d.draw_text(
43                "RyDit v0.0.7 - rydit-gfx",
44                250,
45                50,
46                20,
47                ColorRydit::Amarillo,
48            );
49            d.draw_text(
50                "Rust = Arquitecto, Raylib = Pincel",
51                220,
52                80,
53                16,
54                ColorRydit::Blanco,
55            );
56            d.draw_text("Presiona ESC para salir", 280, 550, 16, ColorRydit::Blanco);
57
58            // d se va de scope aquí, finaliza dibujo
59        }
60
61        // Rust decide después de dibujar
62        if escape_pressed {
63            println!("\n[RUST] Decidiendo cerrar en frame {}...", frame);
64            break;
65        }
66    }
67
68    println!("\n[RUST] Juego terminado. ¡Éxito!");
69}
Source

pub fn draw_rectangle( &mut self, x: i32, y: i32, w: i32, h: i32, color: ColorRydit, )

Dibujar rectángulo

Examples found in repository?
examples/demo.rs (line 36)
6fn main() {
7    println!("=== RYDIT-GFX v0.1.0 ===");
8    println!("Rust = Arquitecto, Raylib = Pincel\n");
9
10    // Crear ventana (Rust controla)
11    let mut gfx = RyditGfx::new("RyDit v0.0.7 - rydit-gfx", 800, 600);
12    gfx.set_target_fps(60);
13
14    println!("[RUST] Ventana creada, iniciando game loop...\n");
15
16    // Game loop controlado por Rust
17    let mut frame = 0;
18    while !gfx.should_close() {
19        frame += 1;
20
21        // Rust decide input PRIMERO (antes de dibujar)
22        let escape_pressed = gfx.is_key_pressed(Key::Escape);
23
24        // Iniciar dibujo (toma &mut self, no podemos usar gfx después)
25        {
26            let mut d = gfx.begin_draw();
27
28            // Limpiar pantalla
29            d.clear(ColorRydit::Negro);
30
31            // Dibujar círculo rojo en el centro (animado)
32            let radius = 50 + (frame % 20);
33            d.draw_circle(400, 300, radius, ColorRydit::Rojo);
34
35            // Dibujar rectángulo verde
36            d.draw_rectangle(100, 100, 100, 100, ColorRydit::Verde);
37
38            // Dibujar línea azul
39            d.draw_line(0, 0, 800, 600, ColorRydit::Azul);
40
41            // Dibujar texto
42            d.draw_text(
43                "RyDit v0.0.7 - rydit-gfx",
44                250,
45                50,
46                20,
47                ColorRydit::Amarillo,
48            );
49            d.draw_text(
50                "Rust = Arquitecto, Raylib = Pincel",
51                220,
52                80,
53                16,
54                ColorRydit::Blanco,
55            );
56            d.draw_text("Presiona ESC para salir", 280, 550, 16, ColorRydit::Blanco);
57
58            // d se va de scope aquí, finaliza dibujo
59        }
60
61        // Rust decide después de dibujar
62        if escape_pressed {
63            println!("\n[RUST] Decidiendo cerrar en frame {}...", frame);
64            break;
65        }
66    }
67
68    println!("\n[RUST] Juego terminado. ¡Éxito!");
69}
Source

pub fn draw_line( &mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: ColorRydit, )

Dibujar línea

Examples found in repository?
examples/demo.rs (line 39)
6fn main() {
7    println!("=== RYDIT-GFX v0.1.0 ===");
8    println!("Rust = Arquitecto, Raylib = Pincel\n");
9
10    // Crear ventana (Rust controla)
11    let mut gfx = RyditGfx::new("RyDit v0.0.7 - rydit-gfx", 800, 600);
12    gfx.set_target_fps(60);
13
14    println!("[RUST] Ventana creada, iniciando game loop...\n");
15
16    // Game loop controlado por Rust
17    let mut frame = 0;
18    while !gfx.should_close() {
19        frame += 1;
20
21        // Rust decide input PRIMERO (antes de dibujar)
22        let escape_pressed = gfx.is_key_pressed(Key::Escape);
23
24        // Iniciar dibujo (toma &mut self, no podemos usar gfx después)
25        {
26            let mut d = gfx.begin_draw();
27
28            // Limpiar pantalla
29            d.clear(ColorRydit::Negro);
30
31            // Dibujar círculo rojo en el centro (animado)
32            let radius = 50 + (frame % 20);
33            d.draw_circle(400, 300, radius, ColorRydit::Rojo);
34
35            // Dibujar rectángulo verde
36            d.draw_rectangle(100, 100, 100, 100, ColorRydit::Verde);
37
38            // Dibujar línea azul
39            d.draw_line(0, 0, 800, 600, ColorRydit::Azul);
40
41            // Dibujar texto
42            d.draw_text(
43                "RyDit v0.0.7 - rydit-gfx",
44                250,
45                50,
46                20,
47                ColorRydit::Amarillo,
48            );
49            d.draw_text(
50                "Rust = Arquitecto, Raylib = Pincel",
51                220,
52                80,
53                16,
54                ColorRydit::Blanco,
55            );
56            d.draw_text("Presiona ESC para salir", 280, 550, 16, ColorRydit::Blanco);
57
58            // d se va de scope aquí, finaliza dibujo
59        }
60
61        // Rust decide después de dibujar
62        if escape_pressed {
63            println!("\n[RUST] Decidiendo cerrar en frame {}...", frame);
64            break;
65        }
66    }
67
68    println!("\n[RUST] Juego terminado. ¡Éxito!");
69}
Source

pub fn draw_text( &mut self, text: &str, x: i32, y: i32, size: i32, color: ColorRydit, )

Dibujar texto

Examples found in repository?
examples/demo.rs (lines 42-48)
6fn main() {
7    println!("=== RYDIT-GFX v0.1.0 ===");
8    println!("Rust = Arquitecto, Raylib = Pincel\n");
9
10    // Crear ventana (Rust controla)
11    let mut gfx = RyditGfx::new("RyDit v0.0.7 - rydit-gfx", 800, 600);
12    gfx.set_target_fps(60);
13
14    println!("[RUST] Ventana creada, iniciando game loop...\n");
15
16    // Game loop controlado por Rust
17    let mut frame = 0;
18    while !gfx.should_close() {
19        frame += 1;
20
21        // Rust decide input PRIMERO (antes de dibujar)
22        let escape_pressed = gfx.is_key_pressed(Key::Escape);
23
24        // Iniciar dibujo (toma &mut self, no podemos usar gfx después)
25        {
26            let mut d = gfx.begin_draw();
27
28            // Limpiar pantalla
29            d.clear(ColorRydit::Negro);
30
31            // Dibujar círculo rojo en el centro (animado)
32            let radius = 50 + (frame % 20);
33            d.draw_circle(400, 300, radius, ColorRydit::Rojo);
34
35            // Dibujar rectángulo verde
36            d.draw_rectangle(100, 100, 100, 100, ColorRydit::Verde);
37
38            // Dibujar línea azul
39            d.draw_line(0, 0, 800, 600, ColorRydit::Azul);
40
41            // Dibujar texto
42            d.draw_text(
43                "RyDit v0.0.7 - rydit-gfx",
44                250,
45                50,
46                20,
47                ColorRydit::Amarillo,
48            );
49            d.draw_text(
50                "Rust = Arquitecto, Raylib = Pincel",
51                220,
52                80,
53                16,
54                ColorRydit::Blanco,
55            );
56            d.draw_text("Presiona ESC para salir", 280, 550, 16, ColorRydit::Blanco);
57
58            // d se va de scope aquí, finaliza dibujo
59        }
60
61        // Rust decide después de dibujar
62        if escape_pressed {
63            println!("\n[RUST] Decidiendo cerrar en frame {}...", frame);
64            break;
65        }
66    }
67
68    println!("\n[RUST] Juego terminado. ¡Éxito!");
69}
Source

pub fn draw_triangle( &mut self, v1: (i32, i32), v2: (i32, i32), v3: (i32, i32), color: ColorRydit, )

Dibujar triángulo

Source

pub fn draw_triangle_lines( &mut self, v1: (i32, i32), v2: (i32, i32), v3: (i32, i32), color: ColorRydit, )

Dibujar triángulo con líneas (outline)

Source

pub fn draw_rectangle_lines( &mut self, x: i32, y: i32, w: i32, h: i32, color: ColorRydit, )

Dibujar rectángulo con líneas (outline)

Source

pub fn draw_ring( &mut self, center: (i32, i32), _inner_radius: i32, outer_radius: i32, color: ColorRydit, )

Dibujar anillo (ring)

Source

pub fn draw_ellipse( &mut self, center: (i32, i32), radius_h: i32, radius_v: i32, color: ColorRydit, )

Dibujar elipse

Source

pub fn draw_line_thick( &mut self, start_pos: (i32, i32), end_pos: (i32, i32), thick: f32, color: ColorRydit, )

Dibujar línea gruesa

Source

pub fn draw_rectangle_pro( &mut self, x: i32, y: i32, width: i32, height: i32, angle: f32, color: ColorRydit, )

Dibujar rectángulo rotado

Source

pub fn draw_texture_ex( &mut self, texture: &Texture2D, position: Vector2, rotation: f32, scale: f32, color: Color, )

Dibujar textura avanzada

Trait Implementations§

Source§

impl<'a> Drop for DrawHandle<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for DrawHandle<'a>

§

impl<'a> RefUnwindSafe for DrawHandle<'a>

§

impl<'a> Send for DrawHandle<'a>

§

impl<'a> Sync for DrawHandle<'a>

§

impl<'a> Unpin for DrawHandle<'a>

§

impl<'a> UnsafeUnpin for DrawHandle<'a>

§

impl<'a> !UnwindSafe for DrawHandle<'a>

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, 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.