Checkpoint
This commit is contained in:
parent
2c6f692c56
commit
afff46b335
4 changed files with 123 additions and 54 deletions
|
@ -31,8 +31,10 @@ pub struct SceneBuilder {
|
|||
scale_factor: f32,
|
||||
stacking_contexts: Vec<StackingContext>,
|
||||
active_stacking_context_stack: Vec<usize>,
|
||||
/// Used by the playground crate.
|
||||
/// Used by the playground crate. I hope to replace it with event_handlers.
|
||||
pub interactive_regions: Vec<InteractiveRegion>,
|
||||
/// Used by the playground crate.
|
||||
pub event_handlers: Vec<EventHandler>,
|
||||
#[cfg(debug_assertions)]
|
||||
mouse_region_ids: HashSet<MouseRegionId>,
|
||||
}
|
||||
|
@ -41,6 +43,7 @@ pub struct Scene {
|
|||
scale_factor: f32,
|
||||
stacking_contexts: Vec<StackingContext>,
|
||||
interactive_regions: Vec<InteractiveRegion>,
|
||||
event_handlers: Vec<EventHandler>,
|
||||
}
|
||||
|
||||
struct StackingContext {
|
||||
|
@ -282,11 +285,17 @@ impl Scene {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// TODO: Hoping to replace this with take_event_handlers
|
||||
pub fn take_interactive_regions(&mut self) -> Vec<InteractiveRegion> {
|
||||
self.interactive_regions
|
||||
.sort_by(|a, b| a.order.cmp(&b.order));
|
||||
std::mem::take(&mut self.interactive_regions)
|
||||
}
|
||||
|
||||
pub fn take_event_handlers(&mut self) -> Vec<EventHandler> {
|
||||
self.event_handlers.sort_by(|a, b| a.order.cmp(&b.order));
|
||||
std::mem::take(&mut self.event_handlers)
|
||||
}
|
||||
}
|
||||
|
||||
impl SceneBuilder {
|
||||
|
@ -299,6 +308,7 @@ impl SceneBuilder {
|
|||
#[cfg(debug_assertions)]
|
||||
mouse_region_ids: Default::default(),
|
||||
interactive_regions: Vec::new(),
|
||||
event_handlers: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,6 +319,7 @@ impl SceneBuilder {
|
|||
scale_factor: self.scale_factor,
|
||||
stacking_contexts: self.stacking_contexts,
|
||||
interactive_regions: self.interactive_regions,
|
||||
event_handlers: self.event_handlers,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -717,6 +728,14 @@ pub struct InteractiveRegion {
|
|||
pub view_id: usize,
|
||||
}
|
||||
|
||||
pub struct EventHandler {
|
||||
pub order: u32,
|
||||
// First param is a dynamic view reference
|
||||
// Second param is a dynamic event reference
|
||||
pub handler: Rc<dyn Fn(&mut dyn Any, &dyn Any, &mut WindowContext, usize)>,
|
||||
pub event_type: TypeId,
|
||||
}
|
||||
|
||||
fn can_draw(bounds: RectF) -> bool {
|
||||
let size = bounds.size();
|
||||
size.x() > 0. && size.y() > 0.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue