Skip to main content

ferroui_base/media/text_formatting/
wrapping_text_line_break.rs

1use std::rc::Rc;
2
3use crate::media::text_formatting::{TextLineBreak, TextRun};
4use crate::media::FlowDirection;
5
6/// A line break of a wrapped line that carries the runs the next line starts
7/// with.
8///
9/// Upstream models this as an internal subclass of `TextLineBreak`; here it is
10/// a `TextLineBreak` with remaining runs, created and consumed through these
11/// functions.
12///
13/// Internal upstream; public so that the Skia unit tests reach it.
14pub struct WrappingTextLineBreak;
15
16impl WrappingTextLineBreak {
17    pub fn new(
18        text_end_of_line: Option<Rc<dyn TextRun>>,
19        flow_direction: FlowDirection,
20        remaining_runs: Vec<Rc<dyn TextRun>>,
21    ) -> TextLineBreak {
22        debug_assert!(!remaining_runs.is_empty());
23
24        let line_break = TextLineBreak::new(text_end_of_line, flow_direction, true);
25        *line_break.remaining_runs.borrow_mut() = Some(remaining_runs);
26        line_break.is_wrapping.set(true);
27        line_break
28    }
29
30    /// Whether the line break is a wrapping line break (C# `is WrappingTextLineBreak`).
31    pub fn is_wrapping(line_break: &TextLineBreak) -> bool {
32        line_break.is_wrapping.get()
33    }
34
35    /// Takes the remaining runs; a second call returns `None`.
36    pub fn acquire_remaining_runs(line_break: &TextLineBreak) -> Option<Vec<Rc<dyn TextRun>>> {
37        line_break.remaining_runs.borrow_mut().take()
38    }
39}