MCPcopy Create free account
hub / github.com/AccessKit/accesskit / bounding_boxes

Method bounding_boxes

consumer/src/text.rs:740–821  ·  view source on GitHub ↗

Returns the range's transformed bounding boxes relative to the tree's container (e.g. window). If the return value is empty, it means that the source tree doesn't provide enough information to calculate bounding boxes. Otherwise, there will always be at least one box, even if it's zero-width, as it is for a degenerate range.

(&self)

Source from the content-addressed store, hash-verified

738 /// there will always be at least one box, even if it's zero-width,
739 /// as it is for a degenerate range.
740 pub fn bounding_boxes(&self) -> Vec<Rect> {
741 let mut result = Vec::new();
742 self.walk(|node| {
743 let mut rect = match node.data().bounds() {
744 Some(rect) => rect,
745 None => {
746 return Some(Vec::new());
747 }
748 };
749 let positions = match node.data().character_positions() {
750 Some(positions) => positions,
751 None => {
752 return Some(Vec::new());
753 }
754 };
755 let widths = match node.data().character_widths() {
756 Some(widths) => widths,
757 None => {
758 return Some(Vec::new());
759 }
760 };
761 let direction = match node.text_direction() {
762 Some(direction) => direction,
763 None => {
764 return Some(Vec::new());
765 }
766 };
767 let character_lengths = node.data().character_lengths();
768 let start_index = if node.id() == self.start.node.id() {
769 self.start.character_index
770 } else {
771 0
772 };
773 let end_index = if node.id() == self.end.node.id() {
774 self.end.character_index
775 } else {
776 character_lengths.len()
777 };
778 if start_index != 0 || end_index != character_lengths.len() {
779 let pixel_start = if start_index < character_lengths.len() {
780 positions[start_index]
781 } else {
782 positions[start_index - 1] + widths[start_index - 1]
783 };
784 let pixel_end = if end_index == start_index {
785 pixel_start
786 } else {
787 positions[end_index - 1] + widths[end_index - 1]
788 };
789 let pixel_start = f64::from(pixel_start);
790 let pixel_end = f64::from(pixel_end);
791 match direction {
792 TextDirection::LeftToRight => {
793 let orig_left = rect.x0;
794 rect.x0 = orig_left + pixel_start;
795 rect.x1 = orig_left + pixel_end;
796 }
797 TextDirection::RightToLeft => {

Callers 3

character_extentsMethod · 0.80
GetBoundingRectanglesMethod · 0.80

Calls 6

walkMethod · 0.80
dataMethod · 0.80
lenMethod · 0.80
transform_rect_bboxMethod · 0.80
transformMethod · 0.80
idMethod · 0.45

Tested by

no test coverage detected