Fix Default implementation for Paragraph

This commit is contained in:
Héctor Ramón Jiménez 2023-09-01 04:14:06 +02:00
parent 51e69d7040
commit 6758de2b43
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -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 {
@ -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
@ -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>,