Skip to content

Commit

Permalink
Fix Default implementation for Paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Sep 1, 2023
1 parent 51e69d7 commit 6758de2
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions graphics/src/text/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::text::{self, FontSystem};
use std::fmt;
use std::sync::{self, Arc};

#[derive(Clone, PartialEq, Default)]
#[derive(Clone, PartialEq)]
pub struct Paragraph(Option<Arc<Internal>>);

struct Internal {
Expand Down Expand Up @@ -195,6 +195,28 @@ impl core::text::Paragraph for Paragraph {
}
}

impl Default for Paragraph {
fn default() -> Self {
Self(Some(Arc::new(Internal::default())))
}
}

impl fmt::Debug for Paragraph {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let paragraph = self.internal();

f.debug_struct("Paragraph")
.field("content", &paragraph.content)
.field("font", &paragraph.font)
.field("shaping", &paragraph.shaping)
.field("horizontal_alignment", &paragraph.horizontal_alignment)
.field("vertical_alignment", &paragraph.vertical_alignment)
.field("bounds", &paragraph.bounds)
.field("min_bounds", &paragraph.min_bounds)
.finish()
}
}

impl PartialEq for Internal {
fn eq(&self, other: &Self) -> bool {
self.content == other.content
Expand Down Expand Up @@ -226,22 +248,6 @@ impl Default for Internal {
}
}

impl fmt::Debug for Paragraph {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let paragraph = self.internal();

f.debug_struct("Paragraph")
.field("content", &paragraph.content)
.field("font", &paragraph.font)
.field("shaping", &paragraph.shaping)
.field("horizontal_alignment", &paragraph.horizontal_alignment)
.field("vertical_alignment", &paragraph.vertical_alignment)
.field("bounds", &paragraph.bounds)
.field("min_bounds", &paragraph.min_bounds)
.finish()
}
}

#[derive(Debug, Clone)]
pub struct Weak {
raw: sync::Weak<Internal>,
Expand Down

0 comments on commit 6758de2

Please sign in to comment.