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
|
/*
wearechat - generic multiplayer game with voip
Copyright (C) 2025 metamuffin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use egui::{Context, epaint::Primitive};
use wgpu::{Buffer, BufferDescriptor, BufferUsages, Device, Queue};
pub struct UiRenderer {
ctx: Context,
}
impl UiRenderer {
pub fn new(device: &Device) -> Self {
let index = device.create_buffer(&BufferDescriptor {
label: None,
size: 1,
usage: BufferUsages::INDEX | BufferUsages::COPY_DST,
mapped_at_creation: false,
});
let vertex = device.create_buffer(&BufferDescriptor {
label: None,
size: 1,
usage: BufferUsages::VERTEX | BufferUsages::COPY_DST,
mapped_at_creation: false,
});
Self {
ctx: Context::default(),
index,
vertex,
}
}
pub fn draw(&self, queue: &Queue) {
let raw_input = egui::RawInput::default();
let full_output = self.ctx.run(raw_input, |ctx| {
egui::CentralPanel::default().show(&ctx, |ui| {
ui.label("Hello world!");
if ui.button("Click me").clicked() {
// take some action here
}
});
});
// handle_platform_output(full_output.platform_output);
let clipped_primitives = self
.ctx
.tessellate(full_output.shapes, full_output.pixels_per_point);
for p in clipped_primitives {
match p.primitive {
Primitive::Mesh(mesh) => {}
_ => unreachable!(),
}
}
// paint(full_output.textures_delta, clipped_primitives);
}
}
|