-
Notifications
You must be signed in to change notification settings - Fork 15
/
imgui.rs
82 lines (74 loc) · 2.75 KB
/
imgui.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
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
mod profile_with_puffin;
use {
screen_13::prelude::*,
screen_13_fx::*,
screen_13_imgui::{Condition, ImGui},
screen_13_window::{Window, WindowError},
winit::dpi::LogicalSize,
};
fn main() -> Result<(), WindowError> {
pretty_env_logger::init();
profile_with_puffin::init();
// Screen 13 things we need for this demo
let window = Window::builder()
.v_sync(false)
.window(|window| window.with_inner_size(LogicalSize::new(1024, 768)))
.build()?;
let display = ComputePresenter::new(&window.device)?;
let mut imgui = ImGui::new(&window.device);
let mut pool = LazyPool::new(&window.device);
// Some example state to make the demo more interesting
let mut value = 0;
let choices = ["test test this is 1", "test test this is 2"];
window.run(|frame| {
// Lease and clear an image as a stand-in for some real game or program output
let app_image = frame.render_graph.bind_node(
pool.lease(ImageInfo::image_2d(
frame.width,
frame.height,
vk::Format::R8G8B8A8_UNORM,
vk::ImageUsageFlags::SAMPLED
| vk::ImageUsageFlags::STORAGE
| vk::ImageUsageFlags::TRANSFER_DST,
))
.unwrap(),
);
frame
.render_graph
.clear_color_image_value(app_image, [0.2, 0.22, 0.2, 1.0]);
// Use the draw function callback to do some fun meant-for-debug-mode GUI stuff
let gui_image = imgui.draw(
0.016,
frame.events,
frame.window,
frame.render_graph,
|ui| {
ui.window("Hello world")
.position([10.0, 10.0], Condition::FirstUseEver)
.size([340.0, 250.0], Condition::FirstUseEver)
.build(|| {
ui.text_wrapped("Hello world!");
ui.text_wrapped("こんにちは世界!");
if ui.button(choices[value]) {
value += 1;
value %= 2;
}
ui.button("This...is...imgui-rs!");
ui.separator();
let mouse_pos = ui.io().mouse_pos;
ui.text(format!(
"Mouse Position: ({:.1},{:.1})",
mouse_pos[0], mouse_pos[1]
));
});
},
);
// Present "gui_image" on top of "app_image" onto "frame.swapchain"
display.present_images(
frame.render_graph,
gui_image,
app_image,
frame.swapchain_image,
);
})
}