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.
Description
Section titled “Description”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.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
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. |
Properties
Section titled “Properties”| Property | Type | Default | Summary |
|---|---|---|---|
| anchorX | double | 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. |
| anchorY | double | set at creation | Vertical position, in design pixels, of the anchor that the canvas zooms around and stays pinned to. |
| zoom | double | 1D | Zoom applied on top of the interface scale. |
| interfaceScale | double | 1D | Factor that the UI bridge applies to make every UI larger or smaller, after the @UIDataScale of the UI. |
Methods
Section titled “Methods”Position and size
Section titled “Position and size”| Returns | Signature | Summary |
|---|---|---|
double | getWidth() | Width of the window, in screen pixels. |
double | getHeight() | Height of the window, in screen pixels. |
Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
double | getRequestedZoom() | Returns the zoom asked for, before the bounds of clampZoom, by UI.zoom(...) or by zoom(...) of the view. |
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. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
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. |
void | render(IRenderBridge render, boolean projection, Runnable draw) | Runs the drawing in the coordinates of the design canvas. |
Constants and fields
Section titled “Constants and fields”| Type | Name | Value | Summary |
|---|---|---|---|
double | DESIGN_WIDTH | 1920D | Width of the design canvas, in design pixels. |
double | DESIGN_HEIGHT | 1080D | Height of the design canvas, in design pixels. |
Creation details
Section titled “Creation details”create
Section titled “create”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.
Property details
Section titled “Property details”anchorX
Section titled “anchorX”this anchorX(double anchorX)fluentdouble 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.
anchorY
Section titled “anchorY”this anchorY(double anchorY)fluentdouble 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)fluentdouble 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.
interfaceScale
Section titled “interfaceScale”this interfaceScale(double interfaceScale)fluentdouble getInterfaceScale()
Default: 1D
Factor that the UI bridge applies to make every UI larger or smaller, after the @UIDataScale of the UI.
Method details
Section titled “Method details”getWidth
Section titled “getWidth”double getWidth()
Width of the window, in screen pixels.
getHeight
Section titled “getHeight”double getHeight()
Height of the window, in screen pixels.
getRequestedZoom
Section titled “getRequestedZoom”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.
getScale
Section titled “getScale”double getScale()
The interface scale multiplied by the zoom.
getOffsetX
Section titled “getOffsetX”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.
getOffsetY
Section titled “getOffsetY”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.
getVisibleWidth
Section titled “getVisibleWidth”double getVisibleWidth()
Width of the window measured in design pixels, after the scale.
getVisibleHeight
Section titled “getVisibleHeight”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.
toScreenX
Section titled “toScreenX”double toScreenX(double uiX)
Converts a horizontal position of the design canvas to the window, in screen pixels.
toScreenY
Section titled “toScreenY”double toScreenY(double uiY)
Converts a vertical position of the design canvas to the window, in screen pixels.
toScreenWidth
Section titled “toScreenWidth”double toScreenWidth(double uiWidth)
Converts a width in design pixels to screen pixels.
toScreenHeight
Section titled “toScreenHeight”double toScreenHeight(double uiHeight)
Converts a height in design pixels to screen pixels.
getViewportWidth
Section titled “getViewportWidth”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.
getViewportHeight
Section titled “getViewportHeight”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.
clampZoom
Section titled “clampZoom”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.
resize
Section titled “resize”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.
render
Section titled “render”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.
Constant and field details
Section titled “Constant and field details”DESIGN_WIDTH
Section titled “DESIGN_WIDTH”double DESIGN_WIDTH
Width of the design canvas, in design pixels.
DESIGN_HEIGHT
Section titled “DESIGN_HEIGHT”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
