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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
#![windows_subsystem = "windows"] // to turn off console.
use celeritas::{Frame_Begin, Frame_End};
use egui::DragValue;
use egui_overlay::EguiOverlay;
use egui_render_three_d::ThreeDBackend;
use egui_render_wgpu::WgpuBackend;
fn main() {
// use tracing_subscriber::{fmt, prelude::*, EnvFilter};
// if RUST_LOG is not set, we will use the following filters
// tracing_subscriber::registry()
// .with(fmt::layer())
// .with(
// EnvFilter::try_from_default_env()
// .unwrap_or(EnvFilter::new("debug,wgpu=warn,naga=warn")),
// )
// .init();
celeritas::egui_utils::start(HelloWorld { frame: 0});
}
pub struct HelloWorld {
pub frame: u64,
}
impl EguiOverlay for HelloWorld {
fn gui_run(
&mut self,
egui_context: &egui::Context,
_default_gfx_backend: &mut ThreeDBackend,
glfw_backend: &mut egui_window_glfw_passthrough::GlfwBackend,
) {
// unsafe {
// Frame_Begin();
// Frame_End();
// }
// just some controls to show how you can use glfw_backend
egui::Window::new("controls").show(egui_context, |ui| {
ui.set_width(300.0);
self.frame += 1;
ui.label(format!("current frame number: {}", self.frame));
// sometimes, you want to see the borders to understand where the overlay is.
let mut borders = glfw_backend.window.is_decorated();
if ui.checkbox(&mut borders, "window borders").changed() {
glfw_backend.window.set_decorated(borders);
}
ui.label(format!(
"pixels_per_virtual_unit: {}",
glfw_backend.physical_pixels_per_virtual_unit
));
ui.label(format!("window scale: {}", glfw_backend.scale));
ui.label(format!("cursor pos x: {}", glfw_backend.cursor_pos[0]));
ui.label(format!("cursor pos y: {}", glfw_backend.cursor_pos[1]));
ui.label(format!(
"passthrough: {}",
glfw_backend.window.is_mouse_passthrough()
));
// how to change size.
// WARNING: don't use drag value, because window size changing while dragging ui messes things up.
let mut size = glfw_backend.window_size_logical;
let mut changed = false;
ui.horizontal(|ui| {
ui.label("width: ");
ui.add_enabled(false, DragValue::new(&mut size[0]));
if ui.button("inc").clicked() {
size[0] += 10.0;
changed = true;
}
if ui.button("dec").clicked() {
size[0] -= 10.0;
changed = true;
}
});
ui.horizontal(|ui| {
ui.label("height: ");
ui.add_enabled(false, DragValue::new(&mut size[1]));
if ui.button("inc").clicked() {
size[1] += 10.0;
changed = true;
}
if ui.button("dec").clicked() {
size[1] -= 10.0;
changed = true;
}
});
if changed {
glfw_backend.set_window_size(size);
}
// how to change size.
// WARNING: don't use drag value, because window size changing while dragging ui messes things up.
let mut pos = glfw_backend.window_position;
let mut changed = false;
ui.horizontal(|ui| {
ui.label("x: ");
ui.add_enabled(false, DragValue::new(&mut pos[0]));
if ui.button("inc").clicked() {
pos[0] += 10;
changed = true;
}
if ui.button("dec").clicked() {
pos[0] -= 10;
changed = true;
}
});
ui.horizontal(|ui| {
ui.label("y: ");
ui.add_enabled(false, DragValue::new(&mut pos[1]));
if ui.button("inc").clicked() {
pos[1] += 10;
changed = true;
}
if ui.button("dec").clicked() {
pos[1] -= 10;
changed = true;
}
});
if changed {
glfw_backend.window.set_pos(pos[0], pos[1]);
}
});
// here you decide if you want to be passthrough or not.
if egui_context.wants_pointer_input() || egui_context.wants_keyboard_input() {
// we need input, so we need the window to be NOT passthrough
glfw_backend.set_passthrough(false);
} else {
// we don't care about input, so the window can be passthrough now
glfw_backend.set_passthrough(true)
}
egui_context.request_repaint();
}
}
|