From 11c7c107a958f3de2bbb7f6df4f5340e8c40ef03 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Mon, 17 Apr 2017 12:26:33 +1200 Subject: [PATCH] add iconPosition property to touch bar buttons --- atom/browser/ui/cocoa/atom_touch_bar.mm | 9 +++++++++ docs/api/touch-bar-button.md | 1 + lib/browser/api/touch-bar.js | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/atom/browser/ui/cocoa/atom_touch_bar.mm b/atom/browser/ui/cocoa/atom_touch_bar.mm index a3e846df4871..95f36cf02d02 100644 --- a/atom/browser/ui/cocoa/atom_touch_bar.mm +++ b/atom/browser/ui/cocoa/atom_touch_bar.mm @@ -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; + } } } diff --git a/docs/api/touch-bar-button.md b/docs/api/touch-bar-button.md index 177e51bcdb20..456fc207fe98 100644 --- a/docs/api/touch-bar-button.md +++ b/docs/api/touch-bar-button.md @@ -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 diff --git a/lib/browser/api/touch-bar.js b/lib/browser/api/touch-bar.js index 1a9c3238a97f..4bb129449eb9 100644 --- a/lib/browser/api/touch-bar.js +++ b/lib/browser/api/touch-bar.js @@ -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()