UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Ui Module / Responsive Layout System Completed

Ui Module — UGTK

Responsive Rect

Summary

Mn_ResponsiveRect makes a child element automatically adapt whenever its RectTransform changes size — no LayoutGroup required. It applies percentage-based horizontal/vertical padding to the content and can auto-scale TMP text sizes to the current height. Works in editor and at runtime.


Content


Modules Dependencies

This module has no hard UGTK dependencies. Text auto-scaling (TMP_Text) is compiled only when the TMP_PRESENT define is set (TextMesh Pro present).


Setup

No prefab and no scene ship with this module, so there is nothing to record: add Mn_ResponsiveRect to a UI object and it configures itself on Reset.


How To Use

Good to know:


Testing Scene

Open Debug/ResponsiveScene.unity. A dark Root panel fills most of the canvas and carries Mn_ResponsiveRect; an orange Content panel sits inside it. The padding between the two is the component's whole output, so the orange rectangle is the readout.

What to do, in order:

  1. Select Root and read Editor Test Tools → Root: the size the padding is derived from.
  2. Drag Horizontal Padding Percent and Vertical Padding Percent. The orange panel follows at once, with the editor stopped.
  3. Switch the Game view resolution from Full HD to a portrait one. The padding follows the new shape, because it is a percentage and not a number of pixels.
  4. Switch back, and press ApplyNow(). It recomputes even though nothing has changed size.
  5. Set both percentages to 0.5. The content collapses to nothing, which is the configured answer and not a bug.

Step 2 is the one that used to fail. Apply keeps a cache of the last root size so that the several OnRectTransformDimensionsChange calls of one layout pass do not each redo the work - and that cache also swallowed every recompute the user asked for. Dragging the sliders did nothing, and neither did the inspector button, which is exactly the case it exists for. Both force the recompute now.

The forced recompute is also deferred by one editor frame. Unity refuses to let a component move another RectTransform from inside OnValidate and says so with a SendMessage cannot be called during ... OnValidate error, so the work is scheduled for immediately after instead.


Known limitation: text scaling is inert

Auto Scale Text is checked by default and currently does nothing. The whole body of ApplyTextScaling sits inside #if TMP_PRESENT, and TMP_PRESENT is defined nowhere in this package - not in this assembly definition, not in the project settings. So the method compiles to an empty body in every build that has ever been made, and the three settings that drive it (minFontSize, maxFontSize, fontSizeFactor) are compiled out of the inspector entirely.

Turning it on is a versionDefines entry plus a TextMeshPro reference on UGTK.UIModule.Responsive.asmdef, which today references nothing at all. It is left off on purpose, because switching it on is not a neutral repair:

In other words the switch changes how existing UI looks. Flip it deliberately, on a project you can look at, rather than as part of an upgrade.


Technical Info


© 2026 Marcello De Bonis. All rights reserved