-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtext.rs
More file actions
100 lines (86 loc) · 2.85 KB
/
Copy pathtext.rs
File metadata and controls
100 lines (86 loc) · 2.85 KB
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
use bevy::prelude::Color;
use processing_glfw::GlfwContext;
use processing::prelude::*;
use processing_render::render::command::DrawCommand;
fn main() {
match sketch() {
Ok(_) => {
eprintln!("Sketch completed successfully");
exit(0).unwrap();
}
Err(e) => {
eprintln!("Sketch error: {:?}", e);
exit(1).unwrap();
}
};
}
fn sketch() -> error::Result<()> {
let mut glfw_ctx = GlfwContext::new(600, 400)?;
init(Config::default())?;
let width = 600;
let height = 400;
let surface = glfw_ctx.create_surface(width, height)?;
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
while glfw_ctx.poll_events() {
graphics_begin_draw(graphics)?;
graphics_record_command(graphics, DrawCommand::BackgroundColor(Color::WHITE))?;
graphics_record_command(graphics, DrawCommand::Fill(Color::BLACK))?;
graphics_record_command(graphics, DrawCommand::TextSize(32.0))?;
graphics_record_command(
graphics,
DrawCommand::Text {
content: "Hello, Processing!".to_string(),
x: 50.0,
y: 100.0,
z: 0.0,
max_w: None,
max_h: None,
},
)?;
graphics_record_command(graphics, DrawCommand::TextSize(18.0))?;
graphics_record_command(
graphics,
DrawCommand::Text {
content: "Text rendering with parley + skrifa + lyon".to_string(),
x: 50.0,
y: 160.0,
z: 0.0,
max_w: None,
max_h: None,
},
)?;
graphics_record_command(graphics, DrawCommand::TextSize(16.0))?;
graphics_record_command(
graphics,
DrawCommand::Text {
content: "This is a longer paragraph of text that should wrap within its bounding box. The text uses parley for layout, skrifa for glyph outlines, and lyon for tessellation.".to_string(),
x: 50.0,
y: 220.0,
z: 0.0,
max_w: Some(300.0),
max_h: Some(200.0),
},
)?;
graphics_record_command(
graphics,
DrawCommand::TextAlign {
h: TextAlignH::Center,
v: TextAlignV::Top,
},
)?;
graphics_record_command(graphics, DrawCommand::TextSize(24.0))?;
graphics_record_command(
graphics,
DrawCommand::Text {
content: "Centered".to_string(),
x: 450.0,
y: 100.0,
z: 0.0,
max_w: Some(200.0),
max_h: None,
},
)?;
graphics_end_draw(graphics)?;
}
Ok(())
}