![]() |
Lysa UI
0.0
Lysa UI —UI components for the Lysa Engine
|
Lysa UI uses a resolution-independent unit coordinate space for all widget positions, sizes, and drawing operations. Understanding this space is essential when placing windows, sizing widgets, or working with mouse input events.
The 2D renderer maps the visible surface to a fixed logical range of 1000 × 1000 units, regardless of the actual pixel dimensions of the rendering window.
Every coordinate you pass to Rect, setRect(), setSize(), or the drawing primitives (drawFilledRect, drawText, drawLine) is expressed in these 1000-unit coordinates.
A widget that is 500 units wide therefore always occupies exactly half the screen width, no matter the resolution.
The coordinate system is Y-up with the origin at the bottom-left corner of the rendering surface:
This matches the convention used by lysa::Rect as defined in the engine:
A Rect at {0, 0, 200, 100} therefore starts at the bottom-left corner and extends 200 units to the right and 100 units upward.
lysa::Rect is the fundamental building block for window and widget placement.
Within a widget tree, each child's Rect is expressed in the same absolute unit space as its parent window. Child alignment (via lysa::ui::Alignment) is calculated by the layout engine relative to the parent's content area, but the resulting Rect stored on the child is always in absolute units.
You can query or override a widget's rectangle at any time:
getWidth() and getHeight() are convenience accessors that return the same rect.width and rect.height values, also in units.
Raw mouse events from the OS arrive in pixels relative to the client area. WindowManager converts them to unit coordinates before routing to widgets:
The virtual event handlers on Widget and Window therefore receive coordinates already expressed in the same 1000-unit space as the widget rectangles:
Similarly, the UIEventMouseButton and UIEventMouseMove payloads delivered through the engine event system carry unit-space coordinates:
Because both axes are mapped independently to 1000 units, a widget with width == height in unit space will appear wider than tall on a landscape display. This is by design: unit coordinates express fractions of each axis independently.
If you need to account for the actual pixel proportions (e.g. to draw a circle or a square that looks square on screen), retrieve the renderer's aspect ratio (or the Scene renderer's aspect ratio) and use it to calculate the desired size :
Use the special constant lysa::RECT_FULLSCREEN to creates a window that automatically covers the entire unit surface regardless of the actual resolution: