-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from mahkoh/jorth/toplevel-cast
Fix toplevel screencasts with hardware cursors
- Loading branch information
Showing
11 changed files
with
191 additions
and
37 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
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
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
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
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,69 @@ | ||
use { | ||
crate::utils::linkedlist::{LinkedList, LinkedListIter, LinkedNode}, | ||
std::{ | ||
cell::Cell, | ||
rc::{Rc, Weak}, | ||
}, | ||
}; | ||
|
||
pub struct EventSource<T: ?Sized> { | ||
listeners: LinkedList<Weak<T>>, | ||
on_attach: Cell<Option<Box<dyn FnOnce()>>>, | ||
} | ||
|
||
pub struct EventListener<T: ?Sized> { | ||
link: LinkedNode<Weak<T>>, | ||
} | ||
|
||
impl<T: ?Sized> Default for EventSource<T> { | ||
fn default() -> Self { | ||
Self { | ||
listeners: Default::default(), | ||
on_attach: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl<T: ?Sized> EventSource<T> { | ||
pub fn iter(&self) -> EventSourceIter<T> { | ||
EventSourceIter { | ||
iter: self.listeners.iter(), | ||
} | ||
} | ||
} | ||
|
||
pub struct EventSourceIter<T: ?Sized> { | ||
iter: LinkedListIter<Weak<T>>, | ||
} | ||
|
||
impl<T: ?Sized> Iterator for EventSourceIter<T> { | ||
type Item = Rc<T>; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
for weak in self.iter.by_ref() { | ||
if let Some(t) = weak.upgrade() { | ||
return Some(t); | ||
} | ||
} | ||
None | ||
} | ||
} | ||
|
||
impl<T: ?Sized> EventListener<T> { | ||
pub fn new(t: Weak<T>) -> Self { | ||
Self { | ||
link: LinkedNode::detached(t), | ||
} | ||
} | ||
|
||
pub fn attach(&self, source: &EventSource<T>) { | ||
source.listeners.add_last_existing(&self.link); | ||
if let Some(on_attach) = source.on_attach.take() { | ||
on_attach(); | ||
} | ||
} | ||
|
||
pub fn detach(&self) { | ||
self.link.detach(); | ||
} | ||
} |
Oops, something went wrong.