add iconPosition property to touch bar buttons

This commit is contained in:
Samuel Attard 2017-04-17 12:26:33 +12:00 committed by Kevin Sawicki
parent 4d9977dac1
commit 11c7c107a9
3 changed files with 12 additions and 1 deletions

View file

@ -307,9 +307,18 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
settings.Get("label", &label); settings.Get("label", &label);
button.title = base::SysUTF8ToNSString(label); button.title = base::SysUTF8ToNSString(label);
std::string iconPosition = "left";
settings.Get("iconPosition", &iconPosition);
gfx::Image image; gfx::Image image;
if (settings.Get("icon", &image)) { if (settings.Get("icon", &image)) {
button.image = image.AsNSImage(); button.image = image.AsNSImage();
if (iconPosition == "overlay") {
button.imagePosition = NSImageOverlaps;
} else if (iconPosition == "right") {
button.imagePosition = NSImageRight;
} else {
button.imagePosition = NSImageLeft;
}
} }
} }

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()