UI optimization

- fader, knob, xy and rgb use 3d accelerated css properties
- reduce the number of composited layers to the strict necessary (tweakin properties such as z-index helps a lot)
This commit is contained in:
jean-emmanuel 2016-02-22 08:13:02 +01:00
parent e2fca54813
commit 72734da6e5
4 changed files with 72 additions and 38 deletions

File diff suppressed because one or more lines are too long

View file

@ -231,7 +231,9 @@ rgbToHsb = function (rgb) {
return hsb
}
sizeToAngle = function(size) {
return clip(Math.acos((size/100))*180/Math.PI,[0,90])
}
clip = function(value,range) {
var max = Math.max,
min = Math.min,

View file

@ -452,7 +452,7 @@ createWidget.xy = function(widgetData) {
var widget = $(`
<div class="xy-wrapper">
<div class="xy">
<div class="handle"><span></span></div>
<div class="handle"></div>
</div>
<div class="value">
<input disabled value="X"></input><input disabled value="Y"></input>
@ -481,6 +481,7 @@ createWidget.xy = function(widgetData) {
pad.resize(function(){
pad.width = pad.innerWidth()
pad.height = pad.innerHeight()
handle[0].setAttribute('style',`transform:translate3d(${pad.width*handle.width/100}px, -${pad.height*handle.height/100}px,0)`)
})
var off = {x:0,y:0}
@ -488,7 +489,9 @@ createWidget.xy = function(widgetData) {
if (absolute || data.ctrlKey || data.shiftKey) {
var h = ((pad.height-data.offsetY) * 100 / pad.height),
w = (data.offsetX * 100 / pad.width)
handle[0].setAttribute('style','height:'+h+'%;width:'+w+'%')
handle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
handle.height = h
handle.width = w
@ -509,7 +512,10 @@ createWidget.xy = function(widgetData) {
var h = clip((-data.deltaY)*100/pad.height+off.y,[0,100]),
w = clip((data.deltaX)*100/pad.width+off.x,[0,100])
handle[0].setAttribute('style','height:'+h+'%;width:'+w+'%')
handle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
// handle[0].setAttribute('style','height:'+h+'%;width:'+w+'%')
handle.height = h
handle.width = w
@ -634,6 +640,8 @@ createWidget.rgb = function(widgetData) {
pad.resize(function(){
pad.width = pad.innerWidth()
pad.height = pad.innerHeight()
rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*rgbHandle.width/100}px, -${pad.height*rgbHandle.height/100}px,0)`)
})
@ -642,7 +650,8 @@ createWidget.rgb = function(widgetData) {
if (absolute || data.ctrlKey || data.shiftKey) {
var h = ((pad.height-data.offsetY) * 100 / pad.height),
w = (data.offsetX * 100 / pad.width)
rgbHandle[0].setAttribute('style','height:'+h+'%;width:'+w+'%')
rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
rgbHandle.height = h
rgbHandle.width = w
@ -663,7 +672,8 @@ createWidget.rgb = function(widgetData) {
var h = clip((-data.deltaY)*100/pad.height+rgbOff.y,[0,100]),
w = clip(data.deltaX*100/pad.width+rgbOff.x,[0,100])
rgbHandle[0].setAttribute('style','height:'+h+'%;width:'+w+'%')
rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
rgbHandle.height = h
rgbHandle.width = w
@ -680,7 +690,7 @@ createWidget.rgb = function(widgetData) {
huePad.on('draginit',function(e,data){
if (absolute || data.ctrlKey || data.shiftKey) {
var d = (data.offsetX * 100 / pad.width)
hueHandle[0].setAttribute('style','width:'+d+'%')
hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*d/100}px,0,0)`)
hueHandle.width = d
@ -709,7 +719,7 @@ createWidget.rgb = function(widgetData) {
if (data.shiftKey) return
var w = clip(data.deltaX*100/pad.width+hueOff,[0,100])
hueHandle[0].setAttribute('style','width:'+w+'%')
hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px,0,0)`)
hueHandle.width = w
var h = clip(hueHandle.width*3.6,[0,360]),
@ -750,8 +760,8 @@ createWidget.rgb = function(widgetData) {
h = mapToScale(hsb.b,[0,100],[0,100]),
hueW = mapToScale(hsb.h,[0,360],[0,100])
rgbHandle[0].setAttribute('style','height:'+h+'%;width:'+w+'%')
hueHandle[0].setAttribute('style','width:'+hueW+'%')
rgbHandle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
hueHandle[0].setAttribute('style',`transform:translate3d(${pad.width*hueW/100}px,0,0)`)
rgbHandle.height = h
rgbHandle.width = w
@ -831,7 +841,7 @@ createWidget.fader = function(widgetData,container){
<div class="fader-wrapper-outer">
<div class="fader-wrapper">
<div class="fader">
<div class="handle"></div>
<div class="handle"><span></span></div>
<div class="pips"></div>
</div>
</div>
@ -839,12 +849,14 @@ createWidget.fader = function(widgetData,container){
</div>
`),
handle = widget.find('.handle'),
knob = widget.find('span')[0],
wrapper = widget.find('.fader-wrapper'),
fader = widget.find('.fader'),
pips = widget.find('.pips'),
input = widget.find('input'),
unit = widgetData.unit?' '+widgetData.unit.trim(): '',
dimension = widgetData.horizontal?'width':'height',
axe = dimension=='height'?'X':'Y',
absolute = widgetData.absolute
if (widgetData.horizontal) container.addClass('horizontal')
@ -866,7 +878,9 @@ createWidget.fader = function(widgetData,container){
var d = (dimension=='height')?
((fader.size-data.offsetY+(wrapper.size-fader.size)/2) * 100 / fader.size):
(data.offsetX - (wrapper.size-fader.size)/2) * 100 / fader.size
handle[0].setAttribute('style',dimension+':'+d+'%')
var r = sizeToAngle(d)
handle[0].setAttribute('style','transform:rotate'+axe+'('+ r +'deg)')
knob.setAttribute('style','transform:rotate'+axe+'('+ (-r) +'deg)')
handle.size = d
var v = widget.getValue()
@ -888,8 +902,11 @@ createWidget.fader = function(widgetData,container){
if (data.shiftKey) return
var d = (dimension=='height')?-data.deltaY:data.deltaX
d = clip(d*100/fader.size+off,[0,100])
handle[0].setAttribute('style',dimension+':'+d+'%')
d = clip(d*100/fader.size+off,[0,100])
var r = sizeToAngle(d)
handle[0].setAttribute('style','transform:rotate'+axe+'('+ r +'deg)')
knob.setAttribute('style','transform:rotate'+axe+'('+ (-r) +'deg)')
handle.size = d
var v = widget.getValue()

View file

@ -699,7 +699,6 @@ a {
}
.label {
z-index: 1;
padding:10rem 10rem;
position:absolute;
top:0;
@ -951,7 +950,6 @@ a {
left:0;
right:0;
bottom:0;
z-index: 1;
.light {
position: absolute;
@ -1120,15 +1118,14 @@ a {
}
.handle {
position:absolute;
height:0rem;
width:0rem;
bottom:0;
left:0;
max-height:100%;
max-width:100%;
z-index:2;
pointer-events: none;
backface-visibility: hidden;
transform-origin: center;
transform:translate3d(0,0,0);
&:before {
content:"";
position: absolute;
@ -1241,17 +1238,15 @@ a {
}
.handle {
position:absolute;
height:100%;
max-width: 100%;
width:0;
z-index:2;
left:0;
bottom:0;
top:50%;
pointer-events: none;
transform: translate3d(0,0,0);
&:before {
content:"";
position: absolute;
top:50%;margin-top:-4rem;
top:-4rem;
right:-4rem;
height:8rem;
width:8rem;
@ -1273,6 +1268,7 @@ a {
.fader-container {
width:100rem;
min-height: 200rem;
height:100%;
&.nolabel .fader-wrapper-outer {
@ -1319,13 +1315,24 @@ a {
bottom:0!important;
top:auto!important;
width:100%;
height:0rem;
height:100%;
transform-origin: bottom;
max-height:100%;
max-width:100%;
background:$color-accent;
z-index: 1;
&:before {
transform-style: preserve-3d;
backface-visibility: hidden;
span {
position: absolute;
bottom:0;
top:0;
width:100%;
height:100%;
transform-origin: top;
backface-visibility: hidden;
}
span:before {
content:"";
position: absolute;
top:-4rem;
@ -1337,7 +1344,7 @@ a {
border-radius: 100%!important;
box-shadow: 0 0 0 6rem transparentize($color-accent,.8),0 0 2rem 0 mix($color-text,$color-fg,2);
}
&:after {
span:after {
content:"";
position: absolute;
top:-10rem;
@ -1401,14 +1408,18 @@ a {
top:50%;
height:4rem;
.handle {
height:100%!important;
width:0;
&:before {
height:100%important;
width:100%;
transform-origin: left;
span {
transform-origin: right;
}
span:before {
top:-2rem;
right:-4rem;
left:auto;
}
&:after {
span:after {
top:-8rem;
right:-10rem;
left:auto
@ -1464,7 +1475,6 @@ a {
input {
bottom:0;
position: absolute;
z-index: 1;
left:0;
}
@ -1533,7 +1543,7 @@ a {
border-radius:100%;
border:12rem solid transparent;
border-bottom-color: $color-raised;
z-index:1;
z-index:2;
}
}
.round {
@ -1554,6 +1564,9 @@ a {
right:0;
bottom:0;
pointer-events: none;
transform:rotateZ(0deg);
backface-visibility: hidden;
z-index: 2;
&:after {
@ -1584,7 +1597,9 @@ a {
right:0;
bottom:0;
pointer-events: none;
z-index: 2;
transform:rotateZ(0deg);
backface-visibility: hidden;
z-index: 3;
&:before {
content:"";
position: absolute;