layout/scrolling: Add move_y_animation
Browse files at this commit357a453c869724a0fb40851e10a3f7239633ea2eParent: ab353481 changed file +38 -0
- src/layout/scrolling.rs +38 -0
src/layout/scrolling.rsmodified+38 -0
| @@ -195,6 +195,9 @@ pub struct Column<W: LayoutElement> { | |||
| 195 | /// Animation of the render offset during window swapping. | 195 | /// Animation of the render offset during window swapping. |
| 196 | move_animation: Option<MoveAnimation>, | 196 | move_animation: Option<MoveAnimation>, |
| 197 | 197 | ||
| 198 | + /// Animation of a column visually moving vertically. | ||
| 199 | + move_y_animation: Option<MoveAnimation>, | ||
| 200 | + | ||
| 198 | /// Latest known view size for this column's workspace. | 201 | /// Latest known view size for this column's workspace. |
| 199 | view_size: Size<f64, Logical>, | 202 | view_size: Size<f64, Logical>, |
| 200 | 203 | ||
| @@ -3971,6 +3974,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 3971 | display_mode, | 3974 | display_mode, |
| 3972 | tab_indicator: TabIndicator::new(options.layout.tab_indicator), | 3975 | tab_indicator: TabIndicator::new(options.layout.tab_indicator), |
| 3973 | move_animation: None, | 3976 | move_animation: None, |
| 3977 | + move_y_animation: None, | ||
| 3974 | view_size, | 3978 | view_size, |
| 3975 | working_area, | 3979 | working_area, |
| 3976 | parent_area, | 3980 | parent_area, |
| @@ -4077,6 +4081,11 @@ impl<W: LayoutElement> Column<W> { | |||
| 4077 | self.move_animation = None; | 4081 | self.move_animation = None; |
| 4078 | } | 4082 | } |
| 4079 | } | 4083 | } |
| 4084 | + if let Some(move_) = &mut self.move_y_animation { | ||
| 4085 | + if move_.anim.is_done() { | ||
| 4086 | + self.move_y_animation = None; | ||
| 4087 | + } | ||
| 4088 | + } | ||
| 4080 | 4089 | ||
| 4081 | for tile in &mut self.tiles { | 4090 | for tile in &mut self.tiles { |
| 4082 | tile.advance_animations(); | 4091 | tile.advance_animations(); |
| @@ -4087,12 +4096,14 @@ impl<W: LayoutElement> Column<W> { | |||
| 4087 | 4096 | ||
| 4088 | pub fn are_animations_ongoing(&self) -> bool { | 4097 | pub fn are_animations_ongoing(&self) -> bool { |
| 4089 | self.move_animation.is_some() | 4098 | self.move_animation.is_some() |
| 4099 | + || self.move_y_animation.is_some() | ||
| 4090 | || self.tab_indicator.are_animations_ongoing() | 4100 | || self.tab_indicator.are_animations_ongoing() |
| 4091 | || self.tiles.iter().any(Tile::are_animations_ongoing) | 4101 | || self.tiles.iter().any(Tile::are_animations_ongoing) |
| 4092 | } | 4102 | } |
| 4093 | 4103 | ||
| 4094 | pub fn are_transitions_ongoing(&self) -> bool { | 4104 | pub fn are_transitions_ongoing(&self) -> bool { |
| 4095 | self.move_animation.is_some() | 4105 | self.move_animation.is_some() |
| 4106 | + || self.move_y_animation.is_some() | ||
| 4096 | || self.tab_indicator.are_animations_ongoing() | 4107 | || self.tab_indicator.are_animations_ongoing() |
| 4097 | || self.tiles.iter().any(Tile::are_transitions_ongoing) | 4108 | || self.tiles.iter().any(Tile::are_transitions_ongoing) |
| 4098 | } | 4109 | } |
| @@ -4159,6 +4170,9 @@ impl<W: LayoutElement> Column<W> { | |||
| 4159 | if let Some(move_) = &self.move_animation { | 4170 | if let Some(move_) = &self.move_animation { |
| 4160 | offset.x += move_.from * move_.anim.value(); | 4171 | offset.x += move_.from * move_.anim.value(); |
| 4161 | } | 4172 | } |
| 4173 | + if let Some(move_) = &self.move_y_animation { | ||
| 4174 | + offset.y += move_.from * move_.anim.value(); | ||
| 4175 | + } | ||
| 4162 | 4176 | ||
| 4163 | offset | 4177 | offset |
| 4164 | } | 4178 | } |
| @@ -4187,6 +4201,30 @@ impl<W: LayoutElement> Column<W> { | |||
| 4187 | }); | 4201 | }); |
| 4188 | } | 4202 | } |
| 4189 | 4203 | ||
| 4204 | + pub fn animate_move_y_from(&mut self, from_y_offset: f64) { | ||
| 4205 | + self.animate_move_y_from_with_config( | ||
| 4206 | + from_y_offset, | ||
| 4207 | + self.options.animations.window_movement.0, | ||
| 4208 | + ); | ||
| 4209 | + } | ||
| 4210 | + | ||
| 4211 | + pub fn animate_move_y_from_with_config( | ||
| 4212 | + &mut self, | ||
| 4213 | + from_y_offset: f64, | ||
| 4214 | + config: niri_config::Animation, | ||
| 4215 | + ) { | ||
| 4216 | + let current_offset = self | ||
| 4217 | + .move_y_animation | ||
| 4218 | + .as_ref() | ||
| 4219 | + .map_or(0., |move_| move_.from * move_.anim.value()); | ||
| 4220 | + | ||
| 4221 | + let anim = Animation::new(self.clock.clone(), 1., 0., 0., config); | ||
| 4222 | + self.move_y_animation = Some(MoveAnimation { | ||
| 4223 | + anim, | ||
| 4224 | + from: from_y_offset + current_offset, | ||
| 4225 | + }); | ||
| 4226 | + } | ||
| 4227 | + | ||
| 4190 | pub fn offset_move_anim_current(&mut self, offset: f64) { | 4228 | pub fn offset_move_anim_current(&mut self, offset: f64) { |
| 4191 | if let Some(move_) = self.move_animation.as_mut() { | 4229 | if let Some(move_) = self.move_animation.as_mut() { |
| 4192 | // If the anim is almost done, there's little point trying to offset it; we can let | 4230 | // If the anim is almost done, there's little point trying to offset it; we can let |