diff --git a/CHANGELOG.md b/CHANGELOG.md index 88d3d4b8..93d0b9bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * `ui.image` now takes `impl Into` as a `size` argument. * Made some more fields of `RawInput` optional. * `Slider` and `DragValue` uses fewer decimals by default. See the full precision by hovering over the value. -* `egui::App`: added `fn name(&self)` +* `egui::App`: added `fn name(&self)` and `fn clear_color(&self)` ### Deprecated * Deprecated `RawInput::screen_size` - use `RawInput::screen_rect` instead. diff --git a/egui/src/app.rs b/egui/src/app.rs index c2fc61da..6ec595e5 100644 --- a/egui/src/app.rs +++ b/egui/src/app.rs @@ -14,6 +14,11 @@ use crate::Context; pub trait App { /// The name of your App. fn name(&self) -> &str; + + /// Background color for the app. + /// e.g. what is sent to `gl.clearColor` + fn clear_color(&self) -> crate::Rgba { + crate::Srgba::from_rgb(16, 16, 16).into() } /// Called once before the first frame. diff --git a/egui_glium/src/backend.rs b/egui_glium/src/backend.rs index 523c139c..35d00126 100644 --- a/egui_glium/src/backend.rs +++ b/egui_glium/src/backend.rs @@ -111,7 +111,13 @@ pub fn run(mut storage: Box, mut app: Box) -> ! let frame_time = (Instant::now() - egui_start).as_secs_f64() as f32; previous_frame_time = Some(frame_time); - painter.paint_jobs(&display, ctx.pixels_per_point(), paint_jobs, &ctx.texture()); + painter.paint_jobs( + &display, + ctx.pixels_per_point(), + app.clear_color(), + paint_jobs, + &ctx.texture(), + ); { let egui::app::AppOutput { diff --git a/egui_glium/src/painter.rs b/egui_glium/src/painter.rs index 81f9d4f6..68cf5505 100644 --- a/egui_glium/src/painter.rs +++ b/egui_glium/src/painter.rs @@ -126,6 +126,7 @@ impl Painter { &mut self, display: &glium::Display, pixels_per_point: f32, + clear_color: egui::Rgba, jobs: PaintJobs, egui_texture: &egui::Texture, ) { @@ -133,7 +134,13 @@ impl Painter { self.upload_pending_user_textures(display); let mut target = display.draw(); - target.clear_color(0.0, 0.0, 0.0, 0.0); + // Verified to be gamma-correct. + target.clear_color( + clear_color[0], + clear_color[1], + clear_color[2], + clear_color[3], + ); for (clip_rect, triangles) in jobs { self.paint_job( &mut target, diff --git a/egui_web/src/backend.rs b/egui_web/src/backend.rs index 51efc33e..e473bad9 100644 --- a/egui_web/src/backend.rs +++ b/egui_web/src/backend.rs @@ -55,10 +55,13 @@ impl WebBackend { Ok((output, paint_jobs)) } - pub fn paint(&mut self, paint_jobs: egui::PaintJobs) -> Result<(), JsValue> { - let bg_color = egui::color::TRANSPARENT; // Use background css color. + pub fn paint( + &mut self, + clear_color: egui::Rgba, + paint_jobs: egui::PaintJobs, + ) -> Result<(), JsValue> { self.painter.paint_jobs( - bg_color, + clear_color, paint_jobs, &self.ctx.texture(), self.ctx.pixels_per_point(), @@ -214,7 +217,7 @@ impl AppRunner { } pub fn paint(&mut self, paint_jobs: egui::PaintJobs) -> Result<(), JsValue> { - self.web_backend.paint(paint_jobs) + self.web_backend.paint(self.app.clear_color(), paint_jobs) } } diff --git a/egui_web/src/webgl.rs b/egui_web/src/webgl.rs index 10105cb7..162c3f7e 100644 --- a/egui_web/src/webgl.rs +++ b/egui_web/src/webgl.rs @@ -328,11 +328,12 @@ impl Painter { self.canvas.width() as i32, self.canvas.height() as i32, ); + let clear_color: Srgba = clear_color.into(); gl.clear_color( - clear_color[0], - clear_color[1], - clear_color[2], - clear_color[3], + clear_color[0] as f32 / 255.0, + clear_color[1] as f32 / 255.0, + clear_color[2] as f32 / 255.0, + clear_color[3] as f32 / 255.0, ); gl.clear(Gl::COLOR_BUFFER_BIT);