mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
dsl: InputLayerCond; collect macros
This commit is contained in:
parent
0d4ba4a54e
commit
3df1938626
6 changed files with 121 additions and 110 deletions
|
|
@ -70,14 +70,18 @@ impl<'a, S, C: DslCommand<'a, S>, I: DslInput> KeyMap<'a, S, C, I> for TokenIter
|
|||
}
|
||||
}
|
||||
|
||||
pub type InputLayerCond<'a, S> = Box<dyn Fn(&S)->bool + Send + Sync + 'a>;
|
||||
|
||||
/// A collection of pre-configured mappings of input events to commands,
|
||||
/// which may be made available subject to given conditions.
|
||||
pub struct InputMap<'a, S, C: DslCommand<'a, S>, I: DslInput, M: KeyMap<'a, S, C, I> + Send + Sync> {
|
||||
pub struct InputMap<'a, S, C, I, M>
|
||||
where
|
||||
C: DslCommand<'a, S>,
|
||||
I: DslInput,
|
||||
M: KeyMap<'a, S, C, I> + Send + Sync
|
||||
{
|
||||
__: &'a PhantomData<(S, C, I)>,
|
||||
pub layers: Vec<(
|
||||
fn(&S)->bool,
|
||||
M
|
||||
)>,
|
||||
pub layers: Vec<(InputLayerCond<'a, S>, M)>,
|
||||
}
|
||||
|
||||
impl<'a, S, C, I, M> Default for InputMap<'a, S, C, I, M>
|
||||
|
|
@ -108,15 +112,15 @@ where
|
|||
self
|
||||
}
|
||||
pub fn add_layer (&mut self, keymap: M) -> &mut Self {
|
||||
self.add_layer_if(|_|true, keymap);
|
||||
self.add_layer_if(Box::new(|_|true), keymap);
|
||||
self
|
||||
}
|
||||
pub fn layer_if (mut self, condition: fn(&S)->bool, keymap: M) -> Self {
|
||||
pub fn layer_if (mut self, condition: InputLayerCond<'a, S>, keymap: M) -> Self {
|
||||
self.add_layer_if(condition, keymap);
|
||||
self
|
||||
}
|
||||
pub fn add_layer_if (&mut self, condition: fn(&S)->bool, keymap: M) -> &mut Self {
|
||||
self.layers.push((condition, keymap));
|
||||
pub fn add_layer_if (&mut self, condition: InputLayerCond<'a, S>, keymap: M) -> &mut Self {
|
||||
self.layers.push((Box::new(condition), keymap));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue