Merge pull request #9208 from electron/touchbar-button-icon-pos

Add iconPosition property to touch bar buttons
This commit is contained in:
Kevin Sawicki 2017-04-18 12:02:44 -04:00 committed by GitHub
commit 190fc46e77
4 changed files with 19 additions and 1 deletions

View file

@ -310,6 +310,16 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
gfx::Image image; gfx::Image image;
if (settings.Get("icon", &image)) { if (settings.Get("icon", &image)) {
button.image = image.AsNSImage(); button.image = image.AsNSImage();
std::string iconPosition;
settings.Get("iconPosition", &iconPosition);
if (iconPosition == "left") {
button.imagePosition = NSImageLeft;
} else if (iconPosition == "right") {
button.imagePosition = NSImageRight;
} else {
button.imagePosition = NSImageOverlaps;
}
} }
} }

View file

@ -11,6 +11,7 @@ Process: [Main](../tutorial/quick-start.md#main-process)
* `backgroundColor` String (optional) - Button background color in hex format, * `backgroundColor` String (optional) - Button background color in hex format,
i.e `#ABCDEF`. i.e `#ABCDEF`.
* `icon` [NativeImage](native-image.md) (optional) - Button icon. * `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. * `click` Function (optional) - Function to call when the button is clicked.
### Instance Properties ### Instance Properties

View file

@ -159,10 +159,11 @@ TouchBar.TouchBarButton = class TouchBarButton extends TouchBarItem {
super() super()
if (config == null) config = {} if (config == null) config = {}
this.type = 'button' this.type = 'button'
const {click, icon, label, backgroundColor} = config const {click, icon, iconPosition, label, backgroundColor} = config
this._addLiveProperty('label', label) this._addLiveProperty('label', label)
this._addLiveProperty('backgroundColor', backgroundColor) this._addLiveProperty('backgroundColor', backgroundColor)
this._addLiveProperty('icon', icon) this._addLiveProperty('icon', icon)
this._addLiveProperty('iconPosition', iconPosition)
if (typeof click === 'function') { if (typeof click === 'function') {
this.onInteraction = () => { this.onInteraction = () => {
config.click() config.click()

View file

@ -1,4 +1,5 @@
const assert = require('assert') const assert = require('assert')
const path = require('path')
const {BrowserWindow, TouchBar} = require('electron').remote const {BrowserWindow, TouchBar} = require('electron').remote
const {closeWindow} = require('./window-helpers') const {closeWindow} = require('./window-helpers')
@ -48,6 +49,11 @@ describe('TouchBar module', function () {
const label = new TouchBarLabel({label: 'bar'}) const label = new TouchBarLabel({label: 'bar'})
const touchBar = new TouchBar([ const touchBar = new TouchBar([
new TouchBarButton({label: 'foo', backgroundColor: '#F00', click: () => {}}), new TouchBarButton({label: 'foo', backgroundColor: '#F00', click: () => {}}),
new TouchBarButton({
icon: path.join(__dirname, 'fixtures', 'assets', 'logo.png'),
iconPosition: 'right',
click: () => {}
}),
new TouchBarColorPicker({selectedColor: '#F00', change: () => {}}), new TouchBarColorPicker({selectedColor: '#F00', change: () => {}}),
new TouchBarGroup({items: new TouchBar([new TouchBarLabel({label: 'hello'})])}), new TouchBarGroup({items: new TouchBar([new TouchBarLabel({label: 'hello'})])}),
label, label,