move ctx in event to be on module so run event and stuff can be used easily
This commit is contained in:
@@ -142,6 +142,17 @@ impl<Ctx> SensorModule<Ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SensorCtx: UiCtx {
|
||||
fn run_sensors(&mut self, cursor: &CursorState, window_size: Vec2);
|
||||
}
|
||||
|
||||
impl<Ctx: UiCtx + 'static> SensorCtx for Ctx {
|
||||
fn run_sensors(&mut self, cursor: &CursorState, window_size: Vec2) {
|
||||
SensorModule::<Ctx>::run(self, cursor, window_size);
|
||||
SensorModule::<Ui>::run(self.ui(), cursor, window_size);
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx: UiCtx + 'static> SensorModule<Ctx> {
|
||||
pub fn run(ctx: &mut Ctx, cursor: &CursorState, window_size: Vec2) {
|
||||
let layers = std::mem::take(&mut ctx.ui().layers);
|
||||
@@ -243,20 +254,20 @@ impl ActivationState {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx: 'static> Event<Ctx> for Senses {
|
||||
type Module = SensorModule<Ctx>;
|
||||
impl Event for Senses {
|
||||
type Module<Ctx: 'static> = SensorModule<Ctx>;
|
||||
type Data = SenseData;
|
||||
}
|
||||
|
||||
impl<Ctx: 'static> Event<Ctx> for Sense {
|
||||
type Module = SensorModule<Ctx>;
|
||||
impl Event for Sense {
|
||||
type Module<Ctx: 'static> = SensorModule<Ctx>;
|
||||
type Data = SenseData;
|
||||
}
|
||||
|
||||
impl<E: Event<Ctx, Data = <Senses as Event<Ctx>>::Data> + Into<Senses>, Ctx: 'static>
|
||||
EventModule<E, Ctx> for SensorModule<Ctx>
|
||||
impl<E: Event<Data = <Senses as Event>::Data> + Into<Senses>, Ctx: 'static> EventModule<E, Ctx>
|
||||
for SensorModule<Ctx>
|
||||
{
|
||||
fn register(&mut self, id: Id, senses: E, f: impl EventFn<Ctx, <E as Event<Ctx>>::Data>) {
|
||||
fn register(&mut self, id: Id, senses: E, f: impl EventFn<Ctx, <E as Event>::Data>) {
|
||||
// TODO: does not add to active if currently active
|
||||
self.map.entry(id).or_default().sensors.push(Sensor {
|
||||
senses: senses.into(),
|
||||
|
||||
Reference in New Issue
Block a user