From 0d71017ad434dabd6bfcec98e8025a7378a70161 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 6 May 2021 20:49:22 +0200 Subject: [PATCH] clippy fixes for rust 1.52 --- egui/src/containers/scroll_area.rs | 2 +- egui/src/widgets/color_picker.rs | 2 +- egui_demo_lib/src/apps/demo/demo_windows.rs | 6 +- egui_glium/src/painter.rs | 16 +++--- egui_web/src/webgl1.rs | 60 ++++++++++---------- egui_web/src/webgl2.rs | 61 ++++++++++----------- 6 files changed, 70 insertions(+), 77 deletions(-) diff --git a/egui/src/containers/scroll_area.rs b/egui/src/containers/scroll_area.rs index e3fac236..09edce67 100644 --- a/egui/src/containers/scroll_area.rs +++ b/egui/src/containers/scroll_area.rs @@ -141,9 +141,9 @@ impl ScrollArea { Prepared { id, state, + current_scroll_bar_width, always_show_scroll, inner_rect, - current_scroll_bar_width, content_ui, } } diff --git a/egui/src/widgets/color_picker.rs b/egui/src/widgets/color_picker.rs index a99be840..38dcebea 100644 --- a/egui/src/widgets/color_picker.rs +++ b/egui/src/widgets/color_picker.rs @@ -311,7 +311,7 @@ fn color_picker_hsvag_2d(ui: &mut Ui, hsva: &mut HsvaGamma, alpha: Alpha) { ui.label("Value"); ui.end_row(); - color_slider_2d(ui, v, s, |v, s| HsvaGamma { v, s, ..opaque }.into()); + color_slider_2d(ui, v, s, |v, s| HsvaGamma { s, v, ..opaque }.into()); ui.label("Value / Saturation"); ui.end_row(); }); diff --git a/egui_demo_lib/src/apps/demo/demo_windows.rs b/egui_demo_lib/src/apps/demo/demo_windows.rs index dd20b9d3..ee5a27d9 100644 --- a/egui_demo_lib/src/apps/demo/demo_windows.rs +++ b/egui_demo_lib/src/apps/demo/demo_windows.rs @@ -42,12 +42,12 @@ impl Default for Demos { .to_owned(), ); - Self { open, demos } + Self { demos, open } } } impl Demos { pub fn checkboxes(&mut self, ui: &mut Ui) { - let Self { open, demos } = self; + let Self { demos, open } = self; for demo in demos { let mut is_open = open.contains(demo.name()); ui.checkbox(&mut is_open, demo.name()); @@ -56,7 +56,7 @@ impl Demos { } pub fn show(&mut self, ctx: &CtxRef) { - let Self { open, demos } = self; + let Self { demos, open } = self; for demo in demos { let mut is_open = open.contains(demo.name()); demo.show(ctx, &mut is_open); diff --git a/egui_glium/src/painter.rs b/egui_glium/src/painter.rs index 938a791c..210d0599 100644 --- a/egui_glium/src/painter.rs +++ b/egui_glium/src/painter.rs @@ -303,15 +303,13 @@ impl Painter { } pub fn upload_pending_user_textures(&mut self, facade: &dyn glium::backend::Facade) { - for user_texture in &mut self.user_textures { - if let Some(user_texture) = user_texture { - if user_texture.gl_texture.is_none() { - let pixels = std::mem::take(&mut user_texture.pixels); - let format = texture::SrgbFormat::U8U8U8U8; - let mipmaps = texture::MipmapsOption::NoMipmap; - user_texture.gl_texture = - Some(SrgbTexture2d::with_format(facade, pixels, format, mipmaps).unwrap()); - } + for user_texture in self.user_textures.iter_mut().flatten() { + if user_texture.gl_texture.is_none() { + let pixels = std::mem::take(&mut user_texture.pixels); + let format = texture::SrgbFormat::U8U8U8U8; + let mipmaps = texture::MipmapsOption::NoMipmap; + user_texture.gl_texture = + Some(SrgbTexture2d::with_format(facade, pixels, format, mipmaps).unwrap()); } } } diff --git a/egui_web/src/webgl1.rs b/egui_web/src/webgl1.rs index e0d37efb..a4d85e10 100644 --- a/egui_web/src/webgl1.rs +++ b/egui_web/src/webgl1.rs @@ -151,41 +151,39 @@ impl WebGlPainter { fn upload_user_textures(&mut self) { let gl = &self.gl; - for user_texture in &mut self.user_textures { - if let Some(user_texture) = user_texture { - if user_texture.gl_texture.is_none() { - let pixels = std::mem::take(&mut user_texture.pixels); + for user_texture in self.user_textures.iter_mut().flatten() { + if user_texture.gl_texture.is_none() { + let pixels = std::mem::take(&mut user_texture.pixels); - let gl_texture = gl.create_texture().unwrap(); - gl.bind_texture(Gl::TEXTURE_2D, Some(&gl_texture)); - gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_S, Gl::CLAMP_TO_EDGE as i32); - gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_T, Gl::CLAMP_TO_EDGE as i32); - gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MIN_FILTER, Gl::LINEAR as i32); - gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, Gl::LINEAR as i32); + let gl_texture = gl.create_texture().unwrap(); + gl.bind_texture(Gl::TEXTURE_2D, Some(&gl_texture)); + gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_S, Gl::CLAMP_TO_EDGE as i32); + gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_T, Gl::CLAMP_TO_EDGE as i32); + gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MIN_FILTER, Gl::LINEAR as i32); + gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, Gl::LINEAR as i32); - gl.bind_texture(Gl::TEXTURE_2D, Some(&gl_texture)); + gl.bind_texture(Gl::TEXTURE_2D, Some(&gl_texture)); - // TODO: https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB - let level = 0; - let internal_format = Gl::RGBA; - let border = 0; - let src_format = Gl::RGBA; - let src_type = Gl::UNSIGNED_BYTE; - gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array( - Gl::TEXTURE_2D, - level, - internal_format as i32, - user_texture.size.0 as i32, - user_texture.size.1 as i32, - border, - src_format, - src_type, - Some(&pixels), - ) - .unwrap(); + // TODO: https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB + let level = 0; + let internal_format = Gl::RGBA; + let border = 0; + let src_format = Gl::RGBA; + let src_type = Gl::UNSIGNED_BYTE; + gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array( + Gl::TEXTURE_2D, + level, + internal_format as i32, + user_texture.size.0 as i32, + user_texture.size.1 as i32, + border, + src_format, + src_type, + Some(&pixels), + ) + .unwrap(); - user_texture.gl_texture = Some(gl_texture); - } + user_texture.gl_texture = Some(gl_texture); } } } diff --git a/egui_web/src/webgl2.rs b/egui_web/src/webgl2.rs index 0e0a5472..26743a3d 100644 --- a/egui_web/src/webgl2.rs +++ b/egui_web/src/webgl2.rs @@ -153,42 +153,39 @@ impl WebGl2Painter { fn upload_user_textures(&mut self) { let gl = &self.gl; + for user_texture in self.user_textures.iter_mut().flatten() { + if user_texture.gl_texture.is_none() { + let pixels = std::mem::take(&mut user_texture.pixels); - for user_texture in &mut self.user_textures { - if let Some(user_texture) = user_texture { - if user_texture.gl_texture.is_none() { - let pixels = std::mem::take(&mut user_texture.pixels); + let gl_texture = gl.create_texture().unwrap(); + gl.bind_texture(Gl::TEXTURE_2D, Some(&gl_texture)); + gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_S, Gl::CLAMP_TO_EDGE as i32); + gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_T, Gl::CLAMP_TO_EDGE as i32); + gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MIN_FILTER, Gl::LINEAR as i32); + gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, Gl::LINEAR as i32); - let gl_texture = gl.create_texture().unwrap(); - gl.bind_texture(Gl::TEXTURE_2D, Some(&gl_texture)); - gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_S, Gl::CLAMP_TO_EDGE as i32); - gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_WRAP_T, Gl::CLAMP_TO_EDGE as i32); - gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MIN_FILTER, Gl::LINEAR as i32); - gl.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, Gl::LINEAR as i32); + gl.bind_texture(Gl::TEXTURE_2D, Some(&gl_texture)); - gl.bind_texture(Gl::TEXTURE_2D, Some(&gl_texture)); + let level = 0; + let internal_format = Gl::SRGB8_ALPHA8; + let border = 0; + let src_format = Gl::RGBA; + let src_type = Gl::UNSIGNED_BYTE; + gl.pixel_storei(Gl::UNPACK_ALIGNMENT, 1); + gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array( + Gl::TEXTURE_2D, + level, + internal_format as i32, + user_texture.size.0 as i32, + user_texture.size.1 as i32, + border, + src_format, + src_type, + Some(&pixels), + ) + .unwrap(); - let level = 0; - let internal_format = Gl::SRGB8_ALPHA8; - let border = 0; - let src_format = Gl::RGBA; - let src_type = Gl::UNSIGNED_BYTE; - gl.pixel_storei(Gl::UNPACK_ALIGNMENT, 1); - gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array( - Gl::TEXTURE_2D, - level, - internal_format as i32, - user_texture.size.0 as i32, - user_texture.size.1 as i32, - border, - src_format, - src_type, - Some(&pixels), - ) - .unwrap(); - - user_texture.gl_texture = Some(gl_texture); - } + user_texture.gl_texture = Some(gl_texture); } } }