Skip to content

Fix FlxInputText cursor, selection and click position when scaled - #3665

Open
Pooki-LTSC wants to merge 3 commits into
HaxeFlixel:devfrom
Pooki-LTSC:fix/inputtext-scale
Open

Pooki-LTSC wants to merge 3 commits into
HaxeFlixel:devfrom
Pooki-LTSC:fix/inputtext-scale

Conversation

@Pooki-LTSC

Copy link
Copy Markdown

Description

When FlxInputText has a scale other 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

  • Cursor, selection boxes, background and border now follow the scale, origin and offset
  • Pointer input uses transformWorldToPixels(), so clicking selects the correct characters and the clickable area matches the input box

Scaled 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).

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
@Geokureli

Copy link
Copy Markdown
Member

Can I get a code sample for reproducing this?

Whatever was used to make that video would suffice.

@Geokureli Geokureli left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment on lines +692 to +717
/**
* 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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

@Geokureli Geokureli Oct 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Automatically set FlxInputText's origin to 0. this is in line with how people typically use input text
  2. Change this line to sprite.origin.copyFrom(origin); and better account for non-zero origin in the text selection code
  3. 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

@Geokureli Geokureli Oct 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants