uiToolbar on the way, screen sized windows by default

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

View file

@ -18,6 +18,7 @@
<body>
<osc-workspace>
<osc-toolbar></osc-toolbar>
<osc-panel-container class="left">
<div class="resize-handle left"></div>
<div class="toggle-button left"></div>
@ -37,7 +38,7 @@
<osc-panel-content class="right" id="osc-inspector"></osc-panel-content>
</osc-panel-inner>
</osc-panel-container>
<osc-modal-container class="backdrop"></osc-modal-container>
<osc-modal-container></osc-modal-container>
</osc-workspace>
<div id="notifications"></div>
</body>

View file

@ -4,7 +4,8 @@ var {updateWidget} = require('./data-workers'),
{icon} = require('../ui/utils'),
editor = require('./'),
locales = require('../locales'),
contextMenu = require('../ui/context-menu')
ContextMenu = require('../ui/context-menu'),
contextMenu = new ContextMenu()
var multiSelectKey = (navigator.platform || '').match('Mac') ? 'metaKey' : 'ctrlKey'

View file

@ -1,7 +1,7 @@
var EventEmitter = require('../events/event-emitter'),
ipc = require('../ipc/')
var WidgetManager = class WidgetManager extends EventEmitter {
class WidgetManager extends EventEmitter {
constructor() {
@ -28,6 +28,10 @@ var WidgetManager = class WidgetManager extends EventEmitter {
this.registerWidget(this.widgets[hash])
}
})
setInterval(()=>{
this.trigger('root-nav-changed')
}, 1000)
}

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()

View file

@ -49,7 +49,7 @@ class Modal extends Panel {
super(options)
this.popup = html`
<div class="popup backdrop">
<div class="popup">
<div class="popup-wrapper">
<div class="popup-title closable"><span class="popup-label"></span><span class="closer">${raw(icon('times'))}</span></div>
<div class="popup-content widget panel-container not-editable contains-widgets"></div>

View file

@ -47,7 +47,7 @@ class Panel extends Container() {
super({...options, html: html`<inner></inner>`})
this.container.classList.toggle('no-scroll', this.getProp('scroll') === false)
this.container.classList.toggle('no-scroll', !this.getProp('scroll'))
this.container.classList.add('layout-' + this.getProp('layout'))
if (this.getProp('layout') === 'grid') {

View file

@ -48,9 +48,11 @@ class Root extends StaticProperties(Panel, {scroll: false, label: false, id: 'ro
this.widget.classList.add('root')
DOM.each(this.widget, '> .navigation', (el)=>{
el.classList.add('main')
})
this.trigger('root-nav-changed')
}
@ -58,12 +60,6 @@ class Root extends StaticProperties(Panel, {scroll: false, label: false, id: 'ro
super.createNavigation()
this.navigation.appendChild(html`
<div class="tools not-editable">${raw(icon('expand'))}></div>
<div class="tools not-editable">${raw(icon('pen'))}></div>
<div class="tools not-editable">${raw(icon('ellipsis-v'))}></div>
`)
}
isVisible() {

View file

@ -11,3 +11,4 @@
@import 'ui/filebrowser';
@import 'ui/lobby';
@import 'ui/loading';
@import 'ui/toolbar';

View file

@ -2,6 +2,9 @@ $line-height: 30rem;
.context-menu {
--widget-padding: 0rem;
--alpha-fill: 0.75;
position:fixed;
z-index: 999999999;
background: var(--color-context-menu);
@ -9,7 +12,6 @@ $line-height: 30rem;
text-transform: none;
color: var(--color-context-menu-text);
line-height: $line-height;
--widget-padding: 0rem;
.context-menu {
position: absolute;
@ -57,4 +59,10 @@ $line-height: 30rem;
position: relative;
}
}
.separator{
margin: 2rem 1rem;
height: 1rem;
background-color: var(--color-ui-background);
opacity: 0.5;
}
}

26
src/scss/ui/toolbar.scss Normal file
View file

@ -0,0 +1,26 @@
osc-toolbar {
--size: 34rem;
position: fixed;
top: 0;
left: 0;
height:var(--size);
width:var(--size);
max-width:var(--size);
min-width:var(--size);
text-align: center;
z-index: 999999999;
cursor: pointer;
&:after {
transition: text-shadow .1s, color .1s;
content:"\f142";
font-family: FontAwesome;
line-height: calc(var(--size) + 4rem);
}
&.on {
&:after {
color: var(--color-widget);
text-shadow: 0 0 8rem;
}
}
}

View file

@ -188,16 +188,6 @@
padding-bottom: 1rem;
position: relative;
&.main {
:last-child, .tools {
width:var(--nav-height);
max-width:var(--nav-height);
min-width:var(--nav-height);
margin-left: 1rem;
text-align: center;
}
}
&:before {
content:"";
position: absolute;

View file

@ -1,8 +1,9 @@
var path = require('path'),
{BrowserWindow, dialog, shell} = require('electron'),
{BrowserWindow, dialog, shell, screen} = require('electron'),
shortcut = require('electron-localshortcut'),
settings = require('./settings'),
theme = require('./theme')
theme = require('./theme'),
screenSize = screen.getPrimaryDisplay().size
module.exports = function(options={}) {
@ -10,8 +11,8 @@ module.exports = function(options={}) {
var window
window = new BrowserWindow({
width: options.width || 800,
height: options.height || 600,
width: options.width || screenSize.width,
height: options.height || screenSize.height,
title: options.title || settings.read('appName'),
icon: path.resolve(__dirname + '/../assets/logo.png'),
backgroundColor: options.color || theme.backgroundColor,