WireLine

Struct WireLine 

Source
pub struct WireLine {
    pub start: FPoint,
    pub end: FPoint,
    pub params: WireParams,
}
Expand description

Represents a wire that will be rendered with drooping effect

Fields§

§start: FPoint§end: FPoint§params: WireParams

Implementations§

Source§

impl WireLine

Source

pub fn new(x1: f32, y1: f32, x2: f32, y2: f32, params: WireParams) -> Self

Create a new wire line from coordinates and parameters

Examples found in repository?
examples/basic.rs (lines 21-34)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Initialize SDL3
7    let sdl = sdl3::init()?;
8    let video = sdl.video()?;
9
10    // Create window
11    let window = video
12        .window("Hotwire - Basic Example", 800, 600)
13        .position_centered()
14        .build()
15        .map_err(|e| e.to_string())?;
16
17    let canvas = window.into_canvas();
18    let mut renderer = WireRenderer::new(canvas);
19
20    // Create a horizontal drooping wire
21    let wire_line = WireLine::new(
22        100.0,
23        200.0,
24        700.0,
25        200.0,
26        WireParams {
27            sag: 80.0,
28            thickness: 4.0,
29            sway_speed: 1.0,
30            sway_amount: 3.0,
31            segment_density: 2.0,
32            color: Color::RGB(160, 160, 160),
33        },
34    );
35
36    let mut event_pump = sdl.event_pump()?;
37
38    'running: loop {
39        // Handle events
40        for event in event_pump.poll_iter() {
41            match event {
42                Event::Quit { .. } => break 'running,
43                _ => {}
44            }
45        }
46
47        // Clear canvas
48        renderer.canvas_mut().set_draw_color(Color::RGB(20, 20, 30));
49        renderer.canvas_mut().clear();
50
51        // Render wire line (static, no animation)
52        renderer.render(&wire_line, 0.0)?;
53
54        // Present
55        renderer.present();
56
57        // Small delay
58        std::thread::sleep(std::time::Duration::from_millis(16));
59    }
60
61    Ok(())
62}
More examples
Hide additional examples
examples/animated.rs (lines 23-36)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    // Initialize SDL3
8    let sdl = sdl3::init()?;
9    let video = sdl.video()?;
10
11    // Create window
12    let window = video
13        .window("Hotwire - Animated Example", 800, 600)
14        .position_centered()
15        .build()
16        .map_err(|e| e.to_string())?;
17
18    let canvas = window.into_canvas();
19    let mut renderer = WireRenderer::new(canvas);
20
21    // Create multiple drooping wires with different parameters
22    let lines = vec![
23        WireLine::new(
24            100.0,
25            150.0,
26            700.0,
27            150.0,
28            WireParams {
29                sag: 60.0,
30                thickness: 3.0,
31                sway_speed: 1.0,
32                sway_amount: 4.0,
33                segment_density: 2.0,
34                color: Color::RGB(200, 180, 160),
35            },
36        ),
37        WireLine::new(
38            150.0,
39            250.0,
40            650.0,
41            280.0,
42            WireParams {
43                sag: 80.0,
44                thickness: 4.0,
45                sway_speed: 1.5,
46                sway_amount: 6.0,
47                segment_density: 2.5,
48                color: Color::RGB(180, 180, 180),
49            },
50        ),
51        WireLine::new(
52            200.0,
53            380.0,
54            600.0,
55            400.0,
56            WireParams {
57                sag: 50.0,
58                thickness: 2.5,
59                sway_speed: 0.8,
60                sway_amount: 3.0,
61                segment_density: 2.0,
62                color: Color::RGB(160, 140, 120),
63            },
64        ),
65    ];
66
67    let mut event_pump = sdl.event_pump()?;
68    let start_time = Instant::now();
69
70    'running: loop {
71        // Handle events
72        for event in event_pump.poll_iter() {
73            match event {
74                Event::Quit { .. } => break 'running,
75                _ => {}
76            }
77        }
78
79        // Get elapsed time in seconds
80        let time = start_time.elapsed().as_secs_f32();
81
82        // Clear canvas
83        renderer.canvas_mut().set_draw_color(Color::RGB(20, 20, 30));
84        renderer.canvas_mut().clear();
85
86        // Render all wire lines with animation
87        for line in &lines {
88            renderer.render(line, time)?;
89        }
90
91        // Present
92        renderer.present();
93
94        // Small delay
95        std::thread::sleep(std::time::Duration::from_millis(16));
96    }
97
98    Ok(())
99}
examples/interactive.rs (lines 61-67)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    // Initialize SDL3
9    let sdl = sdl3::init()?;
10    let video = sdl.video()?;
11
12    // Create window
13    let window = video
14        .window("Hotwire - Interactive Example (Click and drag to draw)", 800, 600)
15        .position_centered()
16        .build()
17        .map_err(|e| e.to_string())?;
18
19    let canvas = window.into_canvas();
20    let mut renderer = WireRenderer::new(canvas);
21
22    let mut event_pump = sdl.event_pump()?;
23    let start_time = Instant::now();
24
25    let mut lines: Vec<WireLine> = Vec::new();
26    let mut drawing = false;
27    let mut current_start: Option<(f32, f32)> = None;
28
29    let params = WireParams {
30        sag: 70.0,
31        thickness: 3.5,
32        sway_speed: 1.2,
33        sway_amount: 5.0,
34        segment_density: 2.0,
35        color: Color::RGB(180, 180, 180),
36    };
37
38    'running: loop {
39        // Handle events
40        for event in event_pump.poll_iter() {
41            match event {
42                Event::Quit { .. } => break 'running,
43                Event::MouseButtonDown {
44                    mouse_btn: MouseButton::Left,
45                    x,
46                    y,
47                    ..
48                } => {
49                    drawing = true;
50                    current_start = Some((x as f32, y as f32));
51                }
52                Event::MouseButtonUp {
53                    mouse_btn: MouseButton::Left,
54                    x,
55                    y,
56                    ..
57                } => {
58                    if drawing {
59                        if let Some((start_x, start_y)) = current_start {
60                            // Create a new wire line
61                            let line = WireLine::new(
62                                start_x,
63                                start_y,
64                                x as f32,
65                                y as f32,
66                                params,
67                            );
68                            lines.push(line);
69                        }
70                        drawing = false;
71                        current_start = None;
72                    }
73                }
74                Event::KeyDown { .. } => {
75                    // Clear all lines on any key press
76                    lines.clear();
77                }
78                _ => {}
79            }
80        }
81
82        // Get elapsed time in seconds
83        let time = start_time.elapsed().as_secs_f32();
84
85        // Clear canvas
86        renderer.canvas_mut().set_draw_color(Color::RGB(20, 20, 30));
87        renderer.canvas_mut().clear();
88
89        // Render all completed wire lines
90        for line in &lines {
91            renderer.render(line, time)?;
92        }
93
94        // If currently drawing, show a preview line
95        if drawing {
96            if let Some((start_x, start_y)) = current_start {
97                let mouse_state = event_pump.mouse_state();
98                let preview_line = WireLine::new(
99                    start_x,
100                    start_y,
101                    mouse_state.x() as f32,
102                    mouse_state.y() as f32,
103                    params,
104                );
105                renderer.render(&preview_line, time)?;
106            }
107        }
108
109        // Present
110        renderer.present();
111
112        // Small delay
113        std::thread::sleep(std::time::Duration::from_millis(16));
114    }
115
116    Ok(())
117}
Source

pub fn horizontal_distance(&self) -> f32

Get the horizontal distance of the line

Source

pub fn vertical_distance(&self) -> f32

Get the vertical distance of the line

Trait Implementations§

Source§

impl Clone for WireLine

Source§

fn clone(&self) -> WireLine

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WireLine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for WireLine

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V