Add more options

This commit is contained in:
Samuel Attard 2017-03-14 18:57:57 +11:00
parent 5e70adb511
commit a55cddaa53
No known key found for this signature in database
GPG key ID: E89DDE5742D58C4E
3 changed files with 85 additions and 3 deletions

View file

@ -515,7 +515,6 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
scrubber.delegate = self;
scrubber.dataSource = self;
scrubber.identifier = id;
scrubber.mode = NSScrubberModeFree;
[item setView:scrubber];
[self updateScrubber:item withSettings:settings];
@ -526,6 +525,44 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
- (void)updateScrubber:(NSCustomTouchBarItem*)item
withSettings:(const mate::PersistentDictionary&)settings {
NSScrubber* scrubber = item.view;
bool showsArrowButtons = false;
settings.Get("showArrowButtons", &showsArrowButtons);
scrubber.showsArrowButtons = showsArrowButtons;
std::string selectedStyle;
std::string overlayStyle;
settings.Get("selectedStyle", &selectedStyle);
settings.Get("overlayStyle", &overlayStyle);
if (selectedStyle == "outline") {
scrubber.selectionBackgroundStyle = [NSScrubberSelectionStyle outlineOverlayStyle];
} else if (selectedStyle == "background") {
scrubber.selectionBackgroundStyle = [NSScrubberSelectionStyle roundedBackgroundStyle];
} else {
scrubber.selectionBackgroundStyle = nil;
}
if (overlayStyle == "outline") {
scrubber.selectionOverlayStyle = [NSScrubberSelectionStyle outlineOverlayStyle];
} else if (overlayStyle == "background") {
scrubber.selectionOverlayStyle = [NSScrubberSelectionStyle roundedBackgroundStyle];
} else {
scrubber.selectionOverlayStyle = nil;
}
std::string mode;
settings.Get("mode", &mode);
if (mode == "fixed") {
scrubber.mode = NSScrubberModeFixed;
} else {
scrubber.mode = NSScrubberModeFree;
}
bool continuous = true;
settings.Get("continuous", &continuous);
scrubber.continuous = continuous;
[scrubber reloadData];
}
@ -546,7 +583,10 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
mate::PersistentDictionary settings = settings_[s_id];
std::vector<mate::PersistentDictionary> items;
settings.Get("items", &items);
if (!settings.Get("items", &items)) return nil;
if ((long)index >= (long)items.size()) return nil;
mate::PersistentDictionary item = items[index];
NSScrubberItemView* itemView;

View file

@ -21,3 +21,40 @@ The following properties are available on instances of `TouchBarScrubber`:
A `ScrubberItem[]` array representing the items in this scrubber. Updating this value immediately
updates the control in the touch bar. Updating deep properties inside this array **does not update the touch bar**.
#### `touchBarSegmentedControl.selectedStyle`
A `String` representing the style that selected items in the scrubber should have. Updating this value immediately
updates the control in the touch bar. Possible values:
* `background` - Maps to `[NSScrubberSelectionStyle roundedBackgroundStyle]`
* `outline` - Maps to `[NSScrubberSelectionStyle outlineOverlayStyle]`
* `null` - Actually null, not a string, removes all styles
#### `touchBarSegmentedControl.overlayStyle`
A `String` retpresenting the style that selected items in the scrubber should have. This style is overlayed on top
of the scrubber item instead of being placed behind it Updating this value immediately updates the control in the
touch bar. Possible values:
* `background` - Maps to `[NSScrubberSelectionStyle roundedBackgroundStyle]`
* `outline` - Maps to `[NSScrubberSelectionStyle outlineOverlayStyle]`
* `null` - Actually null, not a string, removes all styles
#### `touchBarSegmentedControl.showArrowButtons`
A `Boolean` representing whether to show the left / right selection arrows in this scrubber. Updating this value
immediately updates the control in the touch bar.
#### `touchBarSegmentedControl.mode`
A `String` representing the mode of this scrubber. Updating this value immediately
updates the control in the touch bar. Possible values:
* `fixed` - Maps to `NSScrubberModeFixed`
* `free` - Maps to `NSScrubberModeFree`
#### `touchBarSegmentedControl.continuous`
A `Boolean` representing whether this scrubber is continous or not. Updating this value immediately
updates the control in the touch bar.

View file

@ -236,9 +236,14 @@ TouchBar.TouchBarScrubber = class TouchBarScrubber extends TouchBarItem {
super()
if (config == null) config = {}
const {items} = config
let {onSelect, onHighlight} = config
let {onSelect, onHighlight, selectedStyle, highlightedStyle, showArrowButtons, continuous, mode} = config
this.type = 'scrubber'
this._addLiveProperty('items', items)
this._addLiveProperty('selectedStyle', selectedStyle || null)
this._addLiveProperty('overlayStyle', highlightedStyle || null)
this._addLiveProperty('showArrowButtons', showArrowButtons || false)
this._addLiveProperty('mode', mode || 'free')
this._addLiveProperty('continuous', continuous || true)
if (typeof onSelect === 'function' || typeof onHighlight === 'function') {
if (onSelect == null) onSelect = () => {}