-
Notifications
You must be signed in to change notification settings - Fork 6
/
text_input.rs
57 lines (53 loc) · 1.42 KB
/
text_input.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use geng::prelude::*;
struct State {
geng: Geng,
text: String,
}
impl State {
fn new(geng: &Geng) -> Self {
Self {
geng: geng.clone(),
text: "Click to start editing".to_owned(),
}
}
}
impl geng::State for State {
fn draw(&mut self, framebuffer: &mut ugli::Framebuffer) {
ugli::clear(framebuffer, Some(Rgba::BLACK), None, None);
self.geng.default_font().draw(
framebuffer,
&geng::Camera2d {
center: vec2(0.0, 0.0),
rotation: Angle::ZERO,
fov: Camera2dFov::Vertical(15.0),
},
&self.text,
vec2::splat(geng::TextAlign::CENTER),
mat3::identity(),
Rgba::WHITE,
);
}
fn handle_event(&mut self, event: geng::Event) {
match event {
geng::Event::TouchStart(_) | geng::Event::MousePress { .. } => {
self.geng.window().start_text_edit(&self.text);
}
geng::Event::EditText(text) => {
self.text = text;
}
geng::Event::KeyPress {
key: geng::Key::Backspace,
} => {
self.text.pop();
}
_ => {}
}
}
}
fn main() {
logger::init();
geng::setup_panic_handler();
Geng::run("Moving", |geng| async move {
geng.run_state(State::new(&geng)).await
});
}