Minor clippy fixes (clippy::format_push_string)

This commit is contained in:
Emil Ernerfeldt 2022-07-03 11:58:53 +02:00
parent eeae485629
commit 406703568e
4 changed files with 26 additions and 15 deletions

View file

@ -303,15 +303,16 @@ impl WrapApp {
fn ui_file_drag_and_drop(&mut self, ctx: &egui::Context) {
use egui::*;
use std::fmt::Write as _;
// Preview hovering files:
if !ctx.input().raw.hovered_files.is_empty() {
let mut text = "Dropping files:\n".to_owned();
for file in &ctx.input().raw.hovered_files {
if let Some(path) = &file.path {
text += &format!("\n{}", path.display());
write!(text, "\n{}", path.display()).ok();
} else if !file.mime.is_empty() {
text += &format!("\n{}", file.mime);
write!(text, "\n{}", file.mime).ok();
} else {
text += "\n???";
}
@ -351,7 +352,7 @@ impl WrapApp {
"???".to_owned()
};
if let Some(bytes) = &file.bytes {
info += &format!(" ({} bytes)", bytes.len());
write!(info, " ({} bytes)", bytes.len()).ok();
}
ui.label(info);
}

View file

@ -344,21 +344,25 @@ impl super::View for InputTest {
egui::PointerButton::Extra1,
egui::PointerButton::Extra2,
] {
use std::fmt::Write as _;
if response.clicked_by(button) {
new_info += &format!("Clicked by {:?} button\n", button);
writeln!(new_info, "Clicked by {:?} button", button).ok();
}
if response.double_clicked_by(button) {
new_info += &format!("Double-clicked by {:?} button\n", button);
writeln!(new_info, "Double-clicked by {:?} button", button).ok();
}
if response.triple_clicked_by(button) {
new_info += &format!("Triple-clicked by {:?} button\n", button);
writeln!(new_info, "Triple-clicked by {:?} button", button).ok();
}
if response.dragged_by(button) {
new_info += &format!(
"Dragged by {:?} button, delta: {:?}\n",
writeln!(
new_info,
"Dragged by {:?} button, delta: {:?}",
button,
response.drag_delta()
);
)
.ok();
}
}
if !new_info.is_empty() {

View file

@ -200,22 +200,26 @@ impl TexturesDelta {
impl std::fmt::Debug for TexturesDelta {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use std::fmt::Write as _;
let mut debug_struct = f.debug_struct("TexturesDelta");
if !self.set.is_empty() {
let mut string = String::new();
for (tex_id, delta) in &self.set {
let size = delta.image.size();
if let Some(pos) = delta.pos {
string += &format!(
write!(
string,
"{:?} partial ([{} {}] - [{} {}]), ",
tex_id,
pos[0],
pos[1],
pos[0] + size[0],
pos[1] + size[1]
);
)
.ok();
} else {
string += &format!("{:?} full {}x{}, ", tex_id, size[0], size[1]);
write!(string, "{:?} full {}x{}, ", tex_id, size[0], size[1]).ok();
}
}
debug_struct.field("set", &string);

View file

@ -52,7 +52,8 @@ impl eframe::App for MyApp {
"???".to_owned()
};
if let Some(bytes) = &file.bytes {
info += &format!(" ({} bytes)", bytes.len());
use std::fmt::Write as _;
write!(info, " ({} bytes)", bytes.len()).ok();
}
ui.label(info);
}
@ -72,14 +73,15 @@ impl eframe::App for MyApp {
/// Preview hovering files:
fn preview_files_being_dropped(ctx: &egui::Context) {
use egui::*;
use std::fmt::Write as _;
if !ctx.input().raw.hovered_files.is_empty() {
let mut text = "Dropping files:\n".to_owned();
for file in &ctx.input().raw.hovered_files {
if let Some(path) = &file.path {
text += &format!("\n{}", path.display());
write!(text, "\n{}", path.display()).ok();
} else if !file.mime.is_empty() {
text += &format!("\n{}", file.mime);
write!(text, "\n{}", file.mime).ok();
} else {
text += "\n???";
}