mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
Fixed constraints on slider and made fixes to css
This commit is contained in:
parent
5170f5934d
commit
ad26e4835a
@ -8,8 +8,9 @@ var NumberController = function() {
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
// If we simply click and release a number field, we want to highlight it.
|
// If we simply click and release a number field, we want to highlight it.
|
||||||
// This variable keeps track of whether or not we've draggedNumberField.
|
// This variable keeps track of whether or not we've dragged
|
||||||
var draggedNumberField = false;
|
var draggedNumberField = false;
|
||||||
|
|
||||||
var clickedNumberField = false;
|
var clickedNumberField = false;
|
||||||
|
|
||||||
var y = py = 0;
|
var y = py = 0;
|
||||||
@ -99,6 +100,8 @@ var NumberController = function() {
|
|||||||
var dy = py - y;
|
var dy = py - y;
|
||||||
var newVal = _this.getValue() + dy*step;
|
var newVal = _this.getValue() + dy*step;
|
||||||
_this.updateValue(newVal);
|
_this.updateValue(newVal);
|
||||||
|
|
||||||
|
console.log(newVal);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,9 +109,9 @@ var NumberController = function() {
|
|||||||
|
|
||||||
val = parseFloat(val);
|
val = parseFloat(val);
|
||||||
|
|
||||||
if (min && val <= min) {
|
if (min != undefined && val <= min) {
|
||||||
val = min;
|
val = min;
|
||||||
} else if (max && val >= max) {
|
} else if (max != undefined && val >= max) {
|
||||||
val = max;
|
val = max;
|
||||||
}
|
}
|
||||||
_this.setValue(val);
|
_this.setValue(val);
|
||||||
|
@ -13,15 +13,17 @@ var Slider = function(numberController, min, max, step, initValue) {
|
|||||||
var x, px;
|
var x, px;
|
||||||
|
|
||||||
this.domElement = document.createElement('div');
|
this.domElement = document.createElement('div');
|
||||||
this.domElement.setAttribute('class', 'guidat-slider-bg');
|
|
||||||
|
|
||||||
this.fg = document.createElement('div');
|
this.fg = document.createElement('div');
|
||||||
|
this.domElement.setAttribute('class', 'guidat-slider-bg');
|
||||||
this.fg.setAttribute('class', 'guidat-slider-fg');
|
this.fg.setAttribute('class', 'guidat-slider-fg');
|
||||||
|
|
||||||
this.domElement.appendChild(this.fg);
|
this.domElement.appendChild(this.fg);
|
||||||
|
|
||||||
var map = function(v, i1, i2, o1, o2) {
|
var map = function(v, i1, i2, o1, o2) {
|
||||||
return o1 + (o2 - o1) * ((v - i1) / (i2 - i1));
|
var v = o1 + (o2 - o1) * ((v - i1) / (i2 - i1));
|
||||||
|
if (v < o1) v = o1;
|
||||||
|
else if (v > o2) v = o2;
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
var findPos = function(obj) {
|
var findPos = function(obj) {
|
||||||
@ -53,11 +55,15 @@ var Slider = function(numberController, min, max, step, initValue) {
|
|||||||
this.domElement.addEventListener('mousedown', function(e) {
|
this.domElement.addEventListener('mousedown', function(e) {
|
||||||
clicked = true;
|
clicked = true;
|
||||||
x = px = e.pageX;
|
x = px = e.pageX;
|
||||||
|
_this.domElement.setAttribute('class', 'guidat-slider-bg active');
|
||||||
|
_this.fg.setAttribute('class', 'guidat-slider-fg active');
|
||||||
onDrag(e);
|
onDrag(e);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
|
||||||
this.domElement.addEventListener('mouseup', function(e) {
|
document.addEventListener('mouseup', function(e) {
|
||||||
|
_this.domElement.setAttribute('class', 'guidat-slider-bg');
|
||||||
|
_this.fg.setAttribute('class', 'guidat-slider-fg');
|
||||||
clicked = false;
|
clicked = false;
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
1
demo.css
1
demo.css
@ -18,7 +18,6 @@ h1 {
|
|||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
text-transform: lowercase;
|
text-transform: lowercase;
|
||||||
line-height: 80px;
|
line-height: 80px;
|
||||||
text-shadow: 2px 2px 2px #ccc;
|
|
||||||
margin: 20px 0 20px 0;
|
margin: 20px 0 20px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
gui.css
23
gui.css
@ -1,12 +1,12 @@
|
|||||||
#guidat {
|
#guidat {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
width: 320px;
|
width: 280px;
|
||||||
z-index: 200;
|
z-index: 200;
|
||||||
opacity: 0.97;
|
opacity: 0.97;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 100%;
|
left: 100%;
|
||||||
margin-left: -340px;
|
margin-left: -300px;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
-moz-transition: margin-top .2s ease-out;
|
-moz-transition: margin-top .2s ease-out;
|
||||||
-webkit-transition: margin-top .2s ease-out;
|
-webkit-transition: margin-top .2s ease-out;
|
||||||
@ -85,7 +85,7 @@
|
|||||||
border: 0;
|
border: 0;
|
||||||
color: #1ed36f;
|
color: #1ed36f;
|
||||||
margin-right: 2px;
|
margin-right: 2px;
|
||||||
width: 170px;
|
width: 53%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.guidat-controller.boolean {
|
.guidat-controller.boolean {
|
||||||
@ -103,12 +103,9 @@ width: 170px;
|
|||||||
color: #00aeff;
|
color: #00aeff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.guidat-controller.number input[type=slider] {
|
|
||||||
width: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#guidat .guidat-controller.boolean input {
|
#guidat .guidat-controller.boolean input {
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
|
margin-right: 2px;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,10 +123,20 @@ width: 170px;
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.guidat-slider-bg:hover {
|
||||||
|
background-color: #444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.guidat-slider-bg:hover
|
||||||
|
.guidat-slider-fg {
|
||||||
|
background-color: #52c8ff;
|
||||||
|
}
|
||||||
|
|
||||||
.guidat-slider-bg {
|
.guidat-slider-bg {
|
||||||
background-color: #222;
|
background-color: #222;
|
||||||
cursor: ew-resize;
|
cursor: ew-resize;
|
||||||
width: 130px;
|
width: 40%;
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
float: right;
|
float: right;
|
||||||
height: 21px;
|
height: 21px;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
{
|
{
|
||||||
numberProperty: 20,
|
numberProperty: 20,
|
||||||
constrainedNum: 0,
|
constrainedNum: 0,
|
||||||
notchedNum: 240,
|
notchedNum: 200,
|
||||||
textProperty: "a string",
|
textProperty: "a string",
|
||||||
anotherTextProperty: "another string",
|
anotherTextProperty: "another string",
|
||||||
booleanProperty: false,
|
booleanProperty: false,
|
||||||
@ -43,7 +43,7 @@
|
|||||||
GUI.add(controllableObject, "constrainedNum", -100, 100)
|
GUI.add(controllableObject, "constrainedNum", -100, 100)
|
||||||
|
|
||||||
// Creates a slider with notches
|
// Creates a slider with notches
|
||||||
GUI.add(controllableObject, "notchedNum", 0, 800, 20)
|
GUI.add(controllableObject, "notchedNum", 0, 800, 100)
|
||||||
|
|
||||||
// Creates a text field
|
// Creates a text field
|
||||||
GUI.add(controllableObject, "textProperty");
|
GUI.add(controllableObject, "textProperty");
|
||||||
@ -89,7 +89,7 @@ window.onload = function() {
|
|||||||
GUI.add(controllableObject, "constrainedNum", -100, 100)
|
GUI.add(controllableObject, "constrainedNum", -100, 100)
|
||||||
|
|
||||||
// Creates a slider with notches
|
// Creates a slider with notches
|
||||||
GUI.add(controllableObject, "notchedNum", 0, 800, 20)
|
GUI.add(controllableObject, "notchedNum", 0, 800, 100)
|
||||||
|
|
||||||
// Creates a text field
|
// Creates a text field
|
||||||
GUI.add(controllableObject, "textProperty");
|
GUI.add(controllableObject, "textProperty");
|
||||||
|
Loading…
Reference in New Issue
Block a user