Utilities¶
-
LC.util.addImageOnload(image, callback)¶ Ensures callback is called when the image loads, without replacing any existing callbacks.
-
LC.util.classSet({className: bool})¶ Replaces
React.addons.classSet.
-
LC.util.combineCanvases(a, b)¶ - Returns
A canvas containing b rendered on top of a, sized to contain both a and b.[]
-
LC.util.getBackingScale()¶ - Returns
window.devicePixelRatioif it exists and is greater than 1; otherwise, returns 1.
-
LC.util.getBoundingRect(rects)¶ - Arguments
rects – List of dicts with keys
{x, y, width, height}.
- Returns
The smallest rectangle that contains the given rectangles, in the form
{x, y, width, height}.
-
LC.util.getGUID()¶ - Returns
a globally unique ID string
-
LC.util.last(array, n=null)¶ Get the last element of an array. Pass n to get a list of the last n elements.
-
LC.util.matchElementSize(elementToMatch, elementsToResize, scale, callback=null)¶ - Arguments
elementToMatch – DOM element whose size should be matched by elementsToResize
elementsToResize – Array of DOM elements to update
scale – Amount to scale
widthandheightattributes if one of elementsToResize is a canvas elementcallback – Function to be called after each resize event
Keep elementsToResize the same size as elementToMatch. If one of elementsToResize is a
<canvas>, set itswidthandheightproperties to the element’s size multiplied by scale. (This is necessary for environments withdevicePixelRatio != 1.)
-
LC.util.getDefaultImageRect(shapeBoundingRects, explicitSize={width: 0, height: 0}, margin={top: 0, right: 0, bottom: 0, left: 0})¶ Returns the effective bounds of the canvas. Mostly used as a convenient way to limit the scope of a potentially infinite tool. (For example, a paint bucket shouldn’t fill infinite pixels.)
-
LC.util.renderShapes(shapes, bounds, scale=1, canvas=null)¶ Deprecated since version 0.4.5.
Duplicate of
LC.renderShapesToCanvas()