@@ -19,6 +19,8 @@ pub struct Pivot {
1919 pivot : Option < DVec2 > ,
2020 /// The old pivot position in the GUI, used to reduce refreshes of the document bar
2121 old_pivot_position : PivotPosition ,
22+ /// Used to enable and disable the pivot
23+ active : bool
2224}
2325
2426impl Default for Pivot {
@@ -28,6 +30,7 @@ impl Default for Pivot {
2830 transform_from_normalized : Default :: default ( ) ,
2931 pivot : Default :: default ( ) ,
3032 old_pivot_position : PivotPosition :: Center ,
33+ active : true
3134 }
3235 }
3336}
@@ -44,6 +47,8 @@ impl Pivot {
4447
4548 /// Recomputes the pivot position and transform.
4649 fn recalculate_pivot ( & mut self , document : & DocumentMessageHandler ) {
50+ if !self . active { return ; }
51+
4752 let selected_nodes = document. network_interface . selected_nodes ( ) ;
4853 let mut layers = selected_nodes. selected_visible_and_unlocked_layers ( & document. network_interface ) ;
4954 let Some ( first) = layers. next ( ) else {
@@ -83,8 +88,12 @@ impl Pivot {
8388
8489 pub fn update_pivot ( & mut self , document : & DocumentMessageHandler , overlay_context : & mut OverlayContext , draw_data : Option < ( f64 , ) > ) {
8590 if !overlay_context. visibility_settings . pivot ( ) {
91+ self . active = false ;
8692 return ;
8793 }
94+ else {
95+ self . active = true ;
96+ }
8897
8998 self . recalculate_pivot ( document) ;
9099 if let ( Some ( pivot) , Some ( data) ) = ( self . pivot , draw_data) {
@@ -94,6 +103,10 @@ impl Pivot {
94103
95104 /// Answers if the pivot widget has changed (so we should refresh the tool bar at the top of the canvas).
96105 pub fn should_refresh_pivot_position ( & mut self ) -> bool {
106+ if !self . active {
107+ return false ;
108+ }
109+
97110 let new = self . to_pivot_position ( ) ;
98111 let should_refresh = new != self . old_pivot_position ;
99112 self . old_pivot_position = new;
@@ -106,6 +119,8 @@ impl Pivot {
106119
107120 /// Sets the viewport position of the pivot for all selected layers.
108121 pub fn set_viewport_position ( & self , position : DVec2 , document : & DocumentMessageHandler , responses : & mut VecDeque < Message > ) {
122+ if !self . active { return ; }
123+
109124 for layer in document. network_interface . selected_nodes ( ) . selected_visible_and_unlocked_layers ( & document. network_interface ) {
110125 let transform = Self :: get_layer_pivot_transform ( layer, document) ;
111126 // Only update the pivot when computed position is finite.
@@ -119,11 +134,16 @@ impl Pivot {
119134
120135 /// Set the pivot using the normalized transform that is set above.
121136 pub fn set_normalized_position ( & self , position : DVec2 , document : & DocumentMessageHandler , responses : & mut VecDeque < Message > ) {
137+ if !self . active { return ; }
138+
122139 self . set_viewport_position ( self . transform_from_normalized . transform_point2 ( position) , document, responses) ;
123140 }
124141
125142 /// Answers if the pointer is currently positioned over the pivot.
126143 pub fn is_over ( & self , mouse : DVec2 ) -> bool {
144+ if !self . active {
145+ return false ;
146+ }
127147 self . pivot . filter ( |& pivot| mouse. distance_squared ( pivot) < ( PIVOT_DIAMETER / 2. ) . powi ( 2 ) ) . is_some ( )
128148 }
129149}
0 commit comments