Skip to content

UIView

final class UIView
Package: dev.joid.lib.ui.core.view · Module: core · Source: UIView.java

Converts between the screen pixels of the window and the design pixels of a UI, from the window size, the anchor, the interface scale and the zoom.

Every UI has one view, returned by UI.getView. The view fits the 1920 × 1080 design canvas in the window without cropping it, then applies the interface scale and the zoom around the anchor. Use it to place your own drawing in screen pixels or to read where the window edges fall on the canvas.

ReturnsSignatureSummary
UIViewcreate(double anchorX, double anchorY) factoryCreates a view whose anchor is this point of the design canvas, for a 1920 × 1080 window, with no zoom and no interface scale.

PropertyTypeDefaultSummary
anchorXdoubleset at creationHorizontal position, in design pixels, of the anchor that the canvas zooms around and stays pinned to when the window shows more than the canvas.
anchorYdoubleset at creationVertical position, in design pixels, of the anchor that the canvas zooms around and stays pinned to.
zoomdouble1DZoom applied on top of the interface scale.
interfaceScaledouble1DFactor that the UI bridge applies to make every UI larger or smaller, after the @UIDataScale of the UI.

ReturnsSignatureSummary
doublegetWidth()Width of the window, in screen pixels.
doublegetHeight()Height of the window, in screen pixels.
ReturnsSignatureSummary
doublegetRequestedZoom()Returns the zoom asked for, before the bounds of clampZoom, by UI.zoom(...) or by zoom(...) of the view.
doublegetScale()The interface scale multiplied by the zoom.
doublegetOffsetX()Horizontal shift of the canvas inside the viewport, in design pixels, that keeps it pinned to its anchor when the window is wider than the canvas.
doublegetOffsetY()Vertical shift of the canvas inside the viewport, in design pixels, that keeps it pinned to its anchor when the window is taller than the canvas.
doublegetVisibleWidth()Width of the window measured in design pixels, after the scale.
doublegetVisibleHeight()Height of the window measured in design pixels, after the scale.
doubletoUiX(double screenX)Converts a horizontal position of the window, in screen pixels, to the design canvas.
doubletoUiY(double screenY)Converts a vertical position of the window, in screen pixels, to the design canvas.
doubletoScreenX(double uiX)Converts a horizontal position of the design canvas to the window, in screen pixels.
doubletoScreenY(double uiY)Converts a vertical position of the design canvas to the window, in screen pixels.
doubletoScreenWidth(double uiWidth)Converts a width in design pixels to screen pixels.
doubletoScreenHeight(double uiHeight)Converts a height in design pixels to screen pixels.
doublegetViewportWidth()Width of the window measured in design pixels at a scale of 1: at least 1920, larger when the window is wider than 16:9.
doublegetViewportHeight()Height of the window measured in design pixels at a scale of 1: at least 1080, larger when the window is taller than 16:9.
ReturnsSignatureSummary
doubleclampZoom(double zoom)Returns the zoom kept between 0.1D and the largest zoom that the interface scale allows: 1D, or 1D / interfaceScale when the scale is below 1D.
thisresize(double width, double height) fluentFits the view to a window of this size, in screen pixels.
voidrender(IRenderBridge render, boolean projection, Runnable draw)Runs the drawing in the coordinates of the design canvas.
TypeNameValueSummary
doubleDESIGN_WIDTH1920DWidth of the design canvas, in design pixels.
doubleDESIGN_HEIGHT1080DHeight of the design canvas, in design pixels.

UIView create(double anchorX, double anchorY) factory

Creates a view whose anchor is this point of the design canvas, for a 1920 × 1080 window, with no zoom and no interface scale. A UI creates its own view from its anchors.

  • this anchorX(double anchorX) fluent
  • double getAnchorX()

Default: set at creation

Horizontal position, in design pixels, of the anchor that the canvas zooms around and stays pinned to when the window shows more than the canvas.

  • this anchorY(double anchorY) fluent
  • double getAnchorY()

Default: set at creation

Vertical position, in design pixels, of the anchor that the canvas zooms around and stays pinned to.

  • this zoom(double zoom) fluent
  • double getZoom()

Default: 1D

Zoom applied on top of the interface scale. The view keeps the value asked for, even beyond the bounds, and getZoom() returns it kept within clampZoom; unlike UI.zoom(double), writing it here runs no listener.

  • this interfaceScale(double interfaceScale) fluent
  • double getInterfaceScale()

Default: 1D

Factor that the UI bridge applies to make every UI larger or smaller, after the @UIDataScale of the UI.

double getWidth()

Width of the window, in screen pixels.

double getHeight()

Height of the window, in screen pixels.

double getRequestedZoom()

Returns the zoom asked for, before the bounds of clampZoom, by UI.zoom(...) or by zoom(...) of the view. A value written to the view that equals the zoom shown keeps a request of UI.zoom(...) for the next change of interface scale, while getRequestedZoom() returns the value written.

double getScale()

The interface scale multiplied by the zoom.

double getOffsetX()

Horizontal shift of the canvas inside the viewport, in design pixels, that keeps it pinned to its anchor when the window is wider than the canvas.

double getOffsetY()

Vertical shift of the canvas inside the viewport, in design pixels, that keeps it pinned to its anchor when the window is taller than the canvas.

double getVisibleWidth()

Width of the window measured in design pixels, after the scale.

double getVisibleHeight()

Height of the window measured in design pixels, after the scale.

double toUiX(double screenX)

Converts a horizontal position of the window, in screen pixels, to the design canvas.

double toUiY(double screenY)

Converts a vertical position of the window, in screen pixels, to the design canvas.

double toScreenX(double uiX)

Converts a horizontal position of the design canvas to the window, in screen pixels.

double toScreenY(double uiY)

Converts a vertical position of the design canvas to the window, in screen pixels.

double toScreenWidth(double uiWidth)

Converts a width in design pixels to screen pixels.

double toScreenHeight(double uiHeight)

Converts a height in design pixels to screen pixels.

double getViewportWidth()

Width of the window measured in design pixels at a scale of 1: at least 1920, larger when the window is wider than 16:9.

double getViewportHeight()

Height of the window measured in design pixels at a scale of 1: at least 1080, larger when the window is taller than 16:9.

double clampZoom(double zoom)

Returns the zoom kept between 0.1D and the largest zoom that the interface scale allows: 1D, or 1D / interfaceScale when the scale is below 1D.

this resize(double width, double height) fluent

Fits the view to a window of this size, in screen pixels. A size of 0 or below, such as a minimized window, is ignored.

void render(IRenderBridge render, boolean projection, Runnable draw)

Runs the drawing in the coordinates of the design canvas. If projection is true, it also sets an orthographic projection on the viewport; if false, it keeps the projection of the caller and applies only the offset, the scale and the zoom.

double DESIGN_WIDTH

Width of the design canvas, in design pixels.

double DESIGN_HEIGHT

Height of the design canvas, in design pixels.


fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses

Report a problem with this page