File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -104,25 +104,18 @@ impl Stage {
104104 ) ;
105105 } ) ;
106106
107- ui. input ( |i| {
108- let zoom = i. zoom_delta ( ) ;
109- if zoom != 1.0 {
110- if let Some ( mouse_pos) = i. pointer . hover_pos ( ) {
111- let old_zoom = self . camera . zoom ( ) ;
112- self . camera . zoom_by ( zoom) ;
113-
114- // 修正缩放中心
115- let offset = mouse_pos - rect. center ( ) ;
116- let delta = offset * ( self . camera . zoom ( ) / old_zoom - 1.0 ) ;
117- self . camera . pan_by ( delta) ;
118- }
119- }
120-
121- let scroll_delta = -i. smooth_scroll_delta ;
122- if scroll_delta != egui:: Vec2 :: ZERO && zoom == 1.0 {
123- self . camera . pan_by ( scroll_delta) ;
107+ let scroll_delta = ui. input ( |i| i. smooth_scroll_delta ) ;
108+ if scroll_delta. y != 0.0 {
109+ if let Some ( mouse_pos) = ui. input ( |i| i. pointer . hover_pos ( ) ) {
110+ let zoom_factor = ( 1.0 + scroll_delta. y * 0.01 ) . clamp ( 0.9 , 1.1 ) ;
111+ let old_zoom = self . camera . zoom ( ) ;
112+ self . camera . zoom_by ( zoom_factor) ;
113+
114+ let offset = mouse_pos - rect. center ( ) ;
115+ let delta = offset * ( self . camera . zoom ( ) / old_zoom - 1.0 ) ;
116+ self . camera . pan_by ( delta) ;
124117 }
125- } ) ;
118+ }
126119
127120 // 中键拖拽平移
128121 if response. dragged_by ( egui:: PointerButton :: Middle ) {
You can’t perform that action at this time.
0 commit comments