summary history branches tags files
commit:55d7be34a3eeb584c3ef36969bcbc0d78e53f971
author:Trevor Bentley
committer:Trevor Bentley
date:Sun Jul 30 13:30:55 2017 +0200
parents:a45787abf55d4f0eb4ce1904380c1cc7ea618aee
Use fruitbasket stopper correctly in example
diff --git a/examples/example.rs b/examples/example.rs
line changes: +6/-4
index 1a0e9e4..b6b18a1
--- a/examples/example.rs
+++ b/examples/example.rs
@@ -52,7 +52,7 @@ impl TScrubberData for TouchbarHandler {
     }
 }
 
-fn populate(bar_rc: Rc<RefCell<Touchbar>>, count: u32) {
+fn populate(bar_rc: Rc<RefCell<Touchbar>>, count: u32, stopper: fruitbasket::FruitStopper) {
     // Get touchbar from the refcell.  It's wrapped in a cell so
     // it can be passed around in the button callbacks.
     let mut tb = (bar_rc).borrow_mut();
@@ -61,14 +61,15 @@ fn populate(bar_rc: Rc<RefCell<Touchbar>>, count: u32) {
     let mut barid = tb.create_bar();
 
     // Create a quit button for root bar
-    let quit_id = tb.create_button(None, Some("Quit"), Box::new(move |_| {rubrail::app::quit()}));
+    let quit_stopper = stopper.clone();
+    let quit_id = tb.create_button(None, Some("Quit"), Box::new(move |_| {quit_stopper.stop();}));
 
     // Create an action button for the root bar.  When clicked, it will
     // close the bar and re-create itself.
     let bar_copy = bar_rc.clone();
     let text = format!("button{}", count);
     let button1_id = tb.create_button(None, Some(&text), Box::new(move |_| {
-        populate(bar_copy.clone(), count+1)
+        populate(bar_copy.clone(), count+1, stopper.clone())
     }));
 
     // Create a text label for the root bar
@@ -170,8 +171,9 @@ fn main() {
     // Initialize the touchbar
     let bar_rc = Rc::new(RefCell::new(Touchbar::alloc("bar")));
 
+    let stopper = nsapp.stopper();
     // Populate the touchbar with UI elements
-    populate(bar_rc.clone(), 1);
+    populate(bar_rc.clone(), 1, stopper);
 
     // Enter OS X application loop.
     nsapp.run(fruitbasket::RunPeriod::Forever);