uiToolbar on the way, screen sized windows by default

This commit is contained in:
bordun 2020-03-03 22:18:16 +01:00
parent a58075c602
commit 5b1913da12
17 changed files with 252 additions and 51 deletions

View file

@ -1,14 +1,21 @@
var html = require('nanohtml'),
raw = require('nanohtml/raw')
raw = require('nanohtml/raw'),
UiWidget = require('./ui-widget'),
MENU_CONTAINER
class ContextMenu {
class ContextMenu extends UiWidget {
constructor(){
constructor(options){
this.menu = null
this.root = DOM.get('osc-workspace')[0]
super(options)
if (!MENU_CONTAINER) MENU_CONTAINER = DOM.get('osc-modal-container')[0]
this.container = null
MENU_CONTAINER = DOM.get('osc-workspace')[0]
this.clickHandler = (e)=>{
if (this.menu && !this.menu.contains(e.target)) this.close()
if (this.container && !this.container.contains(e.target)) this.close()
}
}
@ -19,7 +26,11 @@ class ContextMenu {
for (let action of actions) {
if (Array.isArray(action.action)) {
if (action.separator) {
menu.appendChild(html`<div class="separator"></div>`)
} else if (Array.isArray(action.action)) {
let item = html`<div class="item has-sub" tabIndex="1">${raw(action.label)}</div>`
@ -60,9 +71,9 @@ class ContextMenu {
if (!parent) {
this.menu = menu
this.container = menu
this.root.appendChild(menu)
MENU_CONTAINER.appendChild(menu)
DOM.each(menu, '.item', (item)=>{
item.addEventListener('mouseenter', ()=>{
@ -90,19 +101,24 @@ class ContextMenu {
document.addEventListener('fast-click', this.clickHandler, true)
document.addEventListener('fast-right-click', this.clickHandler, true)
this.trigger('open')
}
close() {
if (this.menu) {
if (this.container) {
this.menu.parentNode.removeChild(this.menu)
this.menu = null
this.container.parentNode.removeChild(this.container)
this.container = null
}
document.removeEventListener('fast-click', this.clickHandler, true)
document.removeEventListener('fast-right-click', this.clickHandler, true)
this.trigger('close')
}
correctPosition(menu, parent) {
@ -110,8 +126,8 @@ class ContextMenu {
var position = DOM.offset(menu),
width = menu.offsetWidth,
height = menu.offsetHeight,
totalWidth = this.root.offsetWidth,
totalHeight = this.root.offsetHeight
totalWidth = MENU_CONTAINER.offsetWidth,
totalHeight = MENU_CONTAINER.offsetHeight
if (width + position.left > totalWidth) {
menu.style.right = parent ? '100%' : '0'
@ -128,4 +144,4 @@ class ContextMenu {
}
module.exports = new ContextMenu()
module.exports = ContextMenu

View file

@ -5,4 +5,5 @@ require('../events/click')
require('./ios')
require('./notifications')
require('./ui-workspace')
require('./ui-toolbar')
// require('./ui-sidepanel')

View file

@ -3,9 +3,8 @@ var UiWidget = require('./ui-widget'),
html = require('nanohtml'),
raw = require('nanohtml/raw'),
MODAL_SINGLETON = null,
MODAL_CONTAINER = null,
OPENED_MODALS = 0
MODAL_CONTAINER = null
class UiModal extends UiWidget {
constructor(options) {
@ -79,9 +78,6 @@ class UiModal extends UiWidget {
if (this.escKey) document.removeEventListener('keydown', this.escKeyHandler)
if (this.enterKey) document.removeEventListener('keydown', this.enterKeyHandler)
if (--OPENED_MODALS === 0) MODAL_CONTAINER.classList.remove('backdrop')
MODAL_CONTAINER.removeChild(this.container)
this.trigger('close')
@ -96,8 +92,6 @@ class UiModal extends UiWidget {
if (this.escKey) document.addEventListener('keydown', this.escKeyHandler)
if (this.enterKey) document.addEventListener('keydown', this.enterKeyHandler)
if (++OPENED_MODALS === 1) MODAL_CONTAINER.classList.add('backdrop')
MODAL_CONTAINER.appendChild(this.container)
this.trigger('open')

View file

@ -14,7 +14,7 @@ class UiSidePanel extends UiWidget {
this.minWidth = 250
this.width = 250
this.disabled = true
this.disabled = false
this.minimized = false
this.init = false
@ -41,6 +41,8 @@ class UiSidePanel extends UiWidget {
})
this.disable()
}
enable() {

160
src/client/ui/ui-toolbar.js Normal file
View file

@ -0,0 +1,160 @@
var UiWidget = require('./ui-widget'),
morph = require('nanomorph'),
ContextMenu = require('./context-menu'),
html = require('nanohtml'),
raw = require('nanohtml/raw'),
{icon} = require('./utils')
var menu = [
{
label: 'Session',
action: [
{
label: 'new'
},
{
separator: true
},
{
label: 'open'
},
{
label: 'save'
},
{
label: 'save as'
},
{
separator: true
},
{
label: 'import'
},
{
label: 'export'
},
]
},
{
label: 'State',
action: [
{
label: 'store'
},
{
label: 'recall'
},
{
separator: true
},
{
label: 'open'
},
{
label: 'save'
},
{
label: 'save as'
},
{
separator: true
},
{
label: 'import'
},
{
label: 'export'
},
]
},
{
label: 'Editor',
action: [
{
label: 'enabled'
},
{
label: 'grid'
},
{
label: 'project tree'
},
{
label: 'inspector'
}
]
},
{
separator: true
},
{
label: 'Fullscreen',
action: ()=>{}
},
]
class UiToolbar extends UiWidget {
constructor(options) {
super(options)
this.menu = new ContextMenu()
this.opened = false
this.container.addEventListener('fast-click', (e)=>{
if (this.opened) this.close()
else this.open(e)
})
this.menu.on('close', ()=>{
setTimeout(()=>{
this.opened = false
this.toggleState()
})
})
}
open(e) {
if (this.opened) return
this.menu.open({
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)
this.opened = true
this.toggleState()
}
close() {
if (this.opened) return
this.menu.close()
this.opened = false
this.toggleState()
}
toggleState() {
this.container.classList.toggle('on', this.opened)
}
}
module.exports = new UiToolbar({selector: 'osc-toolbar'})

View file

@ -2,7 +2,7 @@ var EventEmitter = require('../events/event-emitter')
class UiWidget extends EventEmitter {
constructor(options) {
constructor(options={}) {
super()