I would like to propose a new BoundingBehavior setting that respects the parent UI elementâs AnchorPoint property.
In this video, I have 2 identical sliders, where both of the handles have an AnchorPoint of 0.5, 0.5:
- The top sliderâs BoundingUI is set to the red frame and its BoundingBehavior is set to EntireObject.
- The bottom sliderâs BoundingUI is set to the green frame and its BoundingBehavior is set to AnchorPoint.
- (Okay, I lied, of course, because that setting doesnât exist. The bottom slider has no BoundingUI and I am using :AddConstraintFunction() to simulate what this AnchorPoint BoundingBehavior would look like.)
Here is my code to simulate that:
local dragDetector = script.Parent
dragDetector:AddConstraintFunction(100, function(proposedPosition: UDim2): UDim2
local trackSize = dragDetector.Parent.Parent.AbsoluteSize.X
local handleSize = dragDetector.Parent.AbsoluteSize.X
local halfwayPoint = (handleSize / trackSize) / 2
local scale = math.clamp(proposedPosition.X.Scale, 0 - halfwayPoint, 1 - halfwayPoint)
local newPosition = UDim2.fromScale(scale, proposedPosition.Y.Scale)
return newPosition
end)
Speaking of which, I also wish the proposed position parameter of the modifier function in :AddConstraintFunction() respected AnchorPoints. (I donât think I used this method as intended, but this is my first time dabbling with UIDragDetectors.) You can see I had to subtract the halfway point of the handle UI element from the positionâs scale to get it to position correctly. Otherwise it would look like this:
Same code as above, just without subtracting the halfway point:
local dragDetector = script.Parent
dragDetector:AddConstraintFunction(100, function(proposedPosition: UDim2): UDim2
local trackSize = dragDetector.Parent.Parent.AbsoluteSize.X
local handleSize = dragDetector.Parent.AbsoluteSize.X
local scale = math.clamp(proposedPosition.X.Scale, 0, 1)
local newPosition = UDim2.fromScale(scale, proposedPosition.Y.Scale)
return newPosition
end)
Why have a BoundingBehavior setting for this?
Simply put, it would be intuitive because of how AnchorPoints work; If my UI element has an AnchorPoint of 0.5, 0.5 and I dragged it to the middle of the slider (Scale.X = 0.5), it should be exactly in the middle, not slightly to the right as if the AnchorPoint was 0, 0. Same goes for the left side (Scale.X = 0) and the right side (Scale.X = 1). And while I did offer a solution with some code above, I think having to code intuitive behavior shouldnât be necessary.
There are probably technical reasons why this wonât work or be an easy solution, but I figured Iâd suggest it anyways. That is all, thank you.
Side note: My code to simulate this behavior was just something I whipped up really quick and doesnât work as expected on any UI that is rotated.
Edit: I just noticed a solution posted above, which I didnât get around to sooner due to the amount of replies this post has. What Iâm proposing here would be a similar, one-click solution with the precision based on the UI elementâs AnchorPoint.