Repository navigation
Fix FlxInputText cursor, selection and click position when scaled - #3665
Pooki-LTSC wants to merge 3 commits into
Conversation
ughhhh this took way too fucking long, basically does what i put up there
… for offset oops it sucked before now its better
tried to match it better once again
|
Can I get a code sample for reproducing this? Whatever was used to make that video would suffice. |
There was a problem hiding this comment.
How viable is it to propegate scale, origin and offset down to the child sprites and update the frameToWorld to work with that? My goal in that is to make these properties behave more like the default, where the input text scales from the origin. if that's a nightmare, than I'm fine merging this as is.
I see changes to clipSprite, can I get examples of what was tested and how input text behaves with clipRect?
Edit: I tested clipRect, and it behaves well, good job on that!
| /** | ||
| * Gets the Y position in the world of the specified Y position in the text field, | ||
| * takes `scale`, `origin` and `offset` into account. | ||
| */ | ||
| inline function frameToWorldY(frameY:Float):Float | ||
| { | ||
| return y - offset.y + origin.y + (frameY - origin.y) * scale.y; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the X position in the text field of the specified X position in the world, | ||
| * takes `scale`, `origin` and `offset` into account. | ||
| */ | ||
| inline function worldToFrameX(worldX:Float):Float | ||
| { | ||
| return (worldX - x + offset.x - origin.x) / scale.x + origin.x; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the Y position in the text field of the specified Y position in the world, | ||
| * takes `scale`, `origin` and `offset` into account. | ||
| */ | ||
| inline function worldToFrameY(worldY:Float):Float | ||
| { | ||
| return (worldY - y + offset.y - origin.y) / scale.y + origin.y; | ||
| } |
There was a problem hiding this comment.
FlxSprite has a few helpers similar to this, but it doesn't have simple X/Y converters. it may be worth adding them
For instance: worldToFramePositionSimple accounts for scale, origin, offset, rotation, flipX/Y as well well little known frame properties like frame offset and rotation. worldToFramePosition accounts for even more things like scrollFactor
All of this is outside the scope of this PR but I wanna note it, and make a new issue about it after this is merged
| { | ||
| sprite.scrollFactor.copyFrom(scrollFactor); | ||
| sprite.scale.copyFrom(scale); | ||
| sprite.origin.set(0, 0); |
There was a problem hiding this comment.
I don't think we should assume 0 origin, here. This change only works if the dev explicitly sets the origin to zero, otherwise the text is misaligned. while it may be common for devs to set the origin to zero, it's not the default.
I see 3 options:
- Automatically set FlxInputText's origin to 0. this is in line with how people typically use input text
- Change this line to
sprite.origin.copyFrom(origin);and better account for non-zero origin in the text selection code - No change to this PR, require the dev to set origin to zero when scaling
Number 1 could break existing code (while unlikely, we would still need to wait for the next major release rather than a patch release.) Number 2 is the most robust and ideal, but I don't know the work involved. Number 3 is clearly the easiest
There was a problem hiding this comment.
I have similar thoughts for offset, it looks like the offset is used to position the sub sprites rather than being copied to them. I wonder if that plays well with things like clipRect and getPixelAt (though I don't know if this is something we tested before). Worth noting that without testing the features mentioned above, offsetting the input text behaves exactly how I expect
I'm okay with also leaving this as is, for the scope of this, but I do find it odd that scale is copied to child sprites, offset is not and origin is assumed zero. Three different solutions for three the three properties.
Description
When
FlxInputTexthas ascaleother than the default, only the text itself is scaled. The cursor, selection boxes, background and border are still drawn at the default size and position, causing misalignment with the text. Pointer input also ignores scale, so interacting with scaled input boxes does not work as intended and attempting to select text causes it to select the wrong characters.Fix
scale,originandoffsettransformWorldToPixels(), so clicking selects the correct characters and the clickable area matches the input boxScaled input texts should behave like any other scaled sprite. With a scale of 1 and no offset, nothing changes.
681364176-edff59b5-3f64-4805-9593-3d8bee433036.mp4
Tested on FunkinCrew's fork of Flixel, which has the same
FlxInputText(merged in FunkinCrew#34).