0

我想TouchBarSlider根据我将其移动到的位置来显示值。TouchBar可以在此处遵循的示例示例。我仍然无法弄清楚如何使用他们给定的方法changeTouchBarSlider.

我的电流main.js如下所示。

const {app, BrowserWindow, TouchBar} = require('electron')

const {TouchBarLabel, TouchBarSlider} = TouchBar
const slider = new TouchBarSlider({label: 'angle',
                                   minValue: 0,
                                   maxValue: 360})
const result = new TouchBarLabel()
result.label = '30' + ' deg'; 

const updateBar = () => {
  let timeout = 100;
  if (slider.change()){
    result.label = slider.values.toString() + ' deg'
  }
  setTimeout(updateBar, timeout)
}

const touchBar = new TouchBar([
  slider, // add slider
  result // add display for slider value but doesn't work yet
])

let window;

app.once('ready', () => {
  window = new BrowserWindow({
    width: 300,
    height: 200
  });
  window.loadURL('about:blank')
  window.setTouchBar(touchBar);
})

// Quit when all windows are closed and no other one is listening to this.
app.on('window-all-closed', () => {
    app.quit();
});

我这里也有示例存储库。您可以替换我main.js在项目中给定的内容以进行尝试。我的电子版是1.6.4节点版是7.4.0

4

1 回答 1

1
const { app, BrowserWindow, TouchBar } = require('electron');
const path = require('path')
const url = require('url')

const {TouchBarButton, TouchBarLabel, TouchBarSlider} = TouchBar

const result = new TouchBarLabel();
result.label = '30' + ' deg';

const slider = new TouchBarSlider({
                               label: 'angle',
                               minValue: 0,
                               maxValue: 360,
                               change: (val) => result.label = val.toString() + ' deg' // register event handler here!
                              });

const touchBar = new TouchBar([
  slider, // add slider
  result // add display for slider value
]);

let window;

app.once('ready', () => {
  window = new BrowserWindow({
  width: 300,
  height: 200
 });
  window.loadURL('about:blank');
  window.setTouchBar(touchBar);
});

// Quit when all windows are closed and no other one is listening to this.
app.on('window-all-closed', () => {
  app.quit();
});

工作代码。希望这可以帮助!;)

于 2017-03-28T09:28:12.563 回答