How to make floating widgets?

Well, your widget is much larger than 32 pixels, 32 was just an example. Check in the designer how big it is and subtract half of it, or do Widget->GetDesiredSize and subtract half of that that. This will position in smack in the centre of the object.

You still need push it off the edges is some cases, precisely as you indicated in your image with the red arrows. GetViewportSize gets you the screen size, GetDesiredSize is the size of the widget.

The following is just pseudo-code, I do not know your setup but hopefully this can get you started. Essentially, if the widget position is too close to the right edge, you move it left:

You should write a separate (pure will do) function that calculates the offset. You will have 4 cases - top, bottom, left or right clipping. The above only accounts for the right clip. The values are just examples, you’d need to populate it with you own numbers and repeat it for all screen edges.