mirror of
https://github.com/nasa/openmct.git
synced 2025-05-06 02:28:21 +00:00
[Fixed Position] Add handles for line end points
Add handles for moving line end points in fixed position view, WTD-882.
This commit is contained in:
parent
11360ba46c
commit
6efccc0784
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*/
|
/*global define*/
|
||||||
|
|
||||||
define(
|
define(
|
||||||
['./ElementProxy'],
|
['./ElementProxy', './LineHandle'],
|
||||||
function (ElementProxy) {
|
function (ElementProxy, LineHandle) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,7 +15,11 @@ define(
|
|||||||
* @param {Array} elements the full array of elements
|
* @param {Array} elements the full array of elements
|
||||||
*/
|
*/
|
||||||
function LineProxy(element, index, 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
|
* Get the top-left x coordinate, in grid space, of
|
||||||
@ -105,6 +109,15 @@ define(
|
|||||||
return element.y2 - proxy.y();
|
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;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user