Skip to main content

ferroui_base/media/text_formatting/unicode/
line_break.rs

1// RichTextKit
2// Copyright © 2019 Topten Software. All Rights Reserved.
3//
4// Licensed under the Apache License, Version 2.0 (the "License"); you may
5// not use this product except in compliance with the License. You may obtain
6// a copy of the License at
7//
8// https://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13// License for the specific language governing permissions and limitations
14// under the License.
15//
16// Ported from: https://github.com/foliojs/linebreak
17// Copied from: https://github.com/toptensoftware/RichTextKit
18
19/// Information about a potential line break position
20#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
21pub struct LineBreak {
22    position_measure: usize,
23    position_wrap: usize,
24    required: bool,
25}
26
27impl LineBreak {
28    /// Constructor
29    ///
30    /// * `position_measure` - The code point index to measure to
31    /// * `position_wrap` - The code point index to actually break the line at
32    /// * `required` - True if this is a required line break; otherwise false
33    #[inline]
34    pub const fn new(position_measure: usize, position_wrap: usize, required: bool) -> Self {
35        Self { position_measure, position_wrap, required }
36    }
37
38    /// The break position, before any trailing whitespace
39    ///
40    /// This doesn't include trailing whitespace
41    #[inline]
42    pub const fn position_measure(&self) -> usize {
43        self.position_measure
44    }
45
46    /// The break position, after any trailing whitespace
47    ///
48    /// This includes trailing whitespace
49    #[inline]
50    pub const fn position_wrap(&self) -> usize {
51        self.position_wrap
52    }
53
54    /// True if there should be a forced line break here
55    #[inline]
56    pub const fn required(&self) -> bool {
57        self.required
58    }
59}