From c4d6a37270eef37eb828318b172a01889e000b26 Mon Sep 17 00:00:00 2001 From: Yichuan Shen Date: Mon, 22 May 2017 14:51:45 +0200 Subject: [PATCH 1/5] Add menu items to change zoom factor --- components/App.js | 10 +++++++++- data/menu.js | 25 +++++++++++++++++++++++++ main.js | 2 +- modules/setting.js | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/components/App.js b/components/App.js index 6f12c493a..843a05add 100644 --- a/components/App.js +++ b/components/App.js @@ -40,6 +40,7 @@ class App extends Component { busy: false, fullScreen: false, showMenuBar: null, + zoomFactor: null, representedFilename: null, gameTrees: [emptyTree], @@ -287,10 +288,17 @@ class App extends Component { this.window.setContentSize(width + widthDiff, height) } + + // Handle zoom factor + + if (prevState.zoomFactor !== this.state.zoomFactor) { + this.window.webContents.setZoomFactor(this.state.zoomFactor) + } } updateSettingState(key = null) { let data = { + 'app.zoom_factor': 'zoomFactor', 'view.show_menubar': 'showMenuBar', 'view.show_coordinates': 'showCoordinates', 'view.show_move_colorization': 'showMoveColorization', @@ -2080,7 +2088,7 @@ class App extends Component { this.stopGeneratingMoves() this.hideInfoOverlay() this.makeResign() - + return } diff --git a/data/menu.js b/data/menu.js index 9d522b968..e250fcc29 100644 --- a/data/menu.js +++ b/data/menu.js @@ -433,6 +433,31 @@ let data = [ checked: 'view.show_comments', accelerator: 'CmdOrCtrl+Shift+T', click: () => toggleSetting('view.show_comments') + }, + {type: 'separator'}, + { + label: 'Z&oom Factor', + submenu: [ + { + label: 'Increase', + accelerator: 'CmdOrCtrl+Plus', + click: () => setting.set('app.zoom_factor', + setting.get('app.zoom_factor') + .1 + ) + }, + { + label: 'Decrease', + accelerator: 'CmdOrCtrl+-', + click: () => setting.set('app.zoom_factor', + Math.max(0, setting.get('app.zoom_factor') - .1) + ) + }, + { + label: 'Reset', + accelerator: 'CmdOrCtrl+0', + click: () => setting.set('app.zoom_factor', 1) + } + ] } ] }, diff --git a/main.js b/main.js index 46edf5c16..5becb9adb 100644 --- a/main.js +++ b/main.js @@ -20,7 +20,7 @@ function newWindow(path) { backgroundColor: '#111111', show: false, webPreferences: { - zoomFactor: setting.get('debug.zoom_factor') + zoomFactor: setting.get('app.zoom_factor') } }) diff --git a/modules/setting.js b/modules/setting.js index 5b049dc08..87f6f1689 100644 --- a/modules/setting.js +++ b/modules/setting.js @@ -30,6 +30,7 @@ let defaults = { 'app.startup_check_updates_delay': 3000, 'app.loadgame_delay': 100, 'app.hide_busy_delay': 200, + 'app.zoom_factor': 1, 'autoplay.sec_per_move': 1, 'autoscroll.max_interval': 200, 'autoscroll.min_interval': 50, @@ -53,7 +54,6 @@ let defaults = { ], 'console.max_history_count': 100, 'debug.dev_tools': false, - 'debug.zoom_factor': 1.0, 'edit.click_currentvertex_to_remove': true, 'edit.show_removenode_warning': true, 'edit.show_removeothervariations_warning': true, From c4ab9501e3755bf374cc50c126fd8032d99bee28 Mon Sep 17 00:00:00 2001 From: Yichuan Shen Date: Mon, 22 May 2017 15:10:49 +0200 Subject: [PATCH 2/5] Add helper.popupMenu() to fix menu positions with zoom factor --- modules/helper.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/helper.js b/modules/helper.js index 09d9678e2..526a5f6d0 100644 --- a/modules/helper.js +++ b/modules/helper.js @@ -109,3 +109,15 @@ exports.htmlify = function(input) { return input } + +exports.popupMenu = function(template, x, y) { + let {remote} = require('electron') + let setting = remote.require('./modules/setting') + let zoomFactor = +setting.get('app.zoom_factor') + + remote.Menu.buildFromTemplate(template).popup(sabaki.window, { + x: Math.round(x * zoomFactor), + y: Math.round(y * zoomFactor), + async: true + }) +} From 00e844a91e7f7d2d6c1809292aa283538a26bad2 Mon Sep 17 00:00:00 2001 From: Yichuan Shen Date: Mon, 22 May 2017 15:11:17 +0200 Subject: [PATCH 3/5] Use helper.popupMenu() instead of menu.popup() --- components/App.js | 9 +++----- components/bars/PlayBar.js | 3 +-- components/drawers/GameChooserDrawer.js | 30 ++++++------------------- components/drawers/InfoDrawer.js | 7 +----- 4 files changed, 12 insertions(+), 37 deletions(-) diff --git a/components/App.js b/components/App.js index 843a05add..add8d0be7 100644 --- a/components/App.js +++ b/components/App.js @@ -662,8 +662,7 @@ class App extends Component { }) let template = [{label: '&Edit Label', click}] - let menu = Menu.buildFromTemplate(template) - menu.popup(this.window, {x, y, async: true}) + helper.popupMenu(template, x, y) return } @@ -1775,8 +1774,7 @@ class App extends Component { } ] - let menu = Menu.buildFromTemplate(template) - menu.popup(this.window, Object.assign({async: true}, options)) + helper.popupMenu(template, options.x, options.y) } openCommentMenu(tree, index, options = {}) { @@ -1859,8 +1857,7 @@ class App extends Component { item.click = () => this.setComment(tree, index, item.data) } - let menu = Menu.buildFromTemplate(template) - menu.popup(this.window, Object.assign({async: true}, options)) + helper.popupMenu(template, options.x, options.y) } // GTP Engines diff --git a/components/bars/PlayBar.js b/components/bars/PlayBar.js index 06e3ff7d5..618f155c4 100644 --- a/components/bars/PlayBar.js +++ b/components/bars/PlayBar.js @@ -45,9 +45,8 @@ class PlayBar extends Component { } ] - let menu = Menu.buildFromTemplate(template) let {left, top} = this.menuButtonElement.getBoundingClientRect() - menu.popup(sabaki.window, {x: Math.round(left), y: Math.round(top), async: true}) + helper.popupMenu(template, left, top) } } diff --git a/components/drawers/GameChooserDrawer.js b/components/drawers/GameChooserDrawer.js index 03cff205c..bd5deae17 100644 --- a/components/drawers/GameChooserDrawer.js +++ b/components/drawers/GameChooserDrawer.js @@ -140,13 +140,7 @@ class GameChooserDrawer extends Component { } ] - let menu = Menu.buildFromTemplate(template) - - menu.popup(sabaki.window, { - x: evt.clientX, - y: evt.clientY, - async: true - }) + helper.popupMenu(template, evt.clientX, evt.clientY) } this.handleItemDragStart = evt => { @@ -247,14 +241,9 @@ class GameChooserDrawer extends Component { ] let element = evt.currentTarget - let {left, top, height} = element.getBoundingClientRect() - let menu = Menu.buildFromTemplate(template) - - menu.popup(sabaki.window, { - x: Math.round(left), - y: Math.round(top + height), - async: true - }) + let {left, bottom} = element.getBoundingClientRect() + + helper.popupMenu(template, left, bottom) } this.handleSortButtonClick = evt => { @@ -317,14 +306,9 @@ class GameChooserDrawer extends Component { } let element = evt.currentTarget - let {left, top, height} = element.getBoundingClientRect() - let menu = Menu.buildFromTemplate(template) - - menu.popup(sabaki.window, { - x: Math.round(left), - y: Math.round(top + height), - async: true - }) + let {left, bottom} = element.getBoundingClientRect() + + helper.popupMenu(template, left, bottom) } } diff --git a/components/drawers/InfoDrawer.js b/components/drawers/InfoDrawer.js index 1595eef38..50188bccc 100644 --- a/components/drawers/InfoDrawer.js +++ b/components/drawers/InfoDrawer.js @@ -171,13 +171,8 @@ class InfoDrawer extends Component { ].filter(x => !!x) let {left, bottom} = evt.currentTarget.getBoundingClientRect() - let menu = Menu.buildFromTemplate(template) - menu.popup(sabaki.window, { - async: true, - x: Math.round(left), - y: Math.round(bottom) - }) + helper.popupMenu(template, left, bottom) }) } From 558d95d09b0afc404d99d5eb1195eb944ae05b4c Mon Sep 17 00:00:00 2001 From: Yichuan Shen Date: Mon, 22 May 2017 16:08:08 +0200 Subject: [PATCH 4/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d868c3be..362499009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. **Added** * Themes (Thanks to [@Seth-Rothschild](https://github.com/Seth-Rothschild)) +* Ability to adjust UI zoom **Changed** From 63a4e89e3ceaa3a6e987efdfb76a032c845c0b40 Mon Sep 17 00:00:00 2001 From: Yichuan Shen Date: Mon, 22 May 2017 21:32:07 +0200 Subject: [PATCH 5/5] Use remote.getCurrentWindow() instead of sabaki.window --- modules/dialog.js | 6 +++--- modules/helper.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/dialog.js b/modules/dialog.js index aeeea0ff7..b59b40167 100644 --- a/modules/dialog.js +++ b/modules/dialog.js @@ -5,10 +5,10 @@ const helper = require('./helper') exports.showMessageBox = function(message, type = 'info', buttons = ['OK'], cancelId = 0) { sabaki.setBusy(true) - let result = dialog.showMessageBox(sabaki.window, { + let result = dialog.showMessageBox(remote.getCurrentWindow(), { type, buttons, - title: sabaki.appName, + title: app.getName(), message, cancelId, noLink: true @@ -24,7 +24,7 @@ exports.showFileDialog = function(type, options, callback = helper.noop) { let [t, ...ype] = [...type] type = t.toUpperCase() + ype.join('').toLowerCase() - let result = dialog[`show${type}Dialog`](sabaki.window, options) + let result = dialog[`show${type}Dialog`](remote.getCurrentWindow(), options) sabaki.setBusy(false) callback({result}) diff --git a/modules/helper.js b/modules/helper.js index 526a5f6d0..39eb3b823 100644 --- a/modules/helper.js +++ b/modules/helper.js @@ -115,7 +115,7 @@ exports.popupMenu = function(template, x, y) { let setting = remote.require('./modules/setting') let zoomFactor = +setting.get('app.zoom_factor') - remote.Menu.buildFromTemplate(template).popup(sabaki.window, { + remote.Menu.buildFromTemplate(template).popup(remote.getCurrentWindow(), { x: Math.round(x * zoomFactor), y: Math.round(y * zoomFactor), async: true