[−][src]Trait piet::TextLayout
Text Layout
A text position is defined in utf-8 code units, as is standard for Rust strings.
However, text position is also related to valid cursor positions. Therefore:
- The end of a line is a valid text position. e.g.
text.len()
is a valid text position. - If the text position is not at a code point or grapheme boundary, undesirable behavior may occur.
Required methods
fn width(&self) -> f64
Measure the advance width of the text.
fn hit_test_point(&self, point: Point) -> HitTestPoint
Given a Point, determine the corresponding text position
fn hit_test_text_position(
&self,
text_position: usize
) -> Option<HitTestTextPosition>
&self,
text_position: usize
) -> Option<HitTestTextPosition>
Given a text position, determine the corresponding pixel location (currently consider the text layout just one line)
Note: if text position is not at grapheme boundary, rounds the boundary to the text position of the grapheme cluster it is a part of. Returned text position is the original text position.
Note: in directwrite, if text position is not at code point boundary, this method will panic. Cairo and web are more lenient and may not panic.