mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 07:38:15 +00:00
Merge branch 'open940b' into open929
Merge in Fixed Position updates to reconcile conflicts related to generalization of selection mechanism, WTD-929. Conflicts: platform/features/layout/src/FixedController.js platform/features/layout/test/FixedControllerSpec.js
This commit is contained in:
@ -8,14 +8,26 @@ define(
|
||||
/**
|
||||
* Utility function for creating getter-setter functions,
|
||||
* since these are frequently useful for element proxies.
|
||||
*
|
||||
* An optional third argument may be supplied in order to
|
||||
* constrain or modify arguments when using as a setter;
|
||||
* this argument is a function which takes two arguments
|
||||
* (the current value for the property, and the requested
|
||||
* new value.) This is useful when values need to be kept
|
||||
* in certain ranges; specifically, to keep x/y positions
|
||||
* non-negative in a fixed position view.
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} object the object to get/set values upon
|
||||
* @param {string} key the property to get/set
|
||||
* @param {function} [updater] function used to process updates
|
||||
*/
|
||||
function AccessorMutator(object, key) {
|
||||
function AccessorMutator(object, key, updater) {
|
||||
return function (value) {
|
||||
if (arguments.length > 0) {
|
||||
object[key] = value;
|
||||
object[key] = updater ?
|
||||
updater(value, object[key]) :
|
||||
value;
|
||||
}
|
||||
return object[key];
|
||||
};
|
||||
|
@ -24,7 +24,7 @@ define(
|
||||
"fixed.text": {
|
||||
fill: "transparent",
|
||||
stroke: "transparent",
|
||||
color: "#717171"
|
||||
color: "#cccccc"
|
||||
}
|
||||
},
|
||||
DIALOGS = {
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
['./AccessorMutator'],
|
||||
function (AccessorMutator) {
|
||||
['./AccessorMutator', './ResizeHandle'],
|
||||
function (AccessorMutator, ResizeHandle) {
|
||||
"use strict";
|
||||
|
||||
// Index deltas for changes in order
|
||||
@ -13,6 +13,11 @@ define(
|
||||
bottom: Number.NEGATIVE_INFINITY
|
||||
};
|
||||
|
||||
// Ensure a value is non-negative (for x/y setters)
|
||||
function clamp(value) {
|
||||
return Math.max(value, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract superclass for other classes which provide useful
|
||||
* interfaces upon an elements in a fixed position view.
|
||||
@ -29,6 +34,8 @@ define(
|
||||
* @param {Array} elements the full array of elements
|
||||
*/
|
||||
function ElementProxy(element, index, elements) {
|
||||
var handles = [ new ResizeHandle(element, 1, 1) ];
|
||||
|
||||
return {
|
||||
/**
|
||||
* The element as stored in the view configuration.
|
||||
@ -40,14 +47,14 @@ define(
|
||||
* @param {number} [x] the new x position (if setting)
|
||||
* @returns {number} the x position
|
||||
*/
|
||||
x: new AccessorMutator(element, 'x'),
|
||||
x: new AccessorMutator(element, 'x', clamp),
|
||||
/**
|
||||
* Get and/or set the y position of this element.
|
||||
* Units are in fixed position grid space.
|
||||
* @param {number} [y] the new y position (if setting)
|
||||
* @returns {number} the y position
|
||||
*/
|
||||
y: new AccessorMutator(element, 'y'),
|
||||
y: new AccessorMutator(element, 'y', clamp),
|
||||
/**
|
||||
* Get and/or set the stroke color of this element.
|
||||
* @param {string} [stroke] the new stroke color (if setting)
|
||||
@ -97,6 +104,13 @@ define(
|
||||
if (elements[index] === element) {
|
||||
elements.splice(index, 1);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Get handles to control specific features of this element,
|
||||
* e.g. corner size.
|
||||
*/
|
||||
handles: function () {
|
||||
return handles;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
61
platform/features/layout/src/elements/LineHandle.js
Normal file
61
platform/features/layout/src/elements/LineHandle.js
Normal file
@ -0,0 +1,61 @@
|
||||
/*global define*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Handle for changing x/y position of a line's end point.
|
||||
* This is used to support drag handles for line elements
|
||||
* in a fixed position view. Field names for opposite ends
|
||||
* are provided to avoid zero-length lines.
|
||||
* @constructor
|
||||
* @param element the line element
|
||||
* @param {string} xProperty field which stores x position
|
||||
* @param {string} yProperty field which stores x position
|
||||
* @param {string} xOther field which stores x of other end
|
||||
* @param {string} yOther field which stores y of other end
|
||||
*/
|
||||
function LineHandle(element, xProperty, yProperty, xOther, yOther) {
|
||||
return {
|
||||
/**
|
||||
* Get/set the x position of the lower-right corner
|
||||
* of the handle-controlled element, changing size
|
||||
* as necessary.
|
||||
*/
|
||||
x: function (value) {
|
||||
if (arguments.length > 0) {
|
||||
// Ensure we stay in view
|
||||
value = Math.max(value, 0);
|
||||
// Make sure end points will still be different
|
||||
if (element[yOther] !== element[yProperty] ||
|
||||
element[xOther] !== value) {
|
||||
element[xProperty] = value;
|
||||
}
|
||||
}
|
||||
return element[xProperty];
|
||||
},
|
||||
/**
|
||||
* Get/set the y position of the lower-right corner
|
||||
* of the handle-controlled element, changing size
|
||||
* as necessary.
|
||||
*/
|
||||
y: function (value) {
|
||||
if (arguments.length > 0) {
|
||||
// Ensure we stay in view
|
||||
value = Math.max(value, 0);
|
||||
// Make sure end points will still be different
|
||||
if (element[xOther] !== element[xProperty] ||
|
||||
element[yOther] !== value) {
|
||||
element[yProperty] = value;
|
||||
}
|
||||
}
|
||||
return element[yProperty];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return LineHandle;
|
||||
|
||||
}
|
||||
);
|
@ -1,8 +1,8 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
['./ElementProxy'],
|
||||
function (ElementProxy) {
|
||||
['./ElementProxy', './LineHandle'],
|
||||
function (ElementProxy, LineHandle) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@ -15,7 +15,11 @@ define(
|
||||
* @param {Array} elements the full array of elements
|
||||
*/
|
||||
function LineProxy(element, index, elements) {
|
||||
var proxy = new ElementProxy(element, index, elements);
|
||||
var proxy = new ElementProxy(element, index, elements),
|
||||
handles = [
|
||||
new LineHandle(element, 'x', 'y', 'x2', 'y2'),
|
||||
new LineHandle(element, 'x2', 'y2', 'x', 'y')
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the top-left x coordinate, in grid space, of
|
||||
@ -24,7 +28,7 @@ define(
|
||||
*/
|
||||
proxy.x = function (v) {
|
||||
var x = Math.min(element.x, element.x2),
|
||||
delta = v - x;
|
||||
delta = Math.max(v, 0) - x;
|
||||
if (arguments.length > 0 && delta) {
|
||||
element.x += delta;
|
||||
element.x2 += delta;
|
||||
@ -39,7 +43,7 @@ define(
|
||||
*/
|
||||
proxy.y = function (v) {
|
||||
var y = Math.min(element.y, element.y2),
|
||||
delta = v - y;
|
||||
delta = Math.max(v, 0) - y;
|
||||
if (arguments.length > 0 && delta) {
|
||||
element.y += delta;
|
||||
element.y2 += delta;
|
||||
@ -105,6 +109,15 @@ define(
|
||||
return element.y2 - proxy.y();
|
||||
};
|
||||
|
||||
/**
|
||||
* Get element handles for changing the position of end
|
||||
* points of this line.
|
||||
* @returns {LineHandle[]} line handles for both end points
|
||||
*/
|
||||
proxy.handles = function () {
|
||||
return handles;
|
||||
};
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
53
platform/features/layout/src/elements/ResizeHandle.js
Normal file
53
platform/features/layout/src/elements/ResizeHandle.js
Normal file
@ -0,0 +1,53 @@
|
||||
/*global define*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Handle for changing width/height properties of an element.
|
||||
* This is used to support drag handles for different
|
||||
* element types in a fixed position view.
|
||||
* @constructor
|
||||
*/
|
||||
function ResizeHandle(element, minWidth, minHeight) {
|
||||
// Ensure reasonable defaults
|
||||
minWidth = minWidth || 0;
|
||||
minHeight = minHeight || 0;
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get/set the x position of the lower-right corner
|
||||
* of the handle-controlled element, changing size
|
||||
* as necessary.
|
||||
*/
|
||||
x: function (value) {
|
||||
if (arguments.length > 0) {
|
||||
element.width = Math.max(
|
||||
minWidth,
|
||||
value - element.x
|
||||
);
|
||||
}
|
||||
return element.x + element.width;
|
||||
},
|
||||
/**
|
||||
* Get/set the y position of the lower-right corner
|
||||
* of the handle-controlled element, changing size
|
||||
* as necessary.
|
||||
*/
|
||||
y: function (value) {
|
||||
if (arguments.length > 0) {
|
||||
element.height = Math.max(
|
||||
minHeight,
|
||||
value - element.y
|
||||
);
|
||||
}
|
||||
return element.y + element.height;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return ResizeHandle;
|
||||
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user