godot: Control anchor points should not be limited from 0 to 1

I’ll try to explain the issue using an example.

Suppose, you have a parent Control and a child Control. The parent Control will change its rect_size dynamically, both width and height. The child Control needs to always satisfy the following conditions.

  1. The child width must always be 40% of parent width
  2. The child height must always be 40% of parent height
  3. The child top-left corner must always be at 20% of parent width and 20% of parent height

This conditions are easily met by setting anchor points and margins on the child Control.

screen shot 2018-08-16 at 5 33 04 pm screen shot 2018-08-16 at 5 27 04 pm screen shot 2018-08-16 at 5 27 10 pm screen shot 2018-08-16 at 5 27 17 pm

Very easy solution, right? This method can be used as long as the child needs to be inside the parent rect. But the situation changes completely when part of the child needs to be outside of parent rect.

For example, just change the conditions to the following.

  1. The child width must always be 40% of parent width
  2. The child height must always be 40% of parent height
  3. The child top-left corner must always be at 80% of parent width and 80% of parent height

If Godot didn’t limit the anchor points from 0 to 1, it would’ve been sufficient to just change the anchor points to the following.

screen shot 2018-08-16 at 5 33 04 pm copy

But as it does not allow anchor points to be outside of this range, we need to find alternative solutions like using scripts or wrapping the child and/or parent Controls inside Node2D.

Similarly, if we needed the child rect to be outside the left and top border of the parent rect, we could use negative anchor points if Godot allowed it.

TLDR: Removing the limit on anchor points will make creating percentage based UI layouts where the child rect has parts outside parent rect a lot easier. With the limit in place, its unnecessarily complex.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 19 (10 by maintainers)

Most upvoted comments

@groud Where are the “or_greater” and “or_lesser” keywords by the way? I don’t see them used anywhere in source.

Edit: Sorry I was searching in the stable version.

To be more precise, I’d be OK with that change only if it does not modifies the current way of editing the properties (the 2d editors anchors are clamped and the sliders go from 0 to 1). But you may be able to enter custom values by hand, a little bit like how it’s done in blender.