less refcells; haptics
This commit is contained in:
@@ -100,6 +100,7 @@ pub struct CallbackData<'a> {
|
||||
pub node_id: taffy::NodeId,
|
||||
pub dirty_nodes: &'a mut Vec<taffy::NodeId>,
|
||||
pub needs_redraw: bool,
|
||||
pub trigger_haptics: bool,
|
||||
}
|
||||
|
||||
impl<'a> WidgetCallback<'a> for CallbackData<'a> {
|
||||
|
||||
@@ -20,9 +20,10 @@ pub type BoxWidget = Arc<Mutex<WidgetState>>;
|
||||
pub type WidgetMap = HopSlotMap<slotmap::DefaultKey, BoxWidget>;
|
||||
|
||||
struct PushEventState<'a> {
|
||||
pub needs_redraw: bool,
|
||||
pub animations: &'a mut Vec<animation::Animation>,
|
||||
pub transform_stack: &'a mut TransformStack,
|
||||
pub needs_redraw: bool,
|
||||
pub trigger_haptics: bool,
|
||||
}
|
||||
|
||||
pub struct Layout {
|
||||
@@ -40,6 +41,7 @@ pub struct Layout {
|
||||
pub content_size: Vec2,
|
||||
|
||||
pub needs_redraw: bool,
|
||||
pub haptics_triggered: bool,
|
||||
|
||||
pub animations: Animations,
|
||||
}
|
||||
@@ -148,6 +150,7 @@ impl Layout {
|
||||
tree: &self.tree,
|
||||
animations: state.animations,
|
||||
needs_redraw: &mut state.needs_redraw,
|
||||
trigger_haptics: &mut state.trigger_haptics,
|
||||
node_id,
|
||||
style,
|
||||
taffy_layout: l,
|
||||
@@ -185,15 +188,25 @@ impl Layout {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_toggle_haptics_triggered(&mut self) -> bool {
|
||||
if self.haptics_triggered {
|
||||
self.haptics_triggered = false;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_event(&mut self, event: &event::Event) -> anyhow::Result<()> {
|
||||
let mut transform_stack = TransformStack::new();
|
||||
let mut animations_to_add = Vec::<animation::Animation>::new();
|
||||
let mut dirty_nodes = Vec::new();
|
||||
|
||||
let mut state = PushEventState {
|
||||
needs_redraw: false,
|
||||
transform_stack: &mut transform_stack,
|
||||
animations: &mut animations_to_add,
|
||||
needs_redraw: false,
|
||||
trigger_haptics: false,
|
||||
};
|
||||
|
||||
self.push_event_widget(&mut state, self.root_node, event, &mut dirty_nodes)?;
|
||||
@@ -202,6 +215,10 @@ impl Layout {
|
||||
self.tree.mark_dirty(node)?;
|
||||
}
|
||||
|
||||
if state.trigger_haptics {
|
||||
self.haptics_triggered = true;
|
||||
}
|
||||
|
||||
if state.needs_redraw {
|
||||
self.needs_redraw = true;
|
||||
}
|
||||
@@ -242,6 +259,7 @@ impl Layout {
|
||||
widget_node_map,
|
||||
widget_states,
|
||||
needs_redraw: true,
|
||||
haptics_triggered: false,
|
||||
animations: Animations::default(),
|
||||
assets,
|
||||
})
|
||||
|
||||
@@ -123,6 +123,7 @@ pub struct EventParams<'a> {
|
||||
pub transform_stack: &'a TransformStack,
|
||||
pub animations: &'a mut Vec<animation::Animation>,
|
||||
pub needs_redraw: &'a mut bool,
|
||||
pub trigger_haptics: &'a mut bool,
|
||||
pub dirty_nodes: &'a mut Vec<taffy::NodeId>,
|
||||
}
|
||||
|
||||
@@ -343,8 +344,12 @@ impl WidgetState {
|
||||
widget_id,
|
||||
node_id,
|
||||
needs_redraw: false,
|
||||
trigger_haptics: false,
|
||||
};
|
||||
callback(&mut data);
|
||||
if data.trigger_haptics {
|
||||
*params.trigger_haptics = true;
|
||||
}
|
||||
if data.needs_redraw {
|
||||
*params.needs_redraw = true;
|
||||
}
|
||||
@@ -361,8 +366,12 @@ impl WidgetState {
|
||||
widget_id,
|
||||
node_id,
|
||||
needs_redraw: false,
|
||||
trigger_haptics: false,
|
||||
};
|
||||
callback(&mut data);
|
||||
if data.trigger_haptics {
|
||||
*params.trigger_haptics = true;
|
||||
}
|
||||
if data.needs_redraw {
|
||||
*params.needs_redraw = true;
|
||||
}
|
||||
@@ -379,8 +388,12 @@ impl WidgetState {
|
||||
widget_id,
|
||||
node_id,
|
||||
needs_redraw: false,
|
||||
trigger_haptics: false,
|
||||
};
|
||||
callback(&mut data, button);
|
||||
if data.trigger_haptics {
|
||||
*params.trigger_haptics = true;
|
||||
}
|
||||
if data.needs_redraw {
|
||||
*params.needs_redraw = true;
|
||||
}
|
||||
@@ -397,8 +410,12 @@ impl WidgetState {
|
||||
widget_id,
|
||||
node_id,
|
||||
needs_redraw: false,
|
||||
trigger_haptics: false,
|
||||
};
|
||||
callback(&mut data, button);
|
||||
if data.trigger_haptics {
|
||||
*params.trigger_haptics = true;
|
||||
}
|
||||
if data.needs_redraw {
|
||||
*params.needs_redraw = true;
|
||||
}
|
||||
@@ -414,8 +431,12 @@ impl WidgetState {
|
||||
widget_id,
|
||||
node_id,
|
||||
needs_redraw: false,
|
||||
trigger_haptics: false,
|
||||
};
|
||||
callback(&mut data);
|
||||
if data.trigger_haptics {
|
||||
*params.trigger_haptics = true;
|
||||
}
|
||||
if data.needs_redraw {
|
||||
*params.needs_redraw = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user