ferroui_base/media/character_hit.rs
1/// Represents information about a character hit within a glyph run.
2///
3/// The `CharacterHit` structure provides information about the index of the
4/// first character that got hit as well as information about leading or
5/// trailing edge.
6///
7/// Indices and lengths are UTF-16 code units (see the index-unit note in
8/// `media/text_formatting/mod.rs`).
9#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
10pub struct CharacterHit {
11 first_character_index: i32,
12 trailing_length: i32,
13}
14
15impl CharacterHit {
16 /// Creates a hit on the leading edge of the character at `first_character_index`.
17 #[inline]
18 pub const fn new(first_character_index: i32) -> Self {
19 Self { first_character_index, trailing_length: 0 }
20 }
21
22 /// Creates a hit with a trailing length.
23 #[inline]
24 pub const fn with_trailing_length(first_character_index: i32, trailing_length: i32) -> Self {
25 Self { first_character_index, trailing_length }
26 }
27
28 /// Gets the index of the first character that got hit.
29 #[inline]
30 pub const fn first_character_index(&self) -> i32 {
31 self.first_character_index
32 }
33
34 /// Gets the trailing length value for the character that got hit.
35 #[inline]
36 pub const fn trailing_length(&self) -> i32 {
37 self.trailing_length
38 }
39}