App::clear_color: give egui::Visuals as argument

This commit is contained in:
Emil Ernerfeldt 2022-04-30 15:41:43 +02:00
parent 8303523ccf
commit e1bcaeebe5
5 changed files with 13 additions and 6 deletions

View file

@ -93,11 +93,13 @@ pub trait App {
/// Background color for the app, e.g. what is sent to `gl.clearColor`. /// Background color for the app, e.g. what is sent to `gl.clearColor`.
/// This is the background of your windows if you don't set a central panel. /// This is the background of your windows if you don't set a central panel.
fn clear_color(&self) -> egui::Rgba { fn clear_color(&self, _visuals: &egui::Visuals) -> egui::Rgba {
// NOTE: a bright gray makes the shadows of the windows look weird. // NOTE: a bright gray makes the shadows of the windows look weird.
// We use a bit of transparency so that if the user switches on the // We use a bit of transparency so that if the user switches on the
// `transparent()` option they get immediate results. // `transparent()` option they get immediate results.
egui::Color32::from_rgba_unmultiplied(12, 12, 12, 180).into() egui::Color32::from_rgba_unmultiplied(12, 12, 12, 180).into()
// _visuals.window_fill() would also be a natural choice
} }
/// Controls whether or not the native window position and size will be /// Controls whether or not the native window position and size will be

View file

@ -95,7 +95,11 @@ pub fn run(app_name: &str, native_options: &epi::NativeOptions, app_creator: epi
crate::profile_scope!("frame"); crate::profile_scope!("frame");
let screen_size_in_pixels: [u32; 2] = gl_window.window().inner_size().into(); let screen_size_in_pixels: [u32; 2] = gl_window.window().inner_size().into();
egui_glow::painter::clear(&gl, screen_size_in_pixels, app.clear_color()); egui_glow::painter::clear(
&gl,
screen_size_in_pixels,
app.clear_color(&integration.egui_ctx.style().visuals),
);
let egui::FullOutput { let egui::FullOutput {
platform_output, platform_output,

View file

@ -278,7 +278,8 @@ impl AppRunner {
} }
pub fn clear_color_buffer(&self) { pub fn clear_color_buffer(&self) {
self.painter.clear(self.app.clear_color()); self.painter
.clear(self.app.clear_color(&self.egui_ctx.style().visuals));
} }
/// Paint the results of the last call to [`Self::logic`]. /// Paint the results of the last call to [`Self::logic`].

View file

@ -156,8 +156,8 @@ impl eframe::App for WrapApp {
eframe::set_value(storage, eframe::APP_KEY, &self.state); eframe::set_value(storage, eframe::APP_KEY, &self.state);
} }
fn clear_color(&self) -> egui::Rgba { fn clear_color(&self, visuals: &egui::Visuals) -> egui::Rgba {
egui::Rgba::TRANSPARENT // we set a [`CentralPanel`] fill color in `demo_windows.rs` visuals.window_fill().into()
} }
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {

View file

@ -24,7 +24,7 @@ fn main() {
struct MyApp {} struct MyApp {}
impl eframe::App for MyApp { impl eframe::App for MyApp {
fn clear_color(&self) -> egui::Rgba { fn clear_color(&self, _visuals: &egui::Visuals) -> egui::Rgba {
egui::Rgba::TRANSPARENT // Make sure we don't paint anything behind the rounded corners egui::Rgba::TRANSPARENT // Make sure we don't paint anything behind the rounded corners
} }