summary history branches tags files
commit:c00e8ff8931e8610b1ce6ac098275d612006d1e3
author:Trevor Bentley
committer:Trevor Bentley
date:Mon Jul 24 20:03:05 2017 +0200
parents:d50c794ceae305d414975eac931312d3428229ab
Support label for sliders
diff --git a/examples/example.rs b/examples/example.rs
line changes: +1/-1
index cc1b949..0851ba6
--- a/examples/example.rs
+++ b/examples/example.rs
@@ -98,7 +98,7 @@ fn populate(bar_rc: Rc<RefCell<Touchbar>>, count: u32) {
     tb.select_scrubber_item(&scrubber2_id, 3);
 
     // Create a slider for the popbar.
-    let slider1_id = tb.create_slider(0.0, 50.0, true,
+    let slider1_id = tb.create_slider(0.0, 50.0, true, "Slide",
                                       Box::new(move |_s,v| {info!("Slid to: {}", v);}));
     tb.update_slider(&slider1_id, 15.0);
 

diff --git a/src/interface.rs b/src/interface.rs
line changes: +2/-0
index f100bc5..1ae423e
--- a/src/interface.rs
+++ b/src/interface.rs
@@ -451,6 +451,7 @@ pub trait TTouchbar {
     ///
     /// * `min` - Minimum value (slider all the way left)
     /// * `max` - Maximum value (slider all the way right)
+    /// * `label` - Text label displayed on left of slider (optional)
     /// * `continuous` - Whether callback is called while sliding, or only
     /// * `cb` - Callback called when the slider value is changed
     ///   after it is released.
@@ -459,6 +460,7 @@ pub trait TTouchbar {
     ///
     /// A newly allocated slider item
     fn create_slider(&mut self, min: f64, max: f64,
+                     label: Option<&str>,
                      continuous: bool, cb: SliderCb) -> ItemId {0}
 
     /// Update the current position of a slider

diff --git a/src/touchbar.rs b/src/touchbar.rs
line changes: +6/-0
index a0ed5c4..1f14c9d
--- a/src/touchbar.rs
+++ b/src/touchbar.rs
@@ -715,6 +715,7 @@ impl TTouchbar for Touchbar {
     }
 
     fn create_slider(&mut self, min: f64, max: f64,
+                     label: Option<&str>,
                      continuous: bool, cb: SliderCb) -> ItemId {
         unsafe {
             let ident = self.generate_ident();
@@ -722,6 +723,11 @@ impl TTouchbar for Touchbar {
             let item: *mut Object = msg_send![cls, alloc];
             let item: *mut Object = msg_send![item, initWithIdentifier: ident];
             let slider: *mut Object = msg_send![item, slider];
+            if let Some(label) = label {
+                let objc_text: *mut Object = NSString::alloc(nil).init_str(label);
+                msg_send![item, setLabel: objc_text];
+                msg_send![objc_text, release];
+            }
             msg_send![slider, setMinValue: min];
             msg_send![slider, setMaxValue: max];
             msg_send![slider, setContinuous: continuous];