|
|
|
@ -6,7 +6,7 @@ use crate::ui::{
|
|
|
|
|
geometry::{Dimensions, LinearLayout, Offset, Rect},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use super::layout::{DefaultTextTheme, TextLayout, TextNoop, TextRenderer};
|
|
|
|
|
use super::layout::{DefaultTextTheme, TextLayout, TextRenderer};
|
|
|
|
|
|
|
|
|
|
pub const MAX_PARAGRAPHS: usize = 6;
|
|
|
|
|
|
|
|
|
@ -71,6 +71,20 @@ where
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "ui_debug")]
|
|
|
|
|
impl<T> crate::trace::Trace for Paragraphs<T>
|
|
|
|
|
where
|
|
|
|
|
T: AsRef<[u8]>,
|
|
|
|
|
{
|
|
|
|
|
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
|
|
|
|
|
t.open("Paragraphs");
|
|
|
|
|
for paragraph in &self.list {
|
|
|
|
|
paragraph.trace(t);
|
|
|
|
|
}
|
|
|
|
|
t.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Paragraph<T> {
|
|
|
|
|
content: T,
|
|
|
|
|
layout: TextLayout,
|
|
|
|
@ -90,11 +104,10 @@ where
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn measure(content: &T, layout: TextLayout) -> Offset {
|
|
|
|
|
let mut cursor = layout.initial_cursor();
|
|
|
|
|
layout.layout_text(content.as_ref(), &mut cursor, &mut TextNoop);
|
|
|
|
|
let width = layout.bounds.width();
|
|
|
|
|
let height = cursor.y - layout.initial_cursor().y;
|
|
|
|
|
Offset::new(width, height)
|
|
|
|
|
Offset::new(
|
|
|
|
|
layout.bounds.width(),
|
|
|
|
|
layout.measure_text_height(content.as_ref()),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -129,3 +142,37 @@ where
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "ui_debug")]
|
|
|
|
|
pub mod trace {
|
|
|
|
|
use crate::ui::component::text::layout::trace::TraceSink;
|
|
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
pub struct TraceText<'a, T>(pub &'a Paragraph<T>);
|
|
|
|
|
|
|
|
|
|
impl<'a, T> crate::trace::Trace for TraceText<'a, T>
|
|
|
|
|
where
|
|
|
|
|
T: AsRef<[u8]>,
|
|
|
|
|
{
|
|
|
|
|
fn trace(&self, d: &mut dyn crate::trace::Tracer) {
|
|
|
|
|
self.0.layout.layout_text(
|
|
|
|
|
self.0.content.as_ref(),
|
|
|
|
|
&mut self.0.layout.initial_cursor(),
|
|
|
|
|
&mut TraceSink(d),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "ui_debug")]
|
|
|
|
|
impl<T> crate::trace::Trace for Paragraph<T>
|
|
|
|
|
where
|
|
|
|
|
T: AsRef<[u8]>,
|
|
|
|
|
{
|
|
|
|
|
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
|
|
|
|
|
t.open("Paragraph");
|
|
|
|
|
t.field("content", &trace::TraceText(self));
|
|
|
|
|
t.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|