Exemple #1
0
    public void DoLayout()
    {
        float   padding = Config.PADDING_XS;
        Vector2 cursor  = new Vector2(-_width * 0.5f, _height * 0.5f);    //the top left

        float freeWidth = _width;

        freeWidth -= minusBox.GetNeededWidth() + padding; //minus width
        freeWidth -= plusBox.GetNeededWidth() + padding;  //plus width
        freeWidth -= padding;                             //padding between name and score

        if (_hasHandle)
        {
            AddChild(handleBox);
            handleBox.SetSize(handleBox.GetNeededWidth(), _height);
            handleBox.SetTopLeft(cursor.x, cursor.y);
            cursor.x  += handleBox.width + padding;
            freeWidth -= handleBox.width + padding;           //handle width
        }
        else
        {
            handleBox.RemoveFromContainer();
        }

        bool shouldRound = (scoreBox.mathMode.amount == 0 || scoreBox.mathMode.amount == 1);

        freeWidth = Mathf.Round(freeWidth);

        resetWidth = freeWidth;

        float mathModeMultiplier = (1.0f + 1.1f * scoreBox.mathMode.amount);
        float maxScoreWidth      = 100.0f;
        float scoreWidth         = Mathf.Min(maxScoreWidth, freeWidth * 1.5f / 5.0f) * mathModeMultiplier;
        float nameWidth          = freeWidth - scoreWidth;

        scoreWidth = Mathf.Round(scoreWidth);
        nameWidth  = Mathf.Round(nameWidth);


        nameBox.SetSize(nameWidth, _height);
        nameBox.SetTopLeft(cursor.x, cursor.y);
        nameCell.Set(cursor.x + nameWidth * 0.5f, cursor.y - _height * 0.5f, nameWidth, _height);
        cursor.x += nameBox.width + padding;

        scoreBox.SetSize(scoreWidth, _height);
        scoreBox.SetTopLeft(cursor.x, cursor.y);
        cursor.x += scoreBox.width + padding;

        minusBox.SetSize(minusBox.GetNeededWidth(), _height);
        minusBox.SetTopLeft(cursor.x, cursor.y);
        cursor.x += minusBox.width + padding;

        plusBox.SetSize(plusBox.GetNeededWidth(), _height);
        plusBox.SetTopLeft(cursor.x, cursor.y);
        cursor.x += plusBox.width + padding;
    }