Interface CanvasElement

All Superinterfaces:
DomQueryable, Element, EventTarget, Node

public interface CanvasElement extends Element
Interface that represents a canvas made up of pixels.

Canvases are rendered by displaying each pixel as its own TextDisplay entity. Thus, when using a canvas element, keep in mind the amount of entities that will be used to render the canvas.

  • Field Details

    • MIN_SIZE

      static final int MIN_SIZE
      Minimum allowed size for a canvas
      See Also:
    • MAX_SIZE

      static final int MAX_SIZE
      Maximum allowed size for a canvas.
      See Also:
    • DEFAULT_SIZE

      static final int DEFAULT_SIZE
      Default size of a canvas element
      See Also:
  • Method Details

    • canHaveChildren

      @Contract("-> false") boolean canHaveChildren()
      Canvas elements cannot have any child nodes.
      Specified by:
      canHaveChildren in interface Element
      Returns:
      false
    • getWidth

      int getWidth()
      Get the value of the Attributes.WIDTH attribute.

      If the attribute has no value, or is not a valid number, DEFAULT_SIZE is returned.

      Note: There is a brief window of time when the value returned by this method differs from getCanvas()'s Canvas.getWidth(). This happens when the attribute is changed, as canvas is updated after all attribute change listeners have been called.

      Returns:
      Width
    • setWidth

      void setWidth(int width) throws IllegalArgumentException
      Set the value of Attributes.WIDTH attribute.

      When called, the getCanvas()'s Canvas.getWidth() will not be updated instantly. All attribute update listeners will be called first, then the canvas' size will be updated.

      When a canvas' size is changed, the canvas is resized, and any existing image data is retained, but the image will be cropped if the size is changed to smaller value than it was before.

      Parameters:
      width - New width
      Throws:
      IllegalArgumentException - If width is less than MIN_SIZE or greater than MAX_SIZE.
    • getHeight

      int getHeight()
      Get the value of the Attributes.HEIGHT attribute.

      If the attribute has no value, or is not a valid number, DEFAULT_SIZE is returned.

      Note: There is a brief window of time when the value returned by this method differs from getCanvas()'s Canvas.getHeight(). This happens when the attribute is changed, as canvas is updated after all attribute change listeners have been called.

      Returns:
      Height
    • setHeight

      void setHeight(int height) throws IllegalArgumentException
      Set the value of Attributes.HEIGHT attribute.

      When called, the getCanvas()'s Canvas.getHeight() will not be updated instantly. All attribute update listeners will be called first, then the canvas' size will be updated.

      When a canvas' size is changed, the canvas is resized, and any existing image data is retained, but the image will be cropped if the size is changed to smaller value than it was before.

      Parameters:
      height - New height
      Throws:
      IllegalArgumentException - If height is less than MIN_SIZE or greater than MAX_SIZE.
    • getCanvas

      @NotNull @NotNull Canvas getCanvas()
      Get the canvas of this element.
      Returns:
      Canvas