1use bottomless_pit::colour::Colour;
2use bottomless_pit::engine_handle::{Engine, EngineBuilder};
3use bottomless_pit::render::RenderHandle;
4use bottomless_pit::text::TextMaterial;
5use bottomless_pit::vec2;
6use bottomless_pit::vectors::Vec2;
7use bottomless_pit::Game;
8
9fn main() {
10 let engine = EngineBuilder::new().build().unwrap();
11
12 let text_mat = TextMaterial::new("this is a test", Colour::RED, 20.0, 20.0 * 1.3);
13
14 let text_example = TextExample {
15 text_mat,
16 text: String::new(),
17 };
18
19 engine.run(text_example);
20}
21
22struct TextExample {
23 text_mat: TextMaterial,
24 text: String,
25}
26
27impl Game for TextExample {
28 fn render<'o>(&'o mut self, mut render: RenderHandle<'o>) {
29 let mut render_handle = render.begin_pass(Colour::BLACK);
30 self.text_mat
31 .add_instance(vec2! { 0.0 }, Colour::WHITE, &render_handle);
32
33 self.text_mat.draw(&mut render_handle);
34 }
35
36 fn update(&mut self, engine_handle: &mut Engine) {
37 let text = engine_handle.get_current_text();
38 if let Some(s) = text {
39 self.text.push_str(s);
40
41 self.text_mat
42 .set_text(&self.text, Colour::RED, engine_handle)
43 }
44
45 self.text_mat.prepare(engine_handle);
46 }
47}