feathersui / feathersui-starling

User interface components for Starling Framework and Adobe AIR

Home Page:https://feathersui.com/learn/as3-starling/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StageTextTextEditor viewport calculation issue

kevinfoley opened this issue · comments

StageTextTextEditor contains the following code to constrain the viewPortX coordinate.

    if((viewPortX + viewPortWidth) > MAX_VIEW_PORT_POSITION)
    {
        viewPortX = MAX_VIEW_PORT_POSITION - viewPortWidth;
    }
    else if(viewPortX < MIN_VIEW_PORT_POSITION)
    {
            viewPortX = MIN_VIEW_PORT_POSITION;
    }

There is similar code to constrain the y-coordinate.

The problem with this code occurs if the viewPortWidth is extremely wide. Say that the viewPortX is 0 and the viewPortWidth is 20,000. The first condition evaluates to true (0 + 20000 > 8191), so the viewPortX gets changed to -20000. This is less than the minimum position, but because of the else, the second condition doesn't get evaluated, so the viewPortX remains less than the minimum.

I see two issues:

  1. You should probably remove the "else" from the second condition so that it will detect if the viewPortX gets set too low by the first condition.

  2. You may wish to throw a specific error if viewPortWidth > MAX_VIEW_PORT_POSITION - MIN_VIEW_PORT_POSITION

I addressed 1, but I decided not to touch 2. I was actually finding that the width could actually be a bit larger without throwing an error when setting viewPort. I'm not sure why, but it doesn't really matter because Stage 3D won't let you create a texture that large anyway.