uitoolbar pretty cool, contextmenu improvements, allow root containing normal widgets
This commit is contained in:
parent
e530e33900
commit
75be4b7d71
17 changed files with 332 additions and 343 deletions
|
|
@ -9,11 +9,10 @@ class ContextMenu extends UiWidget {
|
|||
|
||||
super(options)
|
||||
|
||||
if (!MENU_CONTAINER) MENU_CONTAINER = DOM.get('osc-modal-container')[0]
|
||||
if (!MENU_CONTAINER) MENU_CONTAINER = DOM.get('osc-workspace')[0]
|
||||
|
||||
|
||||
this.container = null
|
||||
MENU_CONTAINER = DOM.get('osc-workspace')[0]
|
||||
this.clickHandler = (e)=>{
|
||||
if (this.container && !this.container.contains(e.target)) this.close()
|
||||
}
|
||||
|
|
@ -32,7 +31,9 @@ class ContextMenu extends UiWidget {
|
|||
|
||||
} else if (Array.isArray(action.action)) {
|
||||
|
||||
let item = html`<div class="item has-sub" tabIndex="1">${raw(action.label)}</div>`
|
||||
let label = typeof action.label === 'function' ? action.label() : action.label,
|
||||
iclass = typeof action.class === 'function' ? action .class() : action.class,
|
||||
item = html`<div class="item has-sub ${iclass}" tabIndex="1">${raw(label)}</div>`
|
||||
|
||||
menu.appendChild(item)
|
||||
|
||||
|
|
@ -41,11 +42,13 @@ class ContextMenu extends UiWidget {
|
|||
|
||||
} else {
|
||||
|
||||
let item = html`<div class="item">${raw(action.label)}</div>`
|
||||
let label = typeof action.label === 'function' ? action.label() : action.label,
|
||||
iclass = typeof action.class === 'function' ? action.class() : action.class,
|
||||
item = html`<div class="item ${iclass}">${raw(label)}</div>`
|
||||
|
||||
menu.appendChild(item)
|
||||
|
||||
if (action.click) {
|
||||
// if (action.click) {
|
||||
|
||||
item.addEventListener('click', (e)=>{
|
||||
e.preventDefault()
|
||||
|
|
@ -53,15 +56,15 @@ class ContextMenu extends UiWidget {
|
|||
this.close()
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
item.addEventListener('fast-click', (e)=>{
|
||||
e.detail.preventOriginalEvent = true
|
||||
action.action()
|
||||
this.close()
|
||||
})
|
||||
|
||||
}
|
||||
// } else {
|
||||
//
|
||||
// item.addEventListener('fast-click', (e)=>{
|
||||
// e.detail.preventOriginalEvent = true
|
||||
// action.action()
|
||||
// this.close()
|
||||
// })
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -87,8 +90,8 @@ class ContextMenu extends UiWidget {
|
|||
})
|
||||
})
|
||||
|
||||
menu.style.top = e.pageY + 'px'
|
||||
menu.style.left = e.pageX + 'px'
|
||||
menu.style.top = e.pageY / PXSCALE + 'rem'
|
||||
menu.style.left = e.pageX / PXSCALE + 'rem'
|
||||
|
||||
this.correctPosition(menu)
|
||||
|
||||
|
|
@ -130,12 +133,16 @@ class ContextMenu extends UiWidget {
|
|||
totalHeight = MENU_CONTAINER.offsetHeight
|
||||
|
||||
if (width + position.left > totalWidth) {
|
||||
menu.style.right = parent ? '100%' : '0'
|
||||
menu.style.left = 'auto'
|
||||
menu.style.marginRight = '1rem'
|
||||
if (position.left - width > 0) {
|
||||
menu.style.right = parent ? '100%' : '0'
|
||||
menu.style.left = 'auto'
|
||||
menu.style.marginRight = '1rem'
|
||||
} else {
|
||||
menu.style.left = (parent.offsetWidth + (totalWidth - width - position.left)) / PXSCALE + 'rem'
|
||||
}
|
||||
}
|
||||
|
||||
if (height + position.top > totalHeight) {
|
||||
if (height + position.top > totalHeight && position.top - height > 0) {
|
||||
menu.style.top = 'auto'
|
||||
menu.style.bottom = '0rem'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ if (screenfull.isEnabled) {
|
|||
toggle(){
|
||||
|
||||
new UiModal({
|
||||
title: locales('fs_unnavailable'),
|
||||
content: locales('fs_addtohome'),
|
||||
title: locales('fullscreen_unnavailable'),
|
||||
content: locales('fullscreen_addtohome'),
|
||||
closable: true
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -192,27 +192,6 @@ var sidepanelData = [
|
|||
]
|
||||
|
||||
|
||||
if (navigator.userAgent.match(/Android|iPhone|iPad|iPod/i)) {
|
||||
|
||||
var NoSleep = require('nosleep.js'),
|
||||
noSleep = new NoSleep(),
|
||||
noSleepState = false
|
||||
|
||||
sidepanelData[0].actions.push({
|
||||
label: locales('sidepanel_nosleep'),
|
||||
class: 'toggle',
|
||||
action:(el)=>{
|
||||
noSleepState = el.classList.toggle('on')
|
||||
if (noSleepState) {
|
||||
noSleep.enable()
|
||||
} else {
|
||||
noSleep.disable()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
var options = html`<ul id="options"></ul>`
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
var html = require('nanohtml'),
|
||||
UiModal = require('./ui-modal')
|
||||
|
||||
class UiLobby {
|
||||
|
||||
constructor() {
|
||||
|
||||
this.state = 0
|
||||
|
||||
this.container = html`
|
||||
<div class="lobby">
|
||||
<div class="list"></div>
|
||||
<div class="footer"></div>
|
||||
</div>
|
||||
`
|
||||
|
||||
this.list = DOM.get(this.container, '.list')[0]
|
||||
this.footer = DOM.get(this.container, '.footer')[0]
|
||||
|
||||
this.modal = new UiModal({
|
||||
content: this.container,
|
||||
closable: false,
|
||||
title: `${PACKAGE.productName} v${PACKAGE.version}`
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
open() {
|
||||
|
||||
this.modal.open()
|
||||
|
||||
}
|
||||
|
||||
close() {
|
||||
|
||||
this.modal.close()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var uiLobby = new UiLobby()
|
||||
|
||||
module.exports = uiLobby
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
var UiWidget = require('./ui-widget')
|
||||
var UiWidget = require('./ui-widget'),
|
||||
locales = require('../locales')
|
||||
|
||||
class UiSidePanel extends UiWidget {
|
||||
|
||||
|
|
@ -6,6 +7,7 @@ class UiSidePanel extends UiWidget {
|
|||
|
||||
super(options)
|
||||
|
||||
DOM.get(this.container, 'osc-panel-header')[0].textContent = options.label
|
||||
this.resizeDirection = this.container.classList.contains('left') ? 1 : -1
|
||||
this.resizeHandle = DOM.get(this.container, '.resize-handle')[0]
|
||||
this.toggleButton = DOM.get(this.container, '.toggle-button')[0]
|
||||
|
|
@ -105,8 +107,8 @@ class UiSidePanel extends UiWidget {
|
|||
|
||||
}
|
||||
|
||||
var leftUiSidePanel = new UiSidePanel({selector: 'osc-panel-container.right'}),
|
||||
rightUiSidePanel = new UiSidePanel({selector: 'osc-panel-container.left'})
|
||||
var leftUiSidePanel = new UiSidePanel({selector: 'osc-panel-container.left', label: locales('editor_tree')}),
|
||||
rightUiSidePanel = new UiSidePanel({selector: 'osc-panel-container.right', label: locales('editor_inspector')})
|
||||
|
||||
module.exports = {
|
||||
left: leftUiSidePanel,
|
||||
|
|
|
|||
|
|
@ -3,87 +3,145 @@ var UiWidget = require('./ui-widget'),
|
|||
ContextMenu = require('./context-menu'),
|
||||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw'),
|
||||
{icon} = require('./utils')
|
||||
{icon} = require('./utils'),
|
||||
ipc = require('../ipc'),
|
||||
locales = require('../locales'),
|
||||
notifications = require('./notifications'),
|
||||
fullscreen = require('./fullscreen'),
|
||||
editor = require('../editor'),
|
||||
sessionManager = require('../managers/session'),
|
||||
stateManager = require('../managers/state'),
|
||||
uiSidePanel = require('./ui-sidepanel')
|
||||
|
||||
|
||||
var menu = [
|
||||
var recentSessions = []
|
||||
var menuEntries = [
|
||||
|
||||
{
|
||||
label: 'Session',
|
||||
label: locales('session'),
|
||||
action: [
|
||||
{
|
||||
label: 'new'
|
||||
label: locales('session_new'),
|
||||
action: sessionManager.create.bind(sessionManager)
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: 'open'
|
||||
label: locales('file_open'),
|
||||
action: sessionManager.browse.bind(sessionManager)
|
||||
},
|
||||
{
|
||||
label: 'save'
|
||||
},
|
||||
{
|
||||
label: 'save as'
|
||||
label: locales('file_open_recent'),
|
||||
action: recentSessions
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: 'import'
|
||||
label: locales('file_save'),
|
||||
action: sessionManager.save.bind(sessionManager)
|
||||
},
|
||||
{
|
||||
label: 'export'
|
||||
label: locales('file_save_as'),
|
||||
action: sessionManager.saveAs.bind(sessionManager)
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: locales('file_import'),
|
||||
action: sessionManager.import.bind(sessionManager)
|
||||
},
|
||||
{
|
||||
label: locales('file_export'),
|
||||
action: sessionManager.export.bind(sessionManager)
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'State',
|
||||
label: locales('state'),
|
||||
class: ()=>{return sessionManager.session === null ? 'disabled' : ''},
|
||||
action: [
|
||||
{
|
||||
label: 'store'
|
||||
label: locales('state_store'),
|
||||
action: stateManager.quickSave.bind(stateManager)
|
||||
},
|
||||
{
|
||||
label: 'recall'
|
||||
label: locales('state_recall'),
|
||||
class: ()=>{return stateManager.quickState === null ? 'disabled' : ''},
|
||||
action: stateManager.quickLoad.bind(stateManager)
|
||||
},
|
||||
{
|
||||
label: locales('state_send'),
|
||||
action: ()=>{
|
||||
stateManager.send()
|
||||
notifications.add({
|
||||
icon: 'sliders-h',
|
||||
message: locales('state_sendsuccess')
|
||||
})
|
||||
}
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: 'open'
|
||||
label: locales('file_open'),
|
||||
action: stateManager.browse.bind(stateManager)
|
||||
},
|
||||
{
|
||||
label: 'save'
|
||||
label: locales('file_save'),
|
||||
action: stateManager.save.bind(stateManager)
|
||||
},
|
||||
{
|
||||
label: 'save as'
|
||||
label: locales('file_save_as'),
|
||||
action: stateManager.saveAs.bind(stateManager)
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: 'import'
|
||||
label: locales('file_import'),
|
||||
action: stateManager.import.bind(stateManager)
|
||||
},
|
||||
{
|
||||
label: 'export'
|
||||
label: locales('file_export'),
|
||||
action: stateManager.export.bind(stateManager)
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Editor',
|
||||
label: locales('editor'),
|
||||
class: ()=>{return sessionManager.session === null ? 'disabled' : ''},
|
||||
action: [
|
||||
{
|
||||
label: 'enabled'
|
||||
label: locales('editor_enabled'),
|
||||
class: ()=>{return 'toggle ' + (editor.enabled ? 'on' : 'off')},
|
||||
action: ()=>{
|
||||
if (editor.enabled) editor.disable()
|
||||
else editor.enable()
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'grid'
|
||||
separator: true
|
||||
},
|
||||
{
|
||||
label: 'project tree'
|
||||
label: locales('editor_grid'),
|
||||
class: ()=>{return 'toggle ' + (editor.grid ? 'on' : 'off')},
|
||||
action: editor.toggleGrid.bind(editor)
|
||||
|
||||
},
|
||||
{
|
||||
label: 'inspector'
|
||||
label: locales('editor_tree'),
|
||||
class: ()=>{return 'toggle ' + (uiSidePanel.left.minimized ? 'off' : 'on')},
|
||||
action: ()=>{return uiSidePanel.left.minimized ? uiSidePanel.left.restore() : uiSidePanel.left.minimize()},
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
label: locales('editor_inspector'),
|
||||
class: ()=>{return 'toggle ' + (uiSidePanel.right.minimized ? 'off' : 'on')},
|
||||
action: ()=>{return uiSidePanel.right.minimized ? uiSidePanel.right.restore() : uiSidePanel.right.minimize()},
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -91,12 +149,37 @@ var menu = [
|
|||
separator: true
|
||||
},
|
||||
{
|
||||
label: 'Fullscreen',
|
||||
action: ()=>{}
|
||||
label: locales('fullscreen'),
|
||||
class: ()=>{return 'toggle ' + (fullscreen.isFullscreen ? 'on' : 'off')},
|
||||
action: ()=>{
|
||||
if (fullscreen.isEnabled) fullscreen.toggle()
|
||||
}
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
if (navigator.userAgent.match(/Android|iPhone|iPad|iPod/i)) {
|
||||
|
||||
var NoSleep = require('nosleep.js'),
|
||||
noSleep = new NoSleep(),
|
||||
noSleepState = false
|
||||
|
||||
menuEntries.push({
|
||||
label: locales('nosleep'),
|
||||
class: ()=>{return 'toggle ' + (noSleepState ? 'on' : 'off')},
|
||||
action:()=>{
|
||||
noSleepState = !noSleepState
|
||||
if (noSleepState) noSleep.disable()
|
||||
else noSleep.enable()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class UiToolbar extends UiWidget {
|
||||
|
||||
|
|
@ -107,6 +190,19 @@ class UiToolbar extends UiWidget {
|
|||
this.menu = new ContextMenu()
|
||||
this.opened = false
|
||||
|
||||
|
||||
ipc.on('sessionList', (data)=>{
|
||||
if (recentSessions.length) {
|
||||
recentSessions.splice(0, 10)
|
||||
}
|
||||
for (let s of data) [
|
||||
recentSessions.push({
|
||||
label: s,
|
||||
action: ()=>{sessionManager.requestOpen(s)}
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
this.container.addEventListener('fast-click', (e)=>{
|
||||
if (this.opened) this.close()
|
||||
else this.open(e)
|
||||
|
|
@ -129,7 +225,7 @@ class UiToolbar extends UiWidget {
|
|||
target: e.detail.target,
|
||||
pageX: e.detail.pageX - e.detail.offsetX + PXSCALE,
|
||||
pageY: e.detail.pageY - e.detail.offsetY + e.detail.target.offsetHeight + 5 * PXSCALE
|
||||
}, menu)
|
||||
}, menuEntries)
|
||||
|
||||
this.opened = true
|
||||
this.toggleState()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue