Ported examples 00 and 01 to proc macro interface.
This commit is contained in:
@@ -585,6 +585,7 @@ impl SceneSnapshot {
|
||||
mod tests {
|
||||
use super::{Color, Point, PreparedText, Rect};
|
||||
use crate::TextSelectionStyle;
|
||||
use crate::{TextStyle, TextSystem, TextWrap};
|
||||
|
||||
#[test]
|
||||
fn prepared_text_hit_testing_clamps_to_nearest_cluster_boundary() {
|
||||
@@ -703,4 +704,22 @@ mod tests {
|
||||
assert_eq!(text.line_start_offset(6), Some(4));
|
||||
assert_eq!(text.line_end_offset(2), Some(4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepared_text_multiline_selection_stays_on_target_line() {
|
||||
let mut text_system = TextSystem::new();
|
||||
let style = TextStyle::new(16.0, Color::rgb(0xFF, 0xFF, 0xFF)).with_wrap(TextWrap::None);
|
||||
let text = text_system.prepare("ab\ncd\nef", Point::new(10.0, 20.0), &style);
|
||||
|
||||
assert_eq!(text.lines.len(), 3);
|
||||
|
||||
let target_line = &text.lines[1];
|
||||
let y = target_line.rect.origin.y + target_line.rect.size.height * 0.5;
|
||||
let start = text.byte_offset_for_position(Point::new(target_line.rect.origin.x, y));
|
||||
let end = text.byte_offset_for_position(Point::new(target_line.rect.origin.x + 16.0, y));
|
||||
let rects = text.selection_rects(start, end);
|
||||
|
||||
assert_eq!(rects.len(), 1);
|
||||
assert_eq!(rects[0].origin.y, target_line.rect.origin.y);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user