finished moving out render_state
This commit is contained in:
1 parent
79813db3ba
commit
06dd015092
26 files changed
+496
-220
No files matched your search
+30
-14
@@ -26,9 +26,9 @@ pub enum CursorSense {
|
||||
pub struct CursorSenses(Vec<CursorSense>);
|
||||
|
||||
impl Event for CursorSenses {
|
||||
type Data = CursorData;
|
||||
type Data<'a> = CursorData<'a>;
|
||||
type State = SensorState;
|
||||
fn should_run(&self, data: &Self::Data) -> Option<Self::Data> {
|
||||
fn should_run<'a>(&self, data: &Self::Data<'a>) -> Option<Self::Data<'a>> {
|
||||
if let Some(sense) = should_run(self, &data.cursor, data.hover) {
|
||||
let mut data = data.clone();
|
||||
data.sense = sense;
|
||||
@@ -129,7 +129,7 @@ pub struct SensorState {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CursorData {
|
||||
pub struct CursorData<'a> {
|
||||
/// where this widget was hit
|
||||
pub pos: Vec2,
|
||||
pub size: Vec2,
|
||||
@@ -138,20 +138,36 @@ pub struct CursorData {
|
||||
pub cursor: CursorState,
|
||||
/// the first sense that triggered this
|
||||
pub sense: CursorSense,
|
||||
pub render: &'a UiRenderState,
|
||||
}
|
||||
|
||||
pub trait SensorUi<Rsc: HasEvents> {
|
||||
fn run_sensors(&mut self, state: &mut Rsc::State, cursor: CursorState, window_size: Vec2);
|
||||
pub trait SensorUi {
|
||||
fn run_sensors<Rsc: HasEvents>(
|
||||
&self,
|
||||
rsc: &mut Rsc,
|
||||
state: &mut Rsc::State,
|
||||
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() {
|
||||
impl SensorUi for UiRenderState {
|
||||
fn run_sensors<Rsc: HasEvents>(
|
||||
&self,
|
||||
rsc: &mut Rsc,
|
||||
state: &mut Rsc::State,
|
||||
cursor: CursorState,
|
||||
window_size: Vec2,
|
||||
) {
|
||||
// in order to remove this take, need to store active list in UiRenderState somehow
|
||||
// this would probably be done through a generic parameter that adds yet another rsc /
|
||||
// state like thing, but local to render state, and is passed to UiRsc events so you can
|
||||
// update it there?
|
||||
let mut active = std::mem::take(&mut rsc.events_mut().get_type::<CursorSense>().active);
|
||||
for layer in self.layers.indices().rev() {
|
||||
let mut sensed = false;
|
||||
for (id, sensor) in active.get_mut(&layer).into_flat_iter() {
|
||||
let shape = self.ui().active.get(id).unwrap().region;
|
||||
let shape = self.active.get(id).unwrap().region;
|
||||
let region = shape.to_px(window_size);
|
||||
let in_shape = cursor.exists && region.contains(cursor.pos);
|
||||
sensor.hover.update(in_shape);
|
||||
@@ -171,15 +187,15 @@ impl<Rsc: HasEvents> SensorUi<Rsc> for Rsc {
|
||||
// this does not have any meaning;
|
||||
// might wanna set up Event to have a prepare stage
|
||||
sense: CursorSense::Hovering,
|
||||
render: self,
|
||||
};
|
||||
self.run_event::<CursorSense>(*id, data, state);
|
||||
rsc.run_event::<CursorSense>(*id, data, state);
|
||||
}
|
||||
if sensed {
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.events_mut().get_type::<CursorSense>().active = active;
|
||||
self.ui_mut().layers = layers;
|
||||
rsc.events_mut().get_type::<CursorSense>().active = active;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user