1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
pub mod canvas;
pub mod utils;
fn test_all() {
use canvas::{Canvas, Color, Text, Line};
use utils::{FontHandler, Image};
let handler = FontHandler::find_fonts("SourceCodePro".to_string()).unwrap();
let mut canvas = Canvas::new((800, 800), "ha".to_string(), Color::RED);
let _ = canvas.create_from_text(&Text::new(
Some("From Text"),
20,
Color::WHITE,
(400., 500.),
));
canvas.create_circle((15., 18.), 200., Color::BLUE, None, None).unwrap();
canvas.create_rectangle((1., 1.), (200., 200.), Color::CYAN, None, None).unwrap();
canvas
.create_text((500., 500.), "Hello", 50, "Arial", Color::WHITE)
.unwrap();
let line = Line::new((200., 200.), (400., 400.), 12.,Color::WHITE).unwrap();
canvas.create_from_line(&line).unwrap();
let image = Image::from_file("~/programming/rust/canrust/1990_praisethesun.png", (80., 300.)).unwrap();
canvas.create_from_image(&image).unwrap();
canvas.mainloop()
}
fn test_fonts() {
use canvas::{Canvas, Text, Color};
let mut canvas = Canvas::new((800, 600), "ha".to_string(), Color::WHITE);
let mut text = Text::new(Some("This is a font test ha"), 50, Color::RED, (1., 1.));
text.set_font("sourcecodepro".to_string()).unwrap();
canvas.create_from_text(&text).unwrap();
canvas.mainloop()
}
fn bind_test() {
use canvas::{Canvas, Color};
let mut canvas = Canvas::new((800, 800), "ha".to_string(), Color::WHITE);
canvas.create_circle((1., 1.), 20., Color::BLACK, None, None).unwrap();
canvas.create_rectangle((20., 20.), (30., 80.), Color::BLACK, None, None).unwrap();
canvas.create_line((18., 20.), (18., 80.), 2., Color::RED, None, None).unwrap();
canvas.create_line((32., 20.), (32., 80.), 2., Color::RED, None, None).unwrap();
canvas.mainloop();
}
use canvas::Canvas;
fn hello(can: &mut Canvas) {
use canvas::Color;
println!("hello from hello");
for i in 0..5 {
let num = i as f32 * 10.;
let ha = i as f32 * 20.;
can.create_circle((56.+ha, 64.+ha), 10., Color::RED, None, None).unwrap();
}
}
#[cfg(test)]
#[test]
fn mouse_test () {
use canvas::{Color, Canvas};
let mut canvas = Canvas::new((800, 800), "ha".to_string(), Color::WHITE);
canvas.bind_mouse("<Button1>", mouse).unwrap();
canvas.mainloop()
}
fn mouse(can: &mut Canvas, pos: (f32, f32)) {
use canvas::Color;
can.create_line(pos, (pos.0+30., pos.1+40.), 4., Color::RED, None, None).unwrap()
}