Skip to main content

ferroui_base/media/
text_hit_test_result.rs

1use crate::media::CharacterHit;
2
3/// Holds a hit test result from a text layout.
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
5pub struct TextHitTestResult {
6    character_hit: CharacterHit,
7    text_position: i32,
8    is_inside: bool,
9    is_trailing: bool,
10}
11
12impl TextHitTestResult {
13    pub const fn new(character_hit: CharacterHit, text_position: i32, is_inside: bool, is_trailing: bool) -> Self {
14        Self { character_hit, text_position, is_inside, is_trailing }
15    }
16
17    /// Gets the character hit of the hit test result.
18    pub const fn character_hit(&self) -> CharacterHit {
19        self.character_hit
20    }
21
22    /// Gets a value indicating whether the point is inside the bounds of the text layout.
23    pub const fn is_inside(&self) -> bool {
24        self.is_inside
25    }
26
27    /// Gets the index of the hit character in the text.
28    pub const fn text_position(&self) -> i32 {
29        self.text_position
30    }
31
32    /// Gets a value indicating whether the hit is on the trailing edge of the character.
33    pub const fn is_trailing(&self) -> bool {
34        self.is_trailing
35    }
36}