move controllers to their own folders, clean up gulpfile

This commit is contained in:
George Michael Brower 2014-08-16 12:43:48 -04:00
parent eef1006135
commit 0dfd9f1d1a
20 changed files with 75 additions and 157 deletions

View File

@ -1,3 +0,0 @@
<link rel="import" href="../components/polymer/polymer.html">
<script src="base-controller.js"></script>
<polymer-element name="base-controller"></polymer-element>

View File

@ -0,0 +1,3 @@
<link rel="import" href="../../components/polymer/polymer.html">
<script src="controller-base.js"></script>
<polymer-element name="controller-base"></polymer-element>

View File

@ -5,7 +5,7 @@
*/ */
Polymer('base-controller', { Polymer('controller-base', {
value: null, value: null,
object: null, object: null,

View File

@ -1,18 +1,17 @@
<link rel="import" href="../components/polymer/polymer.html"> <link rel="import" href="../../components/polymer/polymer.html">
<link rel="import" href="base-controller.html"> <link rel="import" href="../controller-base/controller-base.html">
<script src="number-controller.js"></script> <script src="controller-number.js"></script>
<polymer-element <polymer-element
name="number-controller" name="controller-number"
attributes="min max value step" attributes="min max value step"
extends="base-controller" extends="controller-base"
constructor="NumberController"
> >
<template> <template>
<link rel="stylesheet" href="number-controller.css"> <link rel="stylesheet" href="controller-number.css">
<div id="container" class="transition" horizontal layout center> <div id="container" class="transition" horizontal layout center>

View File

@ -2,12 +2,11 @@
[ ] arrow keys [ ] arrow keys
[ ] only validate input box on blur, not on keydown
[ ] enter key blurs
[ ] min( ) max( ) step( ) commands of yore [ ] min( ) max( ) step( ) commands of yore
[x] sig figs [x] only validate input box on blur, not on keydown
[x] enter key blurs
[x] decimals
[x] step [x] step
[x] dy to drag friction [x] dy to drag friction
[x] negative slider [x] negative slider
@ -15,7 +14,7 @@
*/ */
Polymer('number-controller', { Polymer('controller-number', {
min: 0, min: 0,
max: 100, max: 100,
@ -44,11 +43,14 @@ Polymer('number-controller', {
// ------------------------------- // -------------------------------
valueChanged: function() { valueChanged: function() {
this.value = Math.max( this.value, this.min );
this.value = Math.min( this.value, this.max );
if ( this.step !== null ) { if ( this.step !== null ) {
this.value = Math.round( this.value / this.step ) * this.step; this.value = Math.round( this.value / this.step ) * this.step;
} }
this.value = Math.max( this.value, this.min );
this.value = Math.min( this.value, this.max );
this.super(); this.super();
}, },
@ -154,11 +156,16 @@ Polymer('number-controller', {
}, },
tracky: function( e ) { tracky: function( e ) {
this._dragFriction = Math.max( 0.01, Math.min( 1, this.map( e.dy, 50, 300, 1, 0.1 ) ) ); this._dragFriction = Math.max( 0.01, Math.min( 1, this.map( e.dy, 50, 300, 1, 0.1 ) ) );
}, },
blur: function( e ) { blur: function( e ) {
this.value = parseFloat( this.$.input.value ); var v = parseFloat( this.$.input.value );
if ( v === v ) {
this.value = v;
}
}, },
keydown: function( e ) { keydown: function( e ) {
@ -174,12 +181,7 @@ Polymer('number-controller', {
truncate: function( v ) { truncate: function( v ) {
if ( v % 1 !== 0 && this.decimals !== null ) { if ( v % 1 !== 0 && this.decimals !== null ) {
return this.limitDecimals( v, this.decimals );
var s = v.toString();
var numDecimals = s.substring( s.indexOf( '.' ) ).length;
return v.toFixed( Math.min( numDecimals, this.decimals ) );
} else { } else {
return v; return v;
} }
@ -190,6 +192,23 @@ Polymer('number-controller', {
// Helpers // Helpers
// ------------------------------- // -------------------------------
limitDecimals: function( v, maxDecimals ) {
var str = v.toString();
var numDecimals = str.substring( str.indexOf( '.' ) + 1 ).length;
str = v.toFixed( Math.min( numDecimals, this.decimals ) );
for ( var z, i = 0, l = str.length; i < l; i++ ) {
if ( str.charAt( i ) !== '0' ) {
z = i;
}
}
return str.substring( 0, z+1 );
},
valueFromX: function( x ) { valueFromX: function( x ) {
return this.map( x, this._rect.left, this._rect.right, this.min, this.max ); return this.map( x, this._rect.left, this._rect.right, this.min, this.max );
}, },

View File

@ -1,6 +0,0 @@
:host {
position: absolute;
top: 0;
right: 20px;
width: 300px;
}

View File

@ -1,4 +1,4 @@
<link rel="import" href="../components/polymer/polymer.html"> <link rel="import" href="../../components/polymer/polymer.html">
<polymer-element <polymer-element
name="gui-panel" name="gui-panel"

View File

@ -15,7 +15,7 @@ Polymer('gui-panel', {
if ( typeof object[ property ] == 'number' ) { if ( typeof object[ property ] == 'number' ) {
controller = document.createElement( 'number-controller' ); controller = document.createElement( 'controller-number' );
if ( arguments[ 2 ] !== undefined ) controller.min = arguments[ 2 ]; if ( arguments[ 2 ] !== undefined ) controller.min = arguments[ 2 ];
if ( arguments[ 3 ] !== undefined ) controller.max = arguments[ 3 ]; if ( arguments[ 3 ] !== undefined ) controller.max = arguments[ 3 ];

View File

@ -1,18 +0,0 @@
#row {
-webkit-text-select: none;
background: #1a1a1a;
}
#name {
font: 500 11px 'Roboto', sans-serif;
color: #fff;
-webkit-font-smoothing: antialiased;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
word-wrap: break-word;
overflow: hidden;
width: 33%;
padding: 0 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}

View File

@ -1,9 +1,8 @@
<link rel="import" href="../components/polymer/polymer.html"> <link rel="import" href="../../components/polymer/polymer.html">
<polymer-element <polymer-element
name="gui-row" name="gui-row"
attributes="name" attributes="name">
constructor="GUIRow">
<template> <template>

View File

@ -1,89 +0,0 @@
:host {
display: block;
font-size: 0;
height: 100%;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#track-container {
width: 100%;
height: 30px;
}
#track {
width: 100%;
height: 1px;
-webkit-border-radius: 1px;
border-radius: 1px;
display: inline-block;
position: relative;
background: rgba(255,255,255,0.25);
}
#fill {
height: 1px;
margin-top: 0px;
margin-left: 1px;
-webkit-border-radius: 1px;
border-radius: 1px;
position: absolute;
background: #25a0d8;
pointer-events: none;
}
#knob {
width: 6px;
height: 6px;
margin-left: -3px;
margin-top: -3px;
-webkit-transition: -webkit-transform 0.1s cubic-bezier(0.25, 0.25, 0, 1);
-moz-transition: -moz-transform 0.1s cubic-bezier(0.25, 0.25, 0, 1);
-o-transition: -o-transform 0.1s cubic-bezier(0.25, 0.25, 0, 1);
-ms-transition: -ms-transform 0.1s cubic-bezier(0.25, 0.25, 0, 1);
transition: transform 0.1s cubic-bezier(0.25, 0.25, 0, 1);
pointer-events: none;
position: absolute;
background-color: #25a0d8;
-webkit-border-radius: 100%;
border-radius: 100%;
}
#track-container:hover #knob {
-webkit-transform: scale(2);
-moz-transform: scale(2);
-o-transform: scale(2);
-ms-transform: scale(2);
transform: scale(2);
}
#track-container:active #knob {
-webkit-transform: scale(1.5);
-moz-transform: scale(1.5);
-o-transform: scale(1.5);
-ms-transform: scale(1.5);
transform: scale(1.5);
}
input {
font: 500 11px 'Roboto', sans-serif;
color: #fff;
-webkit-font-smoothing: antialiased;
height: 30px;
margin-left: 5px;
display: inline-block;
background: transparent;
border: 0;
text-align: center;
outline: none;
width: 20%;
-webkit-transition: width 0.2s cubic-bezier(0.25, 0.25, 0, 1);
-moz-transition: width 0.2s cubic-bezier(0.25, 0.25, 0, 1);
-o-transition: width 0.2s cubic-bezier(0.25, 0.25, 0, 1);
-ms-transition: width 0.2s cubic-bezier(0.25, 0.25, 0, 1);
transition: width 0.2s cubic-bezier(0.25, 0.25, 0, 1);
}
input:hover {
width: 28%;
}
input:focus {
width: 50%;
}
input::selection {
background-color: rgba(255,255,255,0.25);
}

View File

@ -7,7 +7,6 @@ ease = cubic-bezier( .25, .25, 0, 1 )
light = rgba( 255, 255, 255, 0.25 ) light = rgba( 255, 255, 255, 0.25 )
dark = rgba( 0, 0, 0, 0.1 ); dark = rgba( 0, 0, 0, 0.1 );
font() font()
font: 500 11px 'Roboto', sans-serif; font: 500 11px 'Roboto', sans-serif;
color: #fff; color: #fff;

View File

@ -1,3 +1,9 @@
/*
[ ] build without polymer bundled
*/
var gulp = require( 'gulp' ), var gulp = require( 'gulp' ),
stylus = require( 'gulp-stylus' ), stylus = require( 'gulp-stylus' ),
nib = require( 'nib' ), nib = require( 'nib' ),
@ -5,29 +11,38 @@ var gulp = require( 'gulp' ),
vulcan = require( 'gulp-vulcanize' ); vulcan = require( 'gulp-vulcanize' );
var paths = { var paths = {
style: './elements/*.styl' style: 'elements/**/*.styl'
} }
function compileCSS( files ) { function compileCSS( files ) {
return files return files
.pipe( stylus( { use: [ nib() ] } ) ) .pipe( stylus( { use: [ nib() ] } ) )
.pipe( gulp.dest( './elements/' ) ); .pipe( gulp.dest( 'elements' ) );
} }
gulp.task( 'default', function() {
gulp.task( 'styles', function() {
compileCSS( gulp.src( paths.style ) ); compileCSS( gulp.src( paths.style ) );
gulp.src( './index.html' ) } );
gulp.task( 'vulcanize', function() {
gulp.src( 'index.html' )
.pipe( vulcan( { .pipe( vulcan( {
dest: 'build', dest: 'build',
inline: true, inline: true,
strip: true strip: true
} ) ); } ) );
} ); } );
gulp.task( 'watch', function() { gulp.task( 'watch', function() {
watch( { glob: paths.style }, compileCSS ); watch( { glob: paths.style }, compileCSS );
} ); } );
gulp.task( 'default', [ 'styles', 'vulcanize' ]);

View File

@ -4,9 +4,9 @@
<script src="components/platform/platform.js"></script> <script src="components/platform/platform.js"></script>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto" type="text/css"> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto" type="text/css">
<link rel="import" href="elements/gui-panel.html"> <link rel="import" href="elements/gui-panel/gui-panel.html">
<link rel="import" href="elements/gui-row.html"> <link rel="import" href="elements/gui-row/gui-row.html">
<link rel="import" href="elements/number-controller.html"> <link rel="import" href="elements/controller-number/controller-number.html">
</head> </head>
<body> <body>

View File

@ -14,7 +14,7 @@ document.addEventListener( 'polymer-ready', function() {
gui.add( object, 'listen4Free' ); gui.add( object, 'listen4Free' );
gui.add( object, 'listen4Free' ).name( 'customName' ); gui.add( object, 'listen4Free' ).name( 'customName' );
gui.add( object, 'step', 0, 50, 5 ); gui.add( object, 'step', 0, 50, 5 );
gui.add( object, 'straddleZero', -5, 5 ); gui.add( object, 'straddleZero', -1, 1, 0.01 );
var c = gui.add( object, 'maxIsNegative', -5, -2 ); var c = gui.add( object, 'maxIsNegative', -5, -2 );