Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom factor #237

Merged
merged 5 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
19 changes: 12 additions & 7 deletions components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class App extends Component {
busy: false,
fullScreen: false,
showMenuBar: null,
zoomFactor: null,

representedFilename: null,
gameTrees: [emptyTree],
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -654,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
}
Expand Down Expand Up @@ -1767,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 = {}) {
Expand Down Expand Up @@ -1851,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
Expand Down Expand Up @@ -2080,7 +2085,7 @@ class App extends Component {
this.stopGeneratingMoves()
this.hideInfoOverlay()
this.makeResign()

return
}

Expand Down
3 changes: 1 addition & 2 deletions components/bars/PlayBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
30 changes: 7 additions & 23 deletions components/drawers/GameChooserDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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)
}
}

Expand Down
7 changes: 1 addition & 6 deletions components/drawers/InfoDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
25 changes: 25 additions & 0 deletions data/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
]
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function newWindow(path) {
backgroundColor: '#111111',
show: false,
webPreferences: {
zoomFactor: setting.get('debug.zoom_factor')
zoomFactor: setting.get('app.zoom_factor')
}
})

Expand Down
6 changes: 3 additions & 3 deletions modules/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down
12 changes: 12 additions & 0 deletions modules/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(remote.getCurrentWindow(), {
x: Math.round(x * zoomFactor),
y: Math.round(y * zoomFactor),
async: true
})
}
2 changes: 1 addition & 1 deletion modules/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down