Skip to main content

ferroui_base/media/text_formatting/
text_line_break.rs

1use std::cell::{Cell, RefCell};
2use std::rc::Rc;
3
4use crate::media::text_formatting::TextRun;
5use crate::media::FlowDirection;
6
7/// Represents the state of a line break: how the line ended and what the
8/// next line has to continue with.
9pub struct TextLineBreak {
10    text_end_of_line: Option<Rc<dyn TextRun>>,
11    flow_direction: FlowDirection,
12    is_split: bool,
13    /// The runs left over by a wrapped line (upstream `WrappingTextLineBreak`).
14    pub(crate) remaining_runs: RefCell<Option<Vec<Rc<dyn TextRun>>>>,
15    /// Whether this is a wrapping line break (stays true after the runs were acquired).
16    pub(crate) is_wrapping: Cell<bool>,
17}
18
19impl TextLineBreak {
20    /// Creates a line break.
21    ///
22    /// `text_end_of_line` is the end of line run (a run whose
23    /// `as_text_end_of_line` is `Some`) when the line ended with one.
24    pub fn new(text_end_of_line: Option<Rc<dyn TextRun>>, flow_direction: FlowDirection, is_split: bool) -> Self {
25        Self { text_end_of_line, flow_direction, is_split, remaining_runs: RefCell::new(None), is_wrapping: Cell::new(false) }
26    }
27
28    /// Get the end of line run.
29    pub fn text_end_of_line(&self) -> Option<&Rc<dyn TextRun>> {
30        self.text_end_of_line.as_ref()
31    }
32
33    /// Get the flow direction for remaining characters.
34    pub fn flow_direction(&self) -> FlowDirection {
35        self.flow_direction
36    }
37
38    /// Gets whether there were remaining runs after this line break, that
39    /// were split up by the `TextFormatter` during the formatting process.
40    pub fn is_split(&self) -> bool {
41        self.is_split
42    }
43}