|
@@ -37,11 +37,7 @@ class PropsEditor extends Component {
|
|
|
e = e.wrap("<div></div>").parent(); // necessary to have find working on top level element
|
|
|
|
|
|
e.find("input[type=checkbox]").wrap("<div class='checkbox-wrapper'></div>");
|
|
|
-
|
|
|
- for( s in e.find("input[type=range]").not("[step]").elements() ) {
|
|
|
- var range = Std.parseFloat(s.attr("max")) - Std.parseFloat(s.attr("min"));
|
|
|
- s.attr("step", ""+hxd.Math.fmt(range/200));
|
|
|
- }
|
|
|
+ e.find("input[type=range]").not("[step]").attr("step", "any");
|
|
|
|
|
|
// -- reload states ---
|
|
|
for( h in e.find(".section > h1").elements() )
|
|
@@ -148,32 +144,49 @@ class PropsField extends Component {
|
|
|
onChange(false);
|
|
|
}
|
|
|
return;
|
|
|
- default:
|
|
|
- }
|
|
|
+ case "range":
|
|
|
|
|
|
- if( f.is("select") ) {
|
|
|
- enumValue = Type.getEnum(current);
|
|
|
- if( enumValue != null && f.find("option").length == 0 ) {
|
|
|
- for( c in enumValue.getConstructors() )
|
|
|
- new Element('<option value="$c">$c</option>').appendTo(f);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var inputView = null;
|
|
|
- if( f.is("[type=range]") ) {
|
|
|
f.wrap('<div class="range-group"/>');
|
|
|
var p = f.parent();
|
|
|
+ var inputView = new Element('<input type="text">').appendTo(p);
|
|
|
+ var originMin = Std.parseFloat(f.attr("min"));
|
|
|
+ var originMax = Std.parseFloat(f.attr("max"));
|
|
|
+ var curMin = originMin, curMax = originMax;
|
|
|
+
|
|
|
+ function setVal( v : Float ) {
|
|
|
+ var tempChange = tempChange;
|
|
|
+ this.setVal(v);
|
|
|
+
|
|
|
+ if( tempChange )
|
|
|
+ return;
|
|
|
+
|
|
|
+ if( v < curMin ) {
|
|
|
+ curMin = Math.floor(v);
|
|
|
+ f.attr("min", curMin);
|
|
|
+ }
|
|
|
+ if( v > curMax ) {
|
|
|
+ curMax = Math.ceil(v);
|
|
|
+ f.attr("max", curMax);
|
|
|
+ }
|
|
|
+ if( v >= originMin && v <= originMax ) {
|
|
|
+ f.attr("min", originMin);
|
|
|
+ f.attr("max", originMax);
|
|
|
+ curMin = originMin;
|
|
|
+ curMax = originMax;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
var original = current;
|
|
|
p.parent().prev("dt").contextmenu(function(e) {
|
|
|
e.preventDefault();
|
|
|
new ContextMenu([
|
|
|
- { label : "Reset", click : function() { f.val(original); f.change(); } },
|
|
|
+ { label : "Reset", click : function() { inputView.val(""+original); inputView.change(); } },
|
|
|
{ label : "Cancel", click : function() {} },
|
|
|
]);
|
|
|
return false;
|
|
|
});
|
|
|
- inputView = new Element('<input type="text">').appendTo(p);
|
|
|
- inputView.val(current);
|
|
|
+
|
|
|
+ f.on("input", function(_) { tempChange = true; f.change(); });
|
|
|
inputView.keyup(function(e) {
|
|
|
if( e.keyCode == 13 || e.keyCode == 27 ) {
|
|
|
inputView.blur();
|
|
@@ -181,67 +194,87 @@ class PropsField extends Component {
|
|
|
return;
|
|
|
}
|
|
|
var v = Std.parseFloat(inputView.val());
|
|
|
- if( !Math.isNaN(v) ) {
|
|
|
- f.val(v);
|
|
|
- f.change();
|
|
|
- }
|
|
|
+ if( Math.isNaN(v) ) return;
|
|
|
+ setVal(v);
|
|
|
+ f.val(v);
|
|
|
});
|
|
|
- f.on("input", function(_) { tempChange = true; f.change(); });
|
|
|
- }
|
|
|
|
|
|
- f.val(current);
|
|
|
- f.keyup(function(e) {
|
|
|
- if( e.keyCode == 13 ) {
|
|
|
- f.blur();
|
|
|
- return;
|
|
|
- }
|
|
|
- if( e.keyCode == 27 ) {
|
|
|
- f.blur();
|
|
|
- return;
|
|
|
- }
|
|
|
- tempChange = true;
|
|
|
- f.change();
|
|
|
- });
|
|
|
- f.change(function(e) {
|
|
|
+ f.val(current);
|
|
|
+ inputView.val(current);
|
|
|
|
|
|
- var newVal : Dynamic = f.val();
|
|
|
+ f.change(function(e) {
|
|
|
|
|
|
- if( f.is("[type=range]") || f.is("[type=number]") )
|
|
|
- newVal = Std.parseFloat(newVal);
|
|
|
+ var v = Math.round(Std.parseFloat(f.val()) * 100) / 100;
|
|
|
+ setVal(v);
|
|
|
+ inputView.val(v);
|
|
|
|
|
|
- if( enumValue != null )
|
|
|
- newVal = Type.createEnum(enumValue, newVal);
|
|
|
+ });
|
|
|
|
|
|
- if( f.is("select") ) f.blur();
|
|
|
+ default:
|
|
|
+ if( f.is("select") ) {
|
|
|
+ enumValue = Type.getEnum(current);
|
|
|
+ if( enumValue != null && f.find("option").length == 0 ) {
|
|
|
+ for( c in enumValue.getConstructors() )
|
|
|
+ new Element('<option value="$c">$c</option>').appendTo(f);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if( current == newVal ) {
|
|
|
- if( tempChange || beforeTempChange == null )
|
|
|
+ f.val(current);
|
|
|
+ f.keyup(function(e) {
|
|
|
+ if( e.keyCode == 13 ) {
|
|
|
+ f.blur();
|
|
|
return;
|
|
|
- current = beforeTempChange.value;
|
|
|
- beforeTempChange = null;
|
|
|
- }
|
|
|
+ }
|
|
|
+ if( e.keyCode == 27 ) {
|
|
|
+ f.blur();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ tempChange = true;
|
|
|
+ f.change();
|
|
|
+ });
|
|
|
+ f.change(function(e) {
|
|
|
|
|
|
- if( inputView != null )
|
|
|
- inputView.val(newVal);
|
|
|
+ var newVal : Dynamic = f.val();
|
|
|
|
|
|
- if( tempChange ) {
|
|
|
- tempChange = false;
|
|
|
- if( beforeTempChange == null ) beforeTempChange = { value : current };
|
|
|
- }
|
|
|
- else {
|
|
|
- props.undo.change(Field(context, fname, current), function() {
|
|
|
- var f = resolveField();
|
|
|
- f.current = Reflect.field(f.context, fname);
|
|
|
- f.root.val(f.current);
|
|
|
- if( inputView != null )
|
|
|
- f.root.parent().find("input[type=text]").val(f.current);
|
|
|
- f.onChange(true);
|
|
|
- });
|
|
|
- }
|
|
|
- current = newVal;
|
|
|
- Reflect.setProperty(context, fname, newVal);
|
|
|
- onChange(false);
|
|
|
- });
|
|
|
+ if( f.is("[type=number]") )
|
|
|
+ newVal = Std.parseFloat(newVal);
|
|
|
+
|
|
|
+ if( enumValue != null )
|
|
|
+ newVal = Type.createEnum(enumValue, newVal);
|
|
|
+
|
|
|
+ if( f.is("select") )
|
|
|
+ f.blur();
|
|
|
+
|
|
|
+ setVal(newVal);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function setVal(v) {
|
|
|
+ if( current == v ) {
|
|
|
+ // delay history save until last change
|
|
|
+ if( tempChange || beforeTempChange == null )
|
|
|
+ return;
|
|
|
+ current = beforeTempChange.value;
|
|
|
+ beforeTempChange = null;
|
|
|
+ }
|
|
|
+ if( tempChange ) {
|
|
|
+ tempChange = false;
|
|
|
+ if( beforeTempChange == null ) beforeTempChange = { value : current };
|
|
|
+ } else {
|
|
|
+ props.undo.change(Field(context, fname, current), function() {
|
|
|
+ var f = resolveField();
|
|
|
+ var v = Reflect.field(f.context, fname);
|
|
|
+ f.current = v;
|
|
|
+ f.root.val(v);
|
|
|
+ f.root.parent().find("input[type=text]").val(v);
|
|
|
+ f.onChange(true);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ current = v;
|
|
|
+ Reflect.setProperty(context, fname, v);
|
|
|
+ onChange(false);
|
|
|
}
|
|
|
|
|
|
public dynamic function onChange( wasUndo : Bool ) {
|