-
Notifications
You must be signed in to change notification settings - Fork 6
/
canvas_window.rs
42 lines (36 loc) · 1.27 KB
/
canvas_window.rs
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
use flo_draw::*;
use flo_canvas::*;
///
/// Simple example that displays a canvas window and renders a triangle
///
pub fn main() {
// 'with_2d_graphics' is used to support operating systems that can't run event loops anywhere other than the main thread
with_2d_graphics(|| {
// Create a window
let canvas = create_drawing_window("Canvas window");
// Render a triangle to it
canvas.draw(|gc| {
// Clear the canvas and set up the coordinates
gc.clear_canvas(Color::Rgba(0.3, 0.2, 0.0, 1.0));
gc.canvas_height(1000.0);
gc.center_region(0.0, 0.0, 1000.0, 1000.0);
// Draw a rectangle...
gc.new_path();
gc.move_to(0.0, 0.0);
gc.line_to(1000.0, 0.0);
gc.line_to(1000.0, 1000.0);
gc.line_to(0.0, 1000.0);
gc.line_to(0.0, 0.0);
gc.fill_color(Color::Rgba(1.0, 1.0, 0.8, 1.0));
gc.fill();
// Draw a triangle on top
gc.new_path();
gc.move_to(200.0, 200.0);
gc.line_to(800.0, 200.0);
gc.line_to(500.0, 800.0);
gc.line_to(200.0, 200.0);
gc.fill_color(Color::Rgba(0.0, 0.0, 0.8, 1.0));
gc.fill();
});
});
}