Added App::clear_color() that apps can use to specify background color
This commit is contained in:
parent
9ea8d907fd
commit
c3c4f28a9d
6 changed files with 33 additions and 11 deletions
|
@ -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<Vec2>` 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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -111,7 +111,13 @@ pub fn run(mut storage: Box<dyn egui::app::Storage>, mut app: Box<dyn App>) -> !
|
|||
|
||||
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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue