From 2680ee9f8f6a3201c19d359a3f53fb11ad5b9ecc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 3 Mar 2017 15:14:51 -0800 Subject: [PATCH] Add support for setting TouchBarLabel text color --- atom/browser/ui/cocoa/atom_touch_bar.mm | 10 +++++++++- docs/api/touch-bar-label.md | 6 ++++++ docs/api/touch-bar.md | 5 +++++ lib/browser/api/touch-bar.js | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/atom/browser/ui/cocoa/atom_touch_bar.mm b/atom/browser/ui/cocoa/atom_touch_bar.mm index 9f006bf7dfda..0ce674bcb918 100644 --- a/atom/browser/ui/cocoa/atom_touch_bar.mm +++ b/atom/browser/ui/cocoa/atom_touch_bar.mm @@ -247,10 +247,18 @@ static NSTouchBarItemIdentifier SliderIdentifier = @"com.electron.touchbar.slide - (void)updateLabel:(NSCustomTouchBarItem*)item withSettings:(const mate::PersistentDictionary&)settings { + NSTextField* text_field = (NSTextField*)item.view; + std::string label; settings.Get("label", &label); - NSTextField* text_field = (NSTextField*)item.view; text_field.stringValue = base::SysUTF8ToNSString(label); + + std::string textColor; + if (settings.Get("textColor", &textColor) && !textColor.empty()) { + text_field.textColor = [self colorFromHexColorString:textColor]; + } else { + text_field.textColor = nil; + } } - (NSTouchBarItem*)makeColorPickerForID:(NSString*)id diff --git a/docs/api/touch-bar-label.md b/docs/api/touch-bar-label.md index 7d0137c35aad..4caecb6a46a3 100644 --- a/docs/api/touch-bar-label.md +++ b/docs/api/touch-bar-label.md @@ -8,6 +8,7 @@ Process: [Main](../tutorial/quick-start.md#main-process) * `options` Object * `label` String (optional) - Text to display. + * `textColor` String (optional) - Hex color of text, i.e `#ABCDEF`. ### Instance Properties @@ -17,3 +18,8 @@ The following properties are available on instances of `TouchBarLabel`: The label's current text. Changing this value immediately updates the label in the touch bar. + +#### `touchBarLabel.textColor` + +The label's current text color. Changing this value immediately updates the +label in the touch bar. diff --git a/docs/api/touch-bar.md b/docs/api/touch-bar.md index fa62b8dc6cc2..2ca8c1ef32b6 100644 --- a/docs/api/touch-bar.md +++ b/docs/api/touch-bar.md @@ -80,12 +80,15 @@ const finishSpin = () => { if (uniqueValues === 1) { // All 3 values are the same result.label = '💰 Jackpot!' + result.textColor = '#FDFF00' } else if (uniqueValues === 2) { // 2 values are the same result.label = '😍 Winner!' + result.textColor = '#FDFF00' } else { // No values are the same result.label = '🙁 Spin Again' + result.textColor = null } spinning = false } @@ -94,7 +97,9 @@ const touchBar = new TouchBar([ spin, new TouchBarSpacer({size: 'large'}), reel1, + new TouchBarSpacer({size: 'small'}), reel2, + new TouchBarSpacer({size: 'small'}), reel3, new TouchBarSpacer({size: 'large'}), result diff --git a/lib/browser/api/touch-bar.js b/lib/browser/api/touch-bar.js index d4c8c5c44c28..ee7388f17756 100644 --- a/lib/browser/api/touch-bar.js +++ b/lib/browser/api/touch-bar.js @@ -164,6 +164,7 @@ TouchBar.TouchBarLabel = class TouchBarLabel extends TouchBarItem { if (config == null) config = {} this.type = 'label' this._addLiveProperty('label', config.label) + this._addLiveProperty('textColor', config.textColor) } }