Skip to content

Commit

Permalink
impl std::fmt::Debug for TexturesDelta
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Feb 22, 2022
1 parent 745f209 commit 2e1a4cf
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions epaint/src/textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ pub struct TexturesDelta {
}

impl TexturesDelta {
pub fn is_empty(&self) -> bool {
self.set.is_empty() && self.free.is_empty()
}

pub fn append(&mut self, mut newer: TexturesDelta) {
self.set.extend(newer.set.into_iter());
self.free.append(&mut newer.free);
Expand All @@ -167,3 +171,32 @@ impl TexturesDelta {
self.free.clear();
}
}

impl std::fmt::Debug for TexturesDelta {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
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!(
"{:?} partial ([{} {}] - [{} {}]), ",
tex_id,
pos[0],
pos[1],
pos[0] + size[0],
pos[1] + size[1]
);
} else {
string += &format!("{:?} full {}x{}, ", tex_id, size[0], size[1]);
}
}
debug_struct.field("set", &string);
}
if !self.free.is_empty() {
debug_struct.field("free", &self.free);
}
debug_struct.finish()
}
}

0 comments on commit 2e1a4cf

Please sign in to comment.