RE ADD CONTEXT
This commit is contained in:
1 parent
dc2be7f688
commit
0b8a93c5ce
39 files changed
+925
-713
No files matched your search
+14
-19
@@ -138,28 +138,23 @@ pub struct CursorData<'a> {
|
||||
pub sense: CursorSense,
|
||||
}
|
||||
|
||||
pub trait SensorUi {
|
||||
fn run_sensors<Ctx: 'static>(&mut self, ctx: &mut Ctx, cursor: &CursorState, window_size: Vec2);
|
||||
pub trait SensorUi<State> {
|
||||
fn run_sensors(&mut self, cursor: &CursorState, window_size: Vec2);
|
||||
}
|
||||
|
||||
impl SensorUi for Ui {
|
||||
fn run_sensors<Ctx: 'static>(
|
||||
&mut self,
|
||||
ctx: &mut Ctx,
|
||||
cursor: &CursorState,
|
||||
window_size: Vec2,
|
||||
) {
|
||||
let layers = std::mem::take(&mut self.data.layers);
|
||||
impl<State: 'static + HasUi> SensorUi<State> for State {
|
||||
fn run_sensors(&mut self, cursor: &CursorState, window_size: Vec2) {
|
||||
let layers = std::mem::take(&mut self.ui().data.layers);
|
||||
let mut active =
|
||||
std::mem::take(&mut self.data.events.get_type::<CursorSense, Ctx>().active);
|
||||
std::mem::take(&mut self.ui().data.events.get_type::<CursorSense>().active);
|
||||
for layer in layers.indices().rev() {
|
||||
let mut sensed = false;
|
||||
for (id, state) in active.get_mut(&layer).into_iter().flatten() {
|
||||
let shape = self.data.active.get(id).unwrap().region;
|
||||
for (id, sensor) in active.get_mut(&layer).into_iter().flatten() {
|
||||
let shape = self.ui().data.active.get(id).unwrap().region;
|
||||
let region = shape.to_px(window_size);
|
||||
let in_shape = cursor.exists && region.contains(cursor.pos);
|
||||
state.hover.update(in_shape);
|
||||
if state.hover == ActivationState::Off {
|
||||
sensor.hover.update(in_shape);
|
||||
if sensor.hover == ActivationState::Off {
|
||||
continue;
|
||||
}
|
||||
sensed = true;
|
||||
@@ -168,20 +163,20 @@ impl SensorUi for Ui {
|
||||
pos: cursor.pos - region.top_left,
|
||||
size: region.bot_right - region.top_left,
|
||||
scroll_delta: cursor.scroll_delta,
|
||||
hover: state.hover,
|
||||
hover: sensor.hover,
|
||||
cursor,
|
||||
// this does not have any meaning;
|
||||
// might wanna set up Event to have a prepare stage
|
||||
sense: CursorSense::Hovering,
|
||||
};
|
||||
self.run_event::<CursorSense, Ctx>(ctx, *id, &mut data);
|
||||
self.run_event::<CursorSense>(*id, &mut data);
|
||||
}
|
||||
if sensed {
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.data.events.get_type::<CursorSense, Ctx>().active = active;
|
||||
self.data.layers = layers;
|
||||
self.ui().data.events.get_type::<CursorSense>().active = active;
|
||||
self.ui().data.layers = layers;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user