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 a3e846df4871fa0a121bc8abdca69b9f941c5878..95f36cf02d027070e65f14699546db5f6996c05d 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 177e51bcdb20019a982f5750100590dcb1a923da..456fc207fe98260b4f971154f9260fad685fc563 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 1a9c3238a97feb95f25fab23e88163252e072518..4bb129449eb9457544ff671f9325b32f3dc450c9 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()