use super::{OwnedSection, OwnedText, Section, Text};
use crate::components::text::glyph::layout::{BuiltInLineBreaker, Layout};
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SectionBuilder {
pub screen_position: (f32, f32),
pub bounds: (f32, f32),
pub layout: Layout<BuiltInLineBreaker>,
}
impl Default for SectionBuilder {
fn default() -> Self {
Self {
screen_position: (0.0, 0.0),
bounds: (f32::INFINITY, f32::INFINITY),
layout: Layout::default(),
}
}
}
impl SectionBuilder {
#[inline]
pub fn with_screen_position<P: Into<(f32, f32)>>(mut self, position: P) -> Self {
self.screen_position = position.into();
self
}
#[inline]
pub fn with_bounds<P: Into<(f32, f32)>>(mut self, bounds: P) -> Self {
self.bounds = bounds.into();
self
}
#[inline]
pub fn with_layout<L: Into<Layout<BuiltInLineBreaker>>>(mut self, layout: L) -> Self {
self.layout = layout.into();
self
}
#[inline]
pub fn add_text<X>(self, text: Text<'_, X>) -> Section<'_, X> {
self.with_text(vec![text])
}
#[inline]
pub fn with_text<X>(self, text: Vec<Text<'_, X>>) -> Section<'_, X> {
Section {
text,
screen_position: self.screen_position,
bounds: self.bounds,
layout: self.layout,
}
}
#[inline]
pub fn add_owned_text<X>(self, text: OwnedText<X>) -> OwnedSection<X> {
self.with_owned_text(vec![text])
}
#[inline]
pub fn with_owned_text<X>(self, text: Vec<OwnedText<X>>) -> OwnedSection<X> {
OwnedSection {
text,
screen_position: self.screen_position,
bounds: self.bounds,
layout: self.layout,
}
}
}