editor: ui tweaks and inspector toolbar
This commit is contained in:
parent
e43c6fea22
commit
8bb2813a49
5 changed files with 161 additions and 58 deletions
|
|
@ -7,8 +7,11 @@ var UiWidget = require('./ui-widget'),
|
|||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw'),
|
||||
fastdom = require('fastdom'),
|
||||
{icon} = require('./utils'),
|
||||
zoom = require('./zoom'),
|
||||
getCodeEditor = require('./ui-code-editor'),
|
||||
codeEditorModKey = (navigator.platform || '').match('Mac') ? 'metaKey' : 'ctrlKey'
|
||||
codeEditorModKey = (navigator.platform || '').match('Mac') ? 'metaKey' : 'ctrlKey',
|
||||
editor
|
||||
|
||||
class UiInspector extends UiWidget {
|
||||
|
||||
|
|
@ -22,6 +25,24 @@ class UiInspector extends UiWidget {
|
|||
|
||||
this.widget = null
|
||||
|
||||
this.toolbar = this.container.appendChild(html`
|
||||
<div class="toolbar">
|
||||
<div class="btn toolbar-btn" data-action="zoom-out">${raw(icon('magnifying-glass-minus'))}</div>
|
||||
<div class="btn toolbar-btn" data-action="zoom-reset">${raw(icon('magnifying-glass'))}</div>
|
||||
<div class="btn toolbar-btn" data-action="zoom-in">${raw(icon('magnifying-glass-plus'))}</div>
|
||||
<div class="btn toolbar-btn" data-action="toggle-grid">${raw(icon('table-cells'))}</div>
|
||||
</div>
|
||||
`)
|
||||
this.toolbarBtns = {}
|
||||
DOM.each(this.toolbar, '.btn', (item)=>{this.toolbarBtns[item.getAttribute('data-action')] = item})
|
||||
zoom.on('local-zoom-changed',()=>{
|
||||
this.toolbarBtns['zoom-out'].classList.toggle('active', zoom.localZoom < 1)
|
||||
this.toolbarBtns['zoom-in'].classList.toggle('active', zoom.localZoom > 1)
|
||||
})
|
||||
|
||||
|
||||
this.content = this.container.appendChild(html`<div class="content"></div>`)
|
||||
|
||||
this.container.addEventListener('fast-click', (e)=>{
|
||||
|
||||
if (e.target.classList.contains('category-header')) {
|
||||
|
|
@ -45,6 +66,23 @@ class UiInspector extends UiWidget {
|
|||
this.expandedCategories.push(name)
|
||||
}
|
||||
|
||||
} else if (e.target.classList.contains('toolbar-btn')) {
|
||||
|
||||
switch (e.target.getAttribute('data-action')) {
|
||||
case 'zoom-out':
|
||||
zoom.setLocalZoom(zoom.localZoom - 0.1)
|
||||
break
|
||||
case 'zoom-reset':
|
||||
zoom.setLocalZoom(1)
|
||||
break
|
||||
case 'zoom-in':
|
||||
zoom.setLocalZoom(zoom.localZoom + 0.1)
|
||||
break
|
||||
case 'toggle-grid':
|
||||
editor = editor || require('../editor')
|
||||
editor.toggleGrid()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
|
@ -112,7 +150,7 @@ class UiInspector extends UiWidget {
|
|||
|
||||
this.clearTimeout = setTimeout(()=>{
|
||||
this.widget = null
|
||||
this.container.innerHTML = ''
|
||||
this.content.innerHTML = ''
|
||||
this.mounted = false
|
||||
this.clearTimeout = null
|
||||
this.colorPicker.close()
|
||||
|
|
@ -137,7 +175,7 @@ class UiInspector extends UiWidget {
|
|||
|
||||
this.widget = widget
|
||||
|
||||
var content = html`<div class="${lock ? 'lock' : ''}"></div>`
|
||||
var content = html`<div class="content ${lock ? 'lock' : ''}"></div>`
|
||||
|
||||
for (let categoryName in props) {
|
||||
|
||||
|
|
@ -207,11 +245,7 @@ class UiInspector extends UiWidget {
|
|||
|
||||
this.lock = true
|
||||
|
||||
if (this.mounted) {
|
||||
morph(this.container.firstChild, content)
|
||||
} else {
|
||||
this.container.appendChild(content)
|
||||
}
|
||||
morph(this.content, content)
|
||||
|
||||
if (codeEditorFields.length) {
|
||||
let fields = DOM.get(this.container, '.has-editor')
|
||||
|
|
|
|||
|
|
@ -1,60 +1,73 @@
|
|||
// mousewheel zoom
|
||||
|
||||
var EventEmitter = require('../events/event-emitter')
|
||||
var mod = (navigator.platform || '').match('Mac') ? 'metaKey' : 'ctrlKey'
|
||||
|
||||
var localZoom = 1//,
|
||||
// mousePos = [0, 0]
|
||||
class Zoom extends EventEmitter {
|
||||
|
||||
document.addEventListener('wheel', function(event) {
|
||||
if (event.ctrlKey) event.preventDefault()
|
||||
if (event[mod]) {
|
||||
constructor() {
|
||||
|
||||
event.preventDefault()
|
||||
super()
|
||||
|
||||
if (event.deltaY === 0) return
|
||||
this.localZoom = 1
|
||||
|
||||
let d = - event.deltaY / (10 * Math.abs(event.deltaY))
|
||||
if (!isNaN(d)) {
|
||||
PXSCALE = parseFloat(d) + parseFloat(PXSCALE)
|
||||
document.addEventListener('wheel', (event)=>{
|
||||
if (event.ctrlKey) event.preventDefault()
|
||||
if (event[mod]) {
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
if (event.deltaY === 0) return
|
||||
|
||||
let d = - event.deltaY / (10 * Math.abs(event.deltaY))
|
||||
if (!isNaN(d)) this.setGlobalZoom(d + PXSCALE)
|
||||
}
|
||||
if (event.altKey) {
|
||||
event.preventDefault()
|
||||
let d = - event.deltaY / (10 * Math.abs(event.deltaY)) * 2
|
||||
if (!isNaN(d)) this.setLocalZoom(d + this.localZoom)
|
||||
}
|
||||
|
||||
}, {passive: false})
|
||||
|
||||
document.addEventListener('keydown', (event)=>{
|
||||
if (event[mod]) {
|
||||
|
||||
if (event.keyCode == 96 || event.keyCode == 48) {
|
||||
this.setGlobalZoom(INITIALZOOM)
|
||||
this.setLocalZoom(1)
|
||||
}
|
||||
else if (event.keyCode == 107 || event.keyCode == 109) {
|
||||
this.setGlobalZoom((event.keyCode == 107 ? 0.1 : -0.1) + PXSCALE)
|
||||
}
|
||||
|
||||
}
|
||||
}, {passive: true})
|
||||
|
||||
}
|
||||
|
||||
setLocalZoom(zoom) {
|
||||
|
||||
zoom = Math.max(Math.min(zoom, 4), 0.25)
|
||||
if (zoom !== this.localZoom) {
|
||||
requestAnimationFrame(()=>{
|
||||
this.localZoom = zoom
|
||||
document.documentElement.style.setProperty('--local-zoom', this.localZoom)
|
||||
this.trigger('local-zoom-changed')
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setGlobalZoom(zoom) {
|
||||
|
||||
if (zoom !== PXSCALE) {
|
||||
PXSCALE = zoom
|
||||
document.documentElement.style.setProperty('font-size', PXSCALE + 'px')
|
||||
DOM.dispatchEvent(window, 'resize')
|
||||
this.trigger('global-zoom-changed')
|
||||
}
|
||||
}
|
||||
if (event.altKey) {
|
||||
event.preventDefault()
|
||||
let d = - event.deltaY / (10 * Math.abs(event.deltaY)) * 2
|
||||
if (!isNaN(d)) {
|
||||
localZoom = Math.max(parseFloat(d) + parseFloat(localZoom), 0.25)
|
||||
applylocalZoom()
|
||||
}
|
||||
}
|
||||
}, {passive: false})
|
||||
|
||||
var container = DOM.get('#osc-container')[0]
|
||||
function applylocalZoom() {
|
||||
requestAnimationFrame(()=>{
|
||||
container.style.setProperty('--local-zoom', localZoom)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', function(event){
|
||||
if (event[mod]) {
|
||||
|
||||
var z = false
|
||||
if (event.keyCode == 96 || event.keyCode == 48) {
|
||||
PXSCALE = INITIALZOOM
|
||||
document.documentElement.style.setProperty('font-size', PXSCALE + 'px')
|
||||
localZoom = 1
|
||||
applylocalZoom()
|
||||
z = true
|
||||
}
|
||||
else if (event.keyCode == 107 || event.keyCode == 109) {
|
||||
PXSCALE = (event.keyCode == 107 ? 0.1 : -0.1) + parseFloat(PXSCALE)
|
||||
document.documentElement.style.setProperty('font-size', PXSCALE + 'px')
|
||||
}
|
||||
|
||||
|
||||
if (z) DOM.dispatchEvent(window, 'resize')
|
||||
|
||||
}
|
||||
}, {passive: true})
|
||||
module.exports = new Zoom()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
.btn {
|
||||
background: var(--color-background);
|
||||
background: var(--color-ui-button);
|
||||
border: 1rem solid var(--color-background);
|
||||
display: block;
|
||||
padding: 0 15rem;
|
||||
position: relative;
|
||||
|
|
@ -13,4 +14,7 @@
|
|||
pointer-events: none;
|
||||
opacity: 0.5;
|
||||
}
|
||||
&.active {
|
||||
color: var(--color-accent)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,53 @@ osc-panel-container.right.editor-breakout {
|
|||
}
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
padding: $padding / 2;
|
||||
height: 46rem;
|
||||
position: relative;
|
||||
top:0;
|
||||
z-index: 21;
|
||||
background: var(--color-ui-background);
|
||||
border-bottom:1rem solid var(--color-background);
|
||||
.btn {
|
||||
margin: $padding / 2;
|
||||
padding: 0 8rem 1rem;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
display: flex;
|
||||
&:last-child {
|
||||
margin-left: auto;
|
||||
}
|
||||
i {
|
||||
pointer-events: none;
|
||||
}
|
||||
&[data-action="toggle-grid"] {
|
||||
color: var(--color-accent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
overflow: hidden;
|
||||
> .content {
|
||||
overflow: auto;
|
||||
flex:1;
|
||||
height: 100%;
|
||||
&::-webkit-scrollbar-thumb, &::-webkit-scrollbar-track-piece {
|
||||
border-color: var(--color-background)!important;
|
||||
border-top:0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
body.no-grid #osc-inspector .toolbar .btn[data-action="toggle-grid"] {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
osc-inspector-field {
|
||||
|
||||
display: flex;
|
||||
|
|
@ -385,9 +430,11 @@ osc-inspector-category {
|
|||
height: $header-height;
|
||||
line-height: $header-height - 1;
|
||||
// padding: 0 8rem;
|
||||
// position: sticky;
|
||||
// top:46rem;z-index: 20;
|
||||
// background: var(--color-ui-background);
|
||||
font-weight: 500;
|
||||
@include pseudo-fill($z: -1);
|
||||
|
||||
&:after {
|
||||
left:-($padding - 1);
|
||||
right:-($padding - 1);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@
|
|||
overflow: auto;
|
||||
padding-left:$padding + 4rem;
|
||||
padding-right:$padding;
|
||||
border-top:1rem solid var(--color-background);
|
||||
|
||||
&::-webkit-scrollbar-thumb, &::-webkit-scrollbar-track-piece {
|
||||
border-color: var(--color-background)!important;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue