add iconPosition property to touch bar buttons
authorSamuel Attard <samuel.r.attard@gmail.com>
Mon, 17 Apr 2017 00:26:33 +0000 (12:26 +1200)
committerKevin Sawicki <kevinsawicki@gmail.com>
Tue, 18 Apr 2017 15:56:39 +0000 (08:56 -0700)
atom/browser/ui/cocoa/atom_touch_bar.mm
docs/api/touch-bar-button.md
lib/browser/api/touch-bar.js

index a3e846d..95f36cf 100644 (file)
@@ -307,9 +307,18 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
   settings.Get("label", &label);
   button.title = base::SysUTF8ToNSString(label);
 
+  std::string iconPosition = "left";
+  settings.Get("iconPosition", &iconPosition);
   gfx::Image image;
   if (settings.Get("icon", &image)) {
     button.image = image.AsNSImage();
+    if (iconPosition == "overlay") {
+        button.imagePosition = NSImageOverlaps;
+    } else if (iconPosition == "right") {
+        button.imagePosition = NSImageRight;
+    } else {
+        button.imagePosition = NSImageLeft;
+    }
   }
 }
 
index 177e51b..456fc20 100644 (file)
@@ -11,6 +11,7 @@ Process: [Main](../tutorial/quick-start.md#main-process)
   * `backgroundColor` String (optional) - Button background color in hex format,
     i.e `#ABCDEF`.
   * `icon` [NativeImage](native-image.md) (optional) - Button icon.
+  * `iconPosition` String - Can be `left`, `right` or `overlay`.
   * `click` Function (optional) - Function to call when the button is clicked.
 
 ### Instance Properties
index 1a9c323..4bb1294 100644 (file)
@@ -159,10 +159,11 @@ TouchBar.TouchBarButton = class TouchBarButton extends TouchBarItem {
     super()
     if (config == null) config = {}
     this.type = 'button'
-    const {click, icon, label, backgroundColor} = config
+    const {click, icon, iconPosition, label, backgroundColor} = config
     this._addLiveProperty('label', label)
     this._addLiveProperty('backgroundColor', backgroundColor)
     this._addLiveProperty('icon', icon)
+    this._addLiveProperty('iconPosition', iconPosition)
     if (typeof click === 'function') {
       this.onInteraction = () => {
         config.click()