Skip to content

Commit

Permalink
refactor!: Unbox the text selection property
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcampbell committed Dec 13, 2024
1 parent 484fd7c commit 8134f05
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
12 changes: 6 additions & 6 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ enum PropertyValue {
VerticalOffset(VerticalOffset),
Affine(Box<Affine>),
Rect(Rect),
TextSelection(Box<TextSelection>),
TextSelection(TextSelection),
CustomActionVec(Vec<CustomAction>),
}

Expand Down Expand Up @@ -1466,6 +1466,7 @@ option_ref_type_getters! {
(get_affine_property, Affine, Affine),
(get_string_property, str, String),
(get_coord_slice_property, [f32], CoordSlice),
(get_rect_property, Rect, Rect),
(get_text_selection_property, TextSelection, TextSelection)
}

Expand All @@ -1474,7 +1475,6 @@ slice_type_getters! {
}

copy_type_getters! {
(get_rect_property, Rect, Rect),
(get_node_id_property, NodeId, NodeId),
(get_f64_property, f64, F64),
(get_usize_property, usize, Usize),
Expand All @@ -1487,12 +1487,12 @@ box_type_setters! {
(set_affine_property, Affine, Affine),
(set_string_property, str, String),
(set_length_slice_property, [u8], LengthSlice),
(set_coord_slice_property, [f32], CoordSlice),
(set_text_selection_property, TextSelection, TextSelection)
(set_coord_slice_property, [f32], CoordSlice)
}

copy_type_setters! {
(set_rect_property, Rect, Rect),
(set_text_selection_property, TextSelection, TextSelection),
(set_node_id_property, NodeId, NodeId),
(set_f64_property, f64, F64),
(set_usize_property, usize, Usize),
Expand Down Expand Up @@ -1782,9 +1782,9 @@ property_methods! {
/// the tree's container (e.g. window).
///
/// [`transform`]: Node::transform
(Bounds, bounds, get_rect_property, Option<Rect>, set_bounds, set_rect_property, Rect, clear_bounds),
(Bounds, bounds, get_rect_property, Option<&Rect>, set_bounds, set_rect_property, Rect, clear_bounds),

(TextSelection, text_selection, get_text_selection_property, Option<&TextSelection>, set_text_selection, set_text_selection_property, impl Into<Box<TextSelection>>, clear_text_selection)
(TextSelection, text_selection, get_text_selection_property, Option<&TextSelection>, set_text_selection, set_text_selection_property, TextSelection, clear_text_selection)
}

impl FrozenNode {
Expand Down
4 changes: 1 addition & 3 deletions consumer/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl<'a> Node<'a> {
parent_transform * self.direct_transform()
}

pub fn raw_bounds(&self) -> Option<Rect> {
pub fn raw_bounds(&self) -> Option<&Rect> {
self.data().bounds()
}

Expand All @@ -269,13 +269,11 @@ impl<'a> Node<'a> {
/// container (e.g. window).
pub fn bounding_box(&self) -> Option<Rect> {
self.raw_bounds()
.as_ref()
.map(|rect| self.transform().transform_rect_bbox(*rect))
}

pub(crate) fn bounding_box_in_coordinate_space(&self, other: &Node) -> Option<Rect> {
self.raw_bounds()
.as_ref()
.map(|rect| self.relative_transform(other).transform_rect_bbox(*rect))
}

Expand Down
2 changes: 1 addition & 1 deletion consumer/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ impl<'a> Range<'a> {
let mut result = Vec::new();
self.walk(|node| {
let mut rect = match node.data().bounds() {
Some(rect) => rect,
Some(rect) => *rect,
None => {
return Some(Vec::new());
}
Expand Down

0 comments on commit 8134f05

Please sign in to comment.