separate state from rsc
This commit is contained in:
1 parent
462c0e6416
commit
5da1e9e767
22 files changed
+373
-492
No files matched your search
@@ -115,7 +115,7 @@ pub enum ActivationState {
|
||||
/// or basically have some way to have custom senses
|
||||
/// that depend on active widget positions
|
||||
/// but I'm not sure how or if worth it
|
||||
pub struct Sensor<Ctx, Data> {
|
||||
pub struct Sensor<Ctx: HasEvents, Data> {
|
||||
pub senses: CursorSenses,
|
||||
pub f: Rc<dyn EventFn<Ctx, Data>>,
|
||||
}
|
||||
@@ -138,12 +138,12 @@ pub struct CursorData<'a> {
|
||||
pub sense: CursorSense,
|
||||
}
|
||||
|
||||
pub trait SensorUi<State> {
|
||||
fn run_sensors(&mut self, cursor: &CursorState, window_size: Vec2);
|
||||
pub trait SensorUi<Rsc: HasEvents> {
|
||||
fn run_sensors(&mut self, state: &mut Rsc::State, cursor: &CursorState, window_size: Vec2);
|
||||
}
|
||||
|
||||
impl<State: RunEvents> SensorUi<State> for State {
|
||||
fn run_sensors(&mut self, cursor: &CursorState, window_size: Vec2) {
|
||||
impl<Rsc: HasEvents> SensorUi<Rsc> for Rsc {
|
||||
fn run_sensors(&mut self, state: &mut Rsc::State, cursor: &CursorState, window_size: Vec2) {
|
||||
let layers = std::mem::take(&mut self.ui_mut().layers);
|
||||
let mut active = std::mem::take(&mut self.events_mut().get_type::<CursorSense>().active);
|
||||
for layer in layers.indices().rev() {
|
||||
@@ -168,7 +168,7 @@ impl<State: RunEvents> SensorUi<State> for State {
|
||||
// might wanna set up Event to have a prepare stage
|
||||
sense: CursorSense::Hovering,
|
||||
};
|
||||
self.run_event::<CursorSense>(*id, &mut data);
|
||||
self.run_event::<CursorSense>(*id, &mut data, state);
|
||||
}
|
||||
if sensed {
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user