-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(animation): Fixed cancelling logic
Added static animation state manager for tracking "in_progress" and "is_cancelled" states. The idea is not to have states in Animation struct but to keep them in HashMap<hwnd, AnimationState> behind reference (Arc<Mutex<>>). So we each animation frame we have access to state and can cancel animation if we have to. Need review and testings
- Loading branch information
1 parent
198b5e8
commit 57e9b2f
Showing
4 changed files
with
105 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use std::collections::HashMap; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
struct AnimationState { | ||
pub in_progress: bool, | ||
pub is_cancelled: bool, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct AnimationManager { | ||
animations: HashMap<isize, AnimationState>, | ||
} | ||
|
||
impl AnimationManager { | ||
pub fn new() -> Self { | ||
Self { | ||
animations: HashMap::new(), | ||
} | ||
} | ||
|
||
pub fn is_cancelled(&self, hwnd: isize) -> bool { | ||
if !self.animations.contains_key(&hwnd) { | ||
return false; | ||
} | ||
|
||
self.animations.get(&hwnd).unwrap().is_cancelled | ||
} | ||
|
||
pub fn in_progress(&self, hwnd: isize) -> bool { | ||
if !self.animations.contains_key(&hwnd) { | ||
return false; | ||
} | ||
|
||
self.animations.get(&hwnd).unwrap().in_progress | ||
} | ||
|
||
pub fn cancel(&mut self, hwnd: isize) { | ||
if !self.animations.contains_key(&hwnd) { | ||
return; | ||
} | ||
|
||
let state = self.animations.get_mut(&hwnd).unwrap(); | ||
state.is_cancelled = true; | ||
} | ||
|
||
pub fn start(&mut self, hwnd: isize) { | ||
if !self.animations.contains_key(&hwnd) { | ||
self.animations.insert( | ||
hwnd, | ||
AnimationState { | ||
in_progress: true, | ||
is_cancelled: false, | ||
}, | ||
); | ||
return; | ||
} | ||
|
||
let state = self.animations.get_mut(&hwnd).unwrap(); | ||
|
||
if !state.in_progress { | ||
state.in_progress = true; | ||
} | ||
} | ||
|
||
pub fn end(&mut self, hwnd: isize) { | ||
if !self.animations.contains_key(&hwnd) { | ||
return; | ||
} | ||
|
||
let state = self.animations.get_mut(&hwnd).unwrap(); | ||
state.in_progress = false; | ||
state.is_cancelled = false; | ||
|
||
self.animations.remove(&hwnd); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters