How can I create my own scaling rule? UI

I need to be derived from some class and in it I can write logic, right? But I don’t understand how to do it …

I want to make a UI to fit different phone / tablet / monitor sizes, but I can’t because DPI adjusts horizontally or vertically.
This does not suit me, I want the horizontal AND vertical to affect the scale of the UI

I do everything in blueprints and I just don’t understand how I can make this rule…
help me please

You can only make that class in C++

This is not a “Blueprintable” class