Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. macro_rules! create_input_tracker {
  2. ($name: ident, $( $element: ident: $ty: ty ; $text: tt ) , +) => {
  3. /// A simple combination of input trackers.
  4. ///
  5. /// You can use this as your [`Game::Input`] directly!
  6. ///
  7. /// [`Game::Input`]: ../trait.Game.html#associatedtype.Input
  8. pub struct $name {
  9. $ (
  10. $element: $ty,
  11. ) +
  12. }
  13.  
  14. impl $name {
  15. $ (
  16. #[doc = "Returns the "]
  17. #[doc = $text]
  18. #[doc = " input tracker."]
  19. pub fn $element(&self) -> &$ty {
  20. &self.$element
  21. }
  22. ) +
  23. }
  24.  
  25. impl Input for $name {
  26. fn new() -> $name {
  27. $name {
  28. $ (
  29. $element: <$ty as Input>::new(),
  30. ) +
  31. }
  32. }
  33.  
  34. fn update(&mut self, event: Event) {
  35. $ (
  36. <$ty as Input>::update(&mut self.$element, event);
  37. ) +
  38. }
  39.  
  40. fn clear(&mut self) {
  41. $ (
  42. <$ty as Input>::clear(&mut self.$element);
  43. ) +
  44. }
  45. }
  46. };
  47. }
  48.  
  49. create_input_tracker!(KeyboardAndMouse, mouse: Mouse; "mouse", keyboard: Keyboard; "keyboard");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement