Created
July 10, 2019 22:42
-
-
Save DarkDrek/1466b2d6a25c03318faa232f5b540fe3 to your computer and use it in GitHub Desktop.
Macro to generate Input combinations
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
macro_rules! create_input_tracker { | |
($name: ident, $( $element: ident: $ty: ty ; $text: tt ) , +) => { | |
/// A simple combination of input trackers. | |
/// | |
/// You can use this as your [`Game::Input`] directly! | |
/// | |
/// [`Game::Input`]: ../trait.Game.html#associatedtype.Input | |
pub struct $name { | |
$ ( | |
$element: $ty, | |
) + | |
} | |
impl $name { | |
$ ( | |
#[doc = "Returns the "] | |
#[doc = $text] | |
#[doc = " input tracker."] | |
pub fn $element(&self) -> &$ty { | |
&self.$element | |
} | |
) + | |
} | |
impl Input for $name { | |
fn new() -> $name { | |
$name { | |
$ ( | |
$element: <$ty as Input>::new(), | |
) + | |
} | |
} | |
fn update(&mut self, event: Event) { | |
$ ( | |
<$ty as Input>::update(&mut self.$element, event); | |
) + | |
} | |
fn clear(&mut self) { | |
$ ( | |
<$ty as Input>::clear(&mut self.$element); | |
) + | |
} | |
} | |
}; | |
} | |
create_input_tracker!(KeyboardAndMouse, mouse: Mouse; "mouse", keyboard: Keyboard; "keyboard"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment