diff --git a/src/about.rs b/src/about.rs index ceb7e90..c31ccc2 100644 --- a/src/about.rs +++ b/src/about.rs @@ -38,7 +38,7 @@ impl WindowExt for AboutWindow { let mut context = EguiWinitWgpuContext::new(&window, event_loop)?; - let mut egui_ctx = context.context_mut(); + let egui_ctx = context.context_mut(); let is_dark = theme == Theme::Dark; if egui_ctx.style().visuals.dark_mode != is_dark { @@ -49,7 +49,7 @@ impl WindowExt for AboutWindow { }); } - setup_fonts(&mut egui_ctx); + setup_fonts(egui_ctx); Ok(Self { context, window }) } diff --git a/src/app.rs b/src/app.rs index 1d1ff09..d7b00e7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -66,10 +66,8 @@ impl App { Event::RedrawRequested(window_id) => { if window_id == self.window.id() { self.core.redraw(&self.window); - } else { - if let Some(window) = self.sub_window_map.get_mut(&window_id) { - window.render(); - } + } else if let Some(window) = self.sub_window_map.get_mut(&window_id) { + window.render(); } } Event::WindowEvent { @@ -78,11 +76,9 @@ impl App { } => { if window_id == self.window.id() { self.core.handle_window_event(event); - } else { - if let Some(window) = self.sub_window_map.get_mut(&window_id) { - if window.handle_window_event(event) { - window.request_redraw(); - } + } else if let Some(window) = self.sub_window_map.get_mut(&window_id) { + if window.handle_window_event(event) { + window.request_redraw(); } } @@ -103,13 +99,11 @@ impl App { } } WindowEvent::MouseInput { button, state, .. } => { - if window_id == self.window.id() { - match button { - MouseButton::Left => self - .core - .handle_mouse_input(*state == ElementState::Pressed), - _ => {} - } + let right_window = window_id == self.window.id(); + let left_pressed = matches!(button, MouseButton::Left); + if right_window && left_pressed { + self.core + .handle_mouse_input(*state == ElementState::Pressed); } } WindowEvent::Resized(physical_size) => { @@ -119,10 +113,8 @@ impl App { physical_size.height as f32, self.window.scale_factor() as f32, ); - } else { - if let Some(window) = self.sub_window_map.get_mut(&window_id) { - window.on_resized(physical_size.width, physical_size.height); - } + } else if let Some(window) = self.sub_window_map.get_mut(&window_id) { + window.on_resized(physical_size.width, physical_size.height); } } WindowEvent::ScaleFactorChanged { @@ -137,10 +129,8 @@ impl App { new_inner_size.height as f32, *scale_factor as f32, ); - } else { - if let Some(window) = self.sub_window_map.get_mut(&window_id) { - window.on_scaled(*scale_factor as f32); - } + } else if let Some(window) = self.sub_window_map.get_mut(&window_id) { + window.on_scaled(*scale_factor as f32); } } _ => {} diff --git a/src/core.rs b/src/core.rs index 12defdc..8a5e8a7 100644 --- a/src/core.rs +++ b/src/core.rs @@ -133,7 +133,7 @@ impl Core { .wgs() .name() .to_ascii_lowercase() - .replace(" ", "_"), + .replace(' ', "_"), "png" ); self.runtime.request_capture_image( @@ -184,7 +184,7 @@ impl Core { UserEvent::OpenExample(example) => { let bytes = example.data(); - match load_wgs_from_buffer(&bytes) { + match load_wgs_from_buffer(bytes) { Ok(wgs) => { self.wgs_path = None; @@ -446,7 +446,7 @@ impl Core { self.runtime.render_with(|device, queue, view| { for (id, delta) in &full_output.textures_delta.set { - self.ui_renderer.update_texture(device, queue, *id, &delta); + self.ui_renderer.update_texture(device, queue, *id, delta); } let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { @@ -524,7 +524,7 @@ impl Core { // Save as. if let Some(path) = create_file(&format!( "{}.{}", - wgs.name().to_ascii_lowercase().replace(" ", "_"), + wgs.name().to_ascii_lowercase().replace(' ', "_"), wgs_core::EXTENSION )) { self.wgs_path = Some(path); @@ -540,13 +540,13 @@ impl Core { .wgs() .name() .to_ascii_lowercase() - .replace(" ", "_"), + .replace(' ', "_"), wgs_core::EXTENSION )); } if self.wgs_path.is_some() { - save_wgs(&self.wgs_path.as_ref().unwrap(), &wgs); + save_wgs(self.wgs_path.as_ref().unwrap(), wgs); self.change_status(AppStatus::Info(fl!("status_save_ok"))); diff --git a/src/egui_winit_wgpu_context.rs b/src/egui_winit_wgpu_context.rs index 2850434..7afeeab 100644 --- a/src/egui_winit_wgpu_context.rs +++ b/src/egui_winit_wgpu_context.rs @@ -14,7 +14,7 @@ impl EguiWinitWgpuContext { pub fn new(window: &Window, event_loop: &EventLoopWindowTarget) -> Result { let mut painter = Painter::new(WgpuConfiguration::default(), 1, None, true); - futures::executor::block_on(painter.set_window(Some(&window)))?; + futures::executor::block_on(painter.set_window(Some(window)))?; let mut state = State::new(&event_loop); state.set_pixels_per_point(window.scale_factor() as f32); diff --git a/src/event.rs b/src/event.rs index 97cc8f6..3bc6f12 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,7 +1,9 @@ use crate::example::Example; +use std::fmt::Debug; use winit::event_loop::EventLoopProxy; #[derive(Clone, Debug)] +#[allow(dead_code)] pub enum AppStatus { Idle, Info(String), @@ -44,9 +46,16 @@ pub struct EventProxyWinit { inner: EventLoopProxy, } -impl EventProxy for EventProxyWinit { +impl EventProxy for EventProxyWinit +where + T: Debug, +{ fn send_event(&self, event: T) { - self.inner.send_event(event); + // Not sure if unwrap is the best idea here, but I don't know enough + // about the app to say other wise + // + // Feel free to replace + self.inner.send_event(event).unwrap(); } } diff --git a/src/ui/highlight/code_theme.rs b/src/ui/highlight/code_theme.rs index d8f55c2..d769b3c 100644 --- a/src/ui/highlight/code_theme.rs +++ b/src/ui/highlight/code_theme.rs @@ -13,6 +13,11 @@ impl Default for CodeTheme { } } +// WHY DO I NEED TO DO THIS??? They're public functions +// +// Anyways I do, if you make changes to this implementation make sure to remove this before you +// compile to check for any warnings +#[allow(dead_code)] impl CodeTheme { pub fn from_style(style: &Style) -> Self { if style.visuals.dark_mode { diff --git a/src/ui/highlight.rs b/src/ui/highlight/mod.rs similarity index 97% rename from src/ui/highlight.rs rename to src/ui/highlight/mod.rs index e4b0668..5920ffc 100644 --- a/src/ui/highlight.rs +++ b/src/ui/highlight/mod.rs @@ -22,7 +22,7 @@ impl Highlighter { while !text.is_empty() { if text.starts_with("//") { - let end = text.find("\n").unwrap_or(text.len()); + let end = text.find('\n').unwrap_or(text.len()); job.append(&text[..end], 0.0, theme.format(TokenType::Comment)); text = &text[end..]; } else if text.starts_with("/*") { @@ -49,7 +49,7 @@ impl Highlighter { .map_or_else(|| text.len(), |i| i + 1); job.append(&text[..end], 0.0, theme.format(TokenType::Whitespace)); text = &text[end..]; - } else if text.starts_with("@") { + } else if text.starts_with('@') { job.append("@", 0.0, theme.format(TokenType::Literal)); text = &text[1..]; let end = text[1..] @@ -58,7 +58,7 @@ impl Highlighter { let word = &text[..end]; job.append(word, 0.0, theme.format(TokenType::KeywordType)); text = &text[end..]; - } else if text.starts_with("<") { + } else if text.starts_with('<') { job.append("<", 0.0, theme.format(TokenType::Literal)); text = &text[1..]; is_inside_angle_bracket = true; diff --git a/src/ui/image_upload.rs b/src/ui/image_upload.rs index dcc620c..e93431f 100644 --- a/src/ui/image_upload.rs +++ b/src/ui/image_upload.rs @@ -44,91 +44,92 @@ impl<'a> Widget for ImageUpload<'a> { Stroke::new(self.rounding.min(self.size * 0.5), ui.visuals().window_fill), ); - if self.editable || self.removable { - if ui.rect_contains_pointer(rect) { - ui.put(rect, |ui: &mut Ui| { - ui.painter().rect_filled( - rect, - self.rounding, - Color32::from_rgba_premultiplied(20, 20, 20, 180), + let editable = self.editable; + let removable = self.removable; + let contains_pointer = ui.rect_contains_pointer(rect); + + if (editable || removable) && contains_pointer { + ui.put(rect, |ui: &mut Ui| { + ui.painter().rect_filled( + rect, + self.rounding, + Color32::from_rgba_premultiplied(20, 20, 20, 180), + ); + + let mut content_size = Vec2::default(); + let button_padding = ui.spacing().button_padding; + + if self.editable { + let (_text, size) = layout_text_widget( + ui, + icon_to_char(Icon::Edit).to_string(), + button_padding, ); - let mut content_size = Vec2::default(); - let button_padding = ui.spacing().button_padding; - - if self.editable { - let (_text, size) = layout_text_widget( - ui, - icon_to_char(Icon::Edit).to_string(), - button_padding, - ); - - content_size += size; - } - - if self.removable { - let (_text, size) = layout_text_widget( - ui, - icon_to_char(Icon::Delete).to_string(), - button_padding, - ); - - content_size += size; - } - - let button_count = if self.editable && self.removable { - 2.0 - } else { - 1.0 - }; - - let item_spacing = ui.spacing().item_spacing; - let content_size = vec2( - content_size[0] + (button_count - 1.0) * item_spacing.x, - content_size[1], - ); - - let content_rect = Rect::from_center_size(rect.center(), content_size); + content_size += size; + } - ui.allocate_ui_at_rect(content_rect, |ui| { - ui.horizontal_centered(|ui| { - if self.editable { - let resp = ui.button(icon_to_char(Icon::Edit).to_string()); - - let resp = if !self.edit_hint.is_empty() { - resp.on_hover_text(self.edit_hint) - } else { - resp - }; + if self.removable { + let (_text, size) = layout_text_widget( + ui, + icon_to_char(Icon::Delete).to_string(), + button_padding, + ); - if resp.clicked() { - if let Some(on_edit) = self.on_edit { - on_edit(); - } + content_size += size; + } + + let button_count = if self.editable && self.removable { + 2.0 + } else { + 1.0 + }; + + let item_spacing = ui.spacing().item_spacing; + let content_size = vec2( + content_size[0] + (button_count - 1.0) * item_spacing.x, + content_size[1], + ); + + let content_rect = Rect::from_center_size(rect.center(), content_size); + + ui.allocate_ui_at_rect(content_rect, |ui| { + ui.horizontal_centered(|ui| { + if self.editable { + let resp = ui.button(icon_to_char(Icon::Edit).to_string()); + + let resp = if !self.edit_hint.is_empty() { + resp.on_hover_text(self.edit_hint) + } else { + resp + }; + + if resp.clicked() { + if let Some(on_edit) = self.on_edit { + on_edit(); } } + } - if self.removable { - let resp = - ui.button(icon_to_char(Icon::Delete).to_string()); + if self.removable { + let resp = ui.button(icon_to_char(Icon::Delete).to_string()); - let resp = if !self.remove_hint.is_empty() { - resp.on_hover_text(self.remove_hint) - } else { - resp - }; + let resp = if !self.remove_hint.is_empty() { + resp.on_hover_text(self.remove_hint) + } else { + resp + }; - if resp.clicked() { - if let Some(on_remove) = self.on_remove { - on_remove(); - } + if resp.clicked() { + if let Some(on_remove) = self.on_remove { + on_remove(); } } - }); - }) - .response - }); - } + } + }); + }) + .response + }); } } None => { @@ -156,6 +157,11 @@ impl<'a> Widget for ImageUpload<'a> { } } +// WHY DO I NEED TO DO THIS??? They're public functions +// +// Anyways I do, if you make changes to this implementation make sure to remove this before you +// compile to check for any warnings +#[allow(dead_code)] impl<'a> ImageUpload<'a> { pub fn new(texture_id: Option) -> Self { Self { diff --git a/src/ui.rs b/src/ui/mod.rs similarity index 95% rename from src/ui.rs rename to src/ui/mod.rs index 03d9a26..63b7e99 100644 --- a/src/ui.rs +++ b/src/ui/mod.rs @@ -51,7 +51,7 @@ impl Ui { "debug", Arc::new(ColorImage::from_rgba_unmultiplied( [width as usize, height as usize], - &data, + data, )), TextureOptions::LINEAR, )); @@ -62,7 +62,7 @@ impl Ui { "debug", Arc::new(ColorImage::from_rgba_unmultiplied( [width as usize, height as usize], - &data, + data, )), TextureOptions::LINEAR, ); @@ -86,7 +86,7 @@ impl Ui { } pub fn remove_texture(&mut self, index: usize) { - self.textures.remove(index); + let _ = self.textures.remove(index); } pub fn reset_textures(&mut self) { @@ -239,7 +239,11 @@ impl Ui { ui.set_width(250.0); if ui.button(fl!("menu_language_system")).clicked() { - select_system_locales(); + // Not sure if unwrap is the best idea here, but I don't know enough + // about the app to say other wise + // + // Feel free to replace + select_system_locales().unwrap(); ui.close_menu(); } @@ -251,7 +255,11 @@ impl Ui { .button(format!("{} [{}]", language.label, language.id)) .clicked() { - select_locales(&[language.id]); + // Not sure if unwrap is the best idea here, but I don't know enough + // about the app to say other wise + // + // Feel free to replace + select_locales(&[language.id]).unwrap(); ui.close_menu(); } @@ -349,13 +357,7 @@ impl Ui { .clicked() { event_proxy.send_event(UserEvent::RequestRedraw); - } - if state.can_capture { - if ui - .button(icon_to_char(Icon::ScreenshotMonitor).to_string()) - .on_hover_text(fl!("control_capture")) - .clicked() - { + if state.can_capture { event_proxy.send_event(UserEvent::CaptureImage); } }