text: Implement Debug for LayoutContent

This commit is contained in:
Kamil Jarosz 2024-06-27 14:15:02 +02:00 committed by Nathan Adams
parent 47ea369047
commit a606fcc8ed
1 changed files with 22 additions and 1 deletions

View File

@ -11,6 +11,7 @@ use crate::DefaultFont;
use gc_arena::Collect; use gc_arena::Collect;
use ruffle_render::shape_utils::DrawCommand; use ruffle_render::shape_utils::DrawCommand;
use std::cmp::{max, min}; use std::cmp::{max, min};
use std::fmt::{Debug, Formatter};
use std::mem; use std::mem;
use std::ops::Deref; use std::ops::Deref;
use std::slice::Iter; use std::slice::Iter;
@ -819,7 +820,7 @@ pub struct LayoutBox<'gc> {
/// Represents different content modes of a given `LayoutBox`. /// Represents different content modes of a given `LayoutBox`.
/// ///
/// Currently, a `LayoutBox` can contain `Text`, `Bullet`s, or a `Drawing`. /// Currently, a `LayoutBox` can contain `Text`, `Bullet`s, or a `Drawing`.
#[derive(Clone, Debug, Collect)] #[derive(Clone, Collect)]
#[collect(no_drop)] #[collect(no_drop)]
pub enum LayoutContent<'gc> { pub enum LayoutContent<'gc> {
/// A layout box containing some part of a text span. /// A layout box containing some part of a text span.
@ -889,6 +890,26 @@ pub enum LayoutContent<'gc> {
}, },
} }
impl<'gc> Debug for LayoutContent<'gc> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
LayoutContent::Text { start, end, .. } => f
.debug_struct("Text")
.field("start", start)
.field("end", end)
.finish(),
LayoutContent::Bullet { position, .. } => f
.debug_struct("Bullet")
.field("position", position)
.finish(),
LayoutContent::Drawing { position, .. } => f
.debug_struct("Drawing")
.field("position", position)
.finish(),
}
}
}
impl<'gc> LayoutBox<'gc> { impl<'gc> LayoutBox<'gc> {
/// Construct a text box for a text node. /// Construct a text box for a text node.
pub fn from_text(start: usize, end: usize, font: Font<'gc>, span: &TextSpan) -> Self { pub fn from_text(start: usize, end: usize, font: Font<'gc>, span: &TextSpan) -> Self {