Skip to content

Commit a1df470

Browse files
committed
Settable BG Color
1 parent 288ce31 commit a1df470

File tree

10 files changed

+45
-31
lines changed

10 files changed

+45
-31
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wgpu-bootstrap"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
edition = "2021"
55

66
[dependencies]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Add the library to your `cargo.toml`. Use the `tag` key to specify the version.
99

1010
```toml
1111
[dependencies]
12-
wgpu-bootstrap = { git = "https://github.com/qlurkin/wgpu-bootstrap", tag = "v0.4.1" }
12+
wgpu-bootstrap = { git = "https://github.com/qlurkin/wgpu-bootstrap", tag = "v0.4.2" }
1313
bytemuck = { version = "1.18", features = ["derive"] }
1414
```
1515

examples/cube/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ mod cube_app;
33
use std::sync::Arc;
44

55
use crate::cube_app::CubeApp;
6-
use wgpu_bootstrap::Runner;
6+
use wgpu_bootstrap::{egui, Runner};
77

88
fn main() {
99
let mut runner = Runner::new(
1010
"Cube App",
1111
800,
1212
600,
13+
egui::Color32::from_rgb(245, 245, 245),
1314
32,
1415
0,
1516
Box::new(|context| Arc::new(CubeApp::new(context))),

examples/gui/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ mod gui_app;
33
use std::sync::Arc;
44

55
use crate::gui_app::GuiApp;
6-
use wgpu_bootstrap::Runner;
6+
use wgpu_bootstrap::{egui, Runner};
77

88
fn main() {
99
let mut runner = Runner::new(
1010
"Gui App",
1111
800,
1212
600,
13+
egui::Color32::from_rgb(245, 245, 245),
1314
32,
1415
0,
1516
Box::new(|context| Arc::new(GuiApp::new(context))),

examples/instances/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ mod instances_app;
33
use std::sync::Arc;
44

55
use crate::instances_app::InstanceApp;
6-
use wgpu_bootstrap::Runner;
6+
use wgpu_bootstrap::{egui, Runner};
77

88
fn main() {
99
let mut runner = Runner::new(
1010
"Gui App",
1111
800,
1212
600,
13+
egui::Color32::from_rgb(245, 245, 245),
1314
32,
1415
0,
1516
Box::new(|context| Arc::new(InstanceApp::new(context))),

examples/shading/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ mod shading_app;
33
use std::sync::Arc;
44

55
use crate::shading_app::ShadingApp;
6-
use wgpu_bootstrap::Runner;
6+
use wgpu_bootstrap::{egui, Runner};
77

88
fn main() {
99
let mut runner = Runner::new(
1010
"Shading App",
1111
800,
1212
600,
13+
egui::Color32::from_rgb(245, 245, 245),
1314
32,
1415
0,
1516
Box::new(|context| Arc::new(ShadingApp::new(context))),

examples/triangle/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ mod triangle_app;
33
use std::sync::Arc;
44

55
use crate::triangle_app::TriangleApp;
6-
use wgpu_bootstrap::Runner;
6+
use wgpu_bootstrap::{egui, Runner};
77

88
fn main() {
99
let mut runner = Runner::new(
1010
"Triangle App",
1111
800,
1212
600,
13+
egui::Color32::from_rgb(245, 245, 245),
1314
0,
1415
0,
1516
Box::new(|context| Arc::new(TriangleApp::new(context))),

examples/wireframe/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ mod wireframe_app;
33
use std::sync::Arc;
44

55
use crate::wireframe_app::WireframeApp;
6-
use wgpu_bootstrap::Runner;
6+
use wgpu_bootstrap::{egui, Runner};
77

88
fn main() {
99
let mut runner = Runner::new(
1010
"Wireframe App",
1111
800,
1212
600,
13+
egui::Color32::from_rgb(245, 245, 245),
1314
32,
1415
0,
1516
Box::new(|context| Arc::new(WireframeApp::new(context))),

src/runner.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use eframe::{
2-
egui::{self, InputState},
2+
egui::{self, InputState, Visuals},
33
egui_wgpu::{self, depth_format_from_bits, CallbackResources, CallbackTrait},
44
wgpu,
55
};
@@ -52,6 +52,7 @@ pub struct Runner {
5252
app_name: String,
5353
width: u32,
5454
height: u32,
55+
bg_color: egui::Color32,
5556
depth_buffer: u8,
5657
stencil_buffer: u8,
5758
app_creator: Option<Box<dyn FnOnce(&Context) -> Arc<dyn App + Send + Sync>>>,
@@ -62,6 +63,7 @@ impl Runner {
6263
app_name: &str,
6364
width: u32,
6465
height: u32,
66+
bg_color: egui::Color32,
6567
depth_buffer: u8,
6668
stencil_buffer: u8,
6769
app_creator: Box<dyn FnOnce(&Context) -> Arc<dyn App + Send + Sync>>,
@@ -72,6 +74,7 @@ impl Runner {
7274
app_name: String::from(app_name),
7375
width,
7476
height,
77+
bg_color,
7578
app_creator: Some(app_creator),
7679
depth_buffer,
7780
stencil_buffer,
@@ -97,6 +100,7 @@ impl Runner {
97100
cc,
98101
self.width,
99102
self.height,
103+
self.bg_color,
100104
depth_stencil_format,
101105
self.app_creator.take().unwrap(),
102106
)))
@@ -108,6 +112,7 @@ impl Runner {
108112
struct EframeApp {
109113
window_width: u32,
110114
window_height: u32,
115+
bg_color: egui::Color32,
111116
depth_stencil_format: Option<wgpu::TextureFormat>,
112117
last: Option<Instant>,
113118
app: Arc<dyn App + Send + Sync>,
@@ -118,6 +123,7 @@ impl EframeApp {
118123
cc: &eframe::CreationContext<'_>,
119124
width: u32,
120125
height: u32,
126+
bg_color: egui::Color32,
121127
depth_stencil_format: Option<wgpu::TextureFormat>,
122128
app_creator: Box<dyn FnOnce(&Context) -> Arc<dyn App + Send + Sync>>,
123129
) -> Self {
@@ -134,15 +140,10 @@ impl EframeApp {
134140
depth_stencil_format,
135141
};
136142

137-
// wgpu_render_state
138-
// .renderer
139-
// .write()
140-
// .callback_resources
141-
// .insert(app_creator(&context));
142-
143143
Self {
144144
window_width: width,
145145
window_height: height,
146+
bg_color,
146147
depth_stencil_format,
147148
last: None,
148149
app: app_creator(&context),
@@ -198,23 +199,30 @@ impl eframe::App for EframeApp {
198199
.unwrap()
199200
.render_gui(ctx, &context);
200201

201-
egui::CentralPanel::default().show(ctx, |ui| {
202-
// egui::Frame::canvas(ui.style()).show(ui, |ui| {
203-
let response = ui.allocate_space(egui::vec2(
204-
ctx.screen_rect().width(),
205-
ctx.screen_rect().height(),
206-
));
207-
208-
ui.painter().add(egui_wgpu::Callback::new_paint_callback(
209-
response.1,
210-
WgpuCallback {
211-
app: self.app.clone(),
212-
},
213-
));
214-
// });
215-
});
202+
let container = egui::containers::Frame::default().fill(self.bg_color);
203+
egui::CentralPanel::default()
204+
.frame(container)
205+
.show(ctx, |ui| {
206+
// egui::Frame::canvas(ctx.style()).show(ctx, |ui| {
207+
let response = ui.allocate_space(egui::vec2(
208+
ctx.screen_rect().width(),
209+
ctx.screen_rect().height(),
210+
));
211+
212+
ui.painter().add(egui_wgpu::Callback::new_paint_callback(
213+
response.1,
214+
WgpuCallback {
215+
app: self.app.clone(),
216+
},
217+
));
218+
// });
219+
});
216220
ctx.request_repaint();
217221
}
222+
223+
fn clear_color(&self, _visuals: &Visuals) -> [f32; 4] {
224+
return [0.9, 0.4, 0.4, 1.0];
225+
}
218226
}
219227

220228
struct WgpuCallback {

0 commit comments

Comments
 (0)