X Tutup
Skip to content

Commit a55cdda

Browse files
Add more options
1 parent 5e70adb commit a55cdda

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

atom/browser/ui/cocoa/atom_touch_bar.mm

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,6 @@ - (NSTouchBarItem*)makeScrubberForID:(NSString*)id
515515
scrubber.delegate = self;
516516
scrubber.dataSource = self;
517517
scrubber.identifier = id;
518-
scrubber.mode = NSScrubberModeFree;
519518

520519
[item setView:scrubber];
521520
[self updateScrubber:item withSettings:settings];
@@ -526,6 +525,44 @@ - (NSTouchBarItem*)makeScrubberForID:(NSString*)id
526525
- (void)updateScrubber:(NSCustomTouchBarItem*)item
527526
withSettings:(const mate::PersistentDictionary&)settings {
528527
NSScrubber* scrubber = item.view;
528+
529+
bool showsArrowButtons = false;
530+
settings.Get("showArrowButtons", &showsArrowButtons);
531+
scrubber.showsArrowButtons = showsArrowButtons;
532+
533+
std::string selectedStyle;
534+
std::string overlayStyle;
535+
settings.Get("selectedStyle", &selectedStyle);
536+
settings.Get("overlayStyle", &overlayStyle);
537+
538+
if (selectedStyle == "outline") {
539+
scrubber.selectionBackgroundStyle = [NSScrubberSelectionStyle outlineOverlayStyle];
540+
} else if (selectedStyle == "background") {
541+
scrubber.selectionBackgroundStyle = [NSScrubberSelectionStyle roundedBackgroundStyle];
542+
} else {
543+
scrubber.selectionBackgroundStyle = nil;
544+
}
545+
546+
if (overlayStyle == "outline") {
547+
scrubber.selectionOverlayStyle = [NSScrubberSelectionStyle outlineOverlayStyle];
548+
} else if (overlayStyle == "background") {
549+
scrubber.selectionOverlayStyle = [NSScrubberSelectionStyle roundedBackgroundStyle];
550+
} else {
551+
scrubber.selectionOverlayStyle = nil;
552+
}
553+
554+
std::string mode;
555+
settings.Get("mode", &mode);
556+
if (mode == "fixed") {
557+
scrubber.mode = NSScrubberModeFixed;
558+
} else {
559+
scrubber.mode = NSScrubberModeFree;
560+
}
561+
562+
bool continuous = true;
563+
settings.Get("continuous", &continuous);
564+
scrubber.continuous = continuous;
565+
529566
[scrubber reloadData];
530567
}
531568

@@ -546,7 +583,10 @@ - (NSScrubberItemView*)scrubber:(NSScrubber*)scrubber
546583

547584
mate::PersistentDictionary settings = settings_[s_id];
548585
std::vector<mate::PersistentDictionary> items;
549-
settings.Get("items", &items);
586+
if (!settings.Get("items", &items)) return nil;
587+
588+
if ((long)index >= (long)items.size()) return nil;
589+
550590
mate::PersistentDictionary item = items[index];
551591

552592
NSScrubberItemView* itemView;

docs/api/touch-bar-scrubber.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,40 @@ The following properties are available on instances of `TouchBarScrubber`:
2121

2222
A `ScrubberItem[]` array representing the items in this scrubber. Updating this value immediately
2323
updates the control in the touch bar. Updating deep properties inside this array **does not update the touch bar**.
24+
25+
#### `touchBarSegmentedControl.selectedStyle`
26+
27+
A `String` representing the style that selected items in the scrubber should have. Updating this value immediately
28+
updates the control in the touch bar. Possible values:
29+
30+
* `background` - Maps to `[NSScrubberSelectionStyle roundedBackgroundStyle]`
31+
* `outline` - Maps to `[NSScrubberSelectionStyle outlineOverlayStyle]`
32+
* `null` - Actually null, not a string, removes all styles
33+
34+
#### `touchBarSegmentedControl.overlayStyle`
35+
36+
A `String` retpresenting the style that selected items in the scrubber should have. This style is overlayed on top
37+
of the scrubber item instead of being placed behind it Updating this value immediately updates the control in the
38+
touch bar. Possible values:
39+
40+
* `background` - Maps to `[NSScrubberSelectionStyle roundedBackgroundStyle]`
41+
* `outline` - Maps to `[NSScrubberSelectionStyle outlineOverlayStyle]`
42+
* `null` - Actually null, not a string, removes all styles
43+
44+
#### `touchBarSegmentedControl.showArrowButtons`
45+
46+
A `Boolean` representing whether to show the left / right selection arrows in this scrubber. Updating this value
47+
immediately updates the control in the touch bar.
48+
49+
#### `touchBarSegmentedControl.mode`
50+
51+
A `String` representing the mode of this scrubber. Updating this value immediately
52+
updates the control in the touch bar. Possible values:
53+
54+
* `fixed` - Maps to `NSScrubberModeFixed`
55+
* `free` - Maps to `NSScrubberModeFree`
56+
57+
#### `touchBarSegmentedControl.continuous`
58+
59+
A `Boolean` representing whether this scrubber is continous or not. Updating this value immediately
60+
updates the control in the touch bar.

lib/browser/api/touch-bar.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,14 @@ TouchBar.TouchBarScrubber = class TouchBarScrubber extends TouchBarItem {
236236
super()
237237
if (config == null) config = {}
238238
const {items} = config
239-
let {onSelect, onHighlight} = config
239+
let {onSelect, onHighlight, selectedStyle, highlightedStyle, showArrowButtons, continuous, mode} = config
240240
this.type = 'scrubber'
241241
this._addLiveProperty('items', items)
242+
this._addLiveProperty('selectedStyle', selectedStyle || null)
243+
this._addLiveProperty('overlayStyle', highlightedStyle || null)
244+
this._addLiveProperty('showArrowButtons', showArrowButtons || false)
245+
this._addLiveProperty('mode', mode || 'free')
246+
this._addLiveProperty('continuous', continuous || true)
242247

243248
if (typeof onSelect === 'function' || typeof onHighlight === 'function') {
244249
if (onSelect == null) onSelect = () => {}

0 commit comments

Comments
 (0)
X Tutup