CalculateOffsetToFit() public method

Calculate the character index offset necessary in order to print the end of the specified text.
public CalculateOffsetToFit ( string text ) : int
text string
return int
Exemplo n.º 1
0
    static int CalculateOffsetToFit(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        UILabel obj  = (UILabel)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UILabel");
        string  arg0 = LuaScriptMgr.GetLuaString(L, 2);
        int     o    = obj.CalculateOffsetToFit(arg0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Exemplo n.º 2
0
 static public int CalculateOffsetToFit(IntPtr l)
 {
     try {
         UILabel       self = (UILabel)checkSelf(l);
         System.String a1;
         checkType(l, 2, out a1);
         var ret = self.CalculateOffsetToFit(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 3
0
	static int CalculateOffsetToFit(IntPtr L)
	{
		try
		{
			ToLua.CheckArgsCount(L, 2);
			UILabel obj = (UILabel)ToLua.CheckObject<UILabel>(L, 1);
			string arg0 = ToLua.CheckString(L, 2);
			int o = obj.CalculateOffsetToFit(arg0);
			LuaDLL.lua_pushinteger(L, o);
			return 1;
		}
		catch (Exception e)
		{
			return LuaDLL.toluaL_exception(L, e);
		}
	}
Exemplo n.º 4
0
    public static int CalculateOffsetToFit(IntPtr l)
    {
        int result;

        try
        {
            UILabel uILabel = (UILabel)LuaObject.checkSelf(l);
            string  text;
            LuaObject.checkType(l, 2, out text);
            int i = uILabel.CalculateOffsetToFit(text);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, i);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Exemplo n.º 5
0
    public string PopupTextAdjust(UILabel lbl, string pop_text)
    {
        if (popAdjustBeforeList == null)
        {
            popAdjustBeforeList = new List <string>();
        }
        popAdjustBeforeList.Add(pop_text);
        char[] array = pop_text.ToCharArray();
        Array.Reverse(array);
        string text  = new string(array);
        int    num   = lbl.CalculateOffsetToFit(text);
        string empty = string.Empty;

        if (num <= 0)
        {
            return(pop_text);
        }
        empty = text.Substring(num - 1);
        empty = "…" + empty;
        char[] array2 = empty.ToCharArray();
        Array.Reverse(array2);
        return(new string(array2));
    }
Exemplo n.º 6
0
    public void UpdateLabel()
    {
        if (!(label != null))
        {
            return;
        }
        if (mDoInit)
        {
            Init();
        }
        bool   isSelected = this.isSelected;
        string value      = this.value;
        bool   flag       = string.IsNullOrEmpty(value) && string.IsNullOrEmpty(Input.compositionString);

        label.color = ((!flag || isSelected) ? activeTextColor : mDefaultColor);
        string text;

        if (flag)
        {
            text = ((!isSelected) ? mDefaultText : string.Empty);
            RestoreLabelPivot();
        }
        else
        {
            if (inputType == InputType.Password)
            {
                text = string.Empty;
                string str = "*";
                if (label.bitmapFont != null && label.bitmapFont.bmFont != null && label.bitmapFont.bmFont.GetGlyph(42) == null)
                {
                    str = "x";
                }
                int i = 0;
                for (int length = value.Length; i < length; i++)
                {
                    text += str;
                }
            }
            else
            {
                text = value;
            }
            int    num  = isSelected ? Mathf.Min(text.Length, cursorPosition) : 0;
            string str2 = text.Substring(0, num);
            if (isSelected)
            {
                str2 += Input.compositionString;
            }
            text = str2 + text.Substring(num, text.Length - num);
            if (isSelected && label.overflowMethod == UILabel.Overflow.ClampContent && label.maxLineCount == 1)
            {
                int num2 = label.CalculateOffsetToFit(text);
                if (num2 == 0)
                {
                    mDrawStart = 0;
                    RestoreLabelPivot();
                }
                else if (num < mDrawStart)
                {
                    mDrawStart = num;
                    SetPivotToLeft();
                }
                else if (num2 < mDrawStart)
                {
                    mDrawStart = num2;
                    SetPivotToLeft();
                }
                else
                {
                    num2 = label.CalculateOffsetToFit(text.Substring(0, num));
                    if (num2 > mDrawStart)
                    {
                        mDrawStart = num2;
                        SetPivotToRight();
                    }
                }
                if (mDrawStart != 0)
                {
                    text = text.Substring(mDrawStart, text.Length - mDrawStart);
                }
            }
            else
            {
                mDrawStart = 0;
                RestoreLabelPivot();
            }
        }
        label.text = text;
        if (isSelected)
        {
            int num3 = mSelectionStart - mDrawStart;
            int num4 = mSelectionEnd - mDrawStart;
            if (mBlankTex == null)
            {
                mBlankTex = new Texture2D(2, 2, TextureFormat.ARGB32, mipmap: false);
                for (int j = 0; j < 2; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        mBlankTex.SetPixel(k, j, Color.white);
                    }
                }
                mBlankTex.Apply();
            }
            if (num3 != num4)
            {
                if (mHighlight == null)
                {
                    mHighlight              = NGUITools.AddWidget <UITexture>(label.cachedGameObject);
                    mHighlight.name         = "Input Highlight";
                    mHighlight.mainTexture  = mBlankTex;
                    mHighlight.fillGeometry = false;
                    mHighlight.pivot        = label.pivot;
                    mHighlight.SetAnchor(label.cachedTransform);
                }
                else
                {
                    mHighlight.pivot       = label.pivot;
                    mHighlight.mainTexture = mBlankTex;
                    mHighlight.MarkAsChanged();
                    mHighlight.enabled = true;
                }
            }
            if (mCaret == null)
            {
                mCaret              = NGUITools.AddWidget <UITexture>(label.cachedGameObject);
                mCaret.name         = "Input Caret";
                mCaret.mainTexture  = mBlankTex;
                mCaret.fillGeometry = false;
                mCaret.pivot        = label.pivot;
                mCaret.SetAnchor(label.cachedTransform);
            }
            else
            {
                mCaret.pivot       = label.pivot;
                mCaret.mainTexture = mBlankTex;
                mCaret.MarkAsChanged();
                mCaret.enabled = true;
            }
            if (num3 != num4)
            {
                label.PrintOverlay(num3, num4, mCaret.geometry, mHighlight.geometry, caretColor, selectionColor);
                mHighlight.enabled = mHighlight.geometry.hasVertices;
            }
            else
            {
                label.PrintOverlay(num3, num4, mCaret.geometry, null, caretColor, selectionColor);
                if (mHighlight != null)
                {
                    mHighlight.enabled = false;
                }
            }
            mNextBlink = RealTime.time + 0.5f;
            mLastAlpha = label.finalAlpha;
        }
        else
        {
            Cleanup();
        }
    }
Exemplo n.º 7
0
    /// <summary>
    /// Update the visual text label.
    /// </summary>

    public void UpdateLabel()
    {
        if (label != null)
        {
            if (mDoInit)
            {
                Init();
            }
            bool   selected = isSelected;
            string fullText = value;
            bool   isEmpty  = string.IsNullOrEmpty(fullText) && string.IsNullOrEmpty(Input.compositionString);
            label.color = (isEmpty && !selected) ? mDefaultColor : activeTextColor;
            string processed;

            if (isEmpty)
            {
                processed = selected ? "" : mDefaultText;
                RestoreLabelPivot();
            }
            else
            {
                if (inputType == InputType.Password)
                {
                    processed = "";

                    string asterisk = "*";

                    if (label.bitmapFont != null && label.bitmapFont.bmFont != null &&
                        label.bitmapFont.bmFont.GetGlyph('*') == null)
                    {
                        asterisk = "x";
                    }

                    for (int i = 0, imax = fullText.Length; i < imax; ++i)
                    {
                        processed += asterisk;
                    }
                }
                else
                {
                    processed = fullText;
                }

                // Start with text leading up to the selection
                int    selPos = selected ? Mathf.Min(processed.Length, cursorPosition) : 0;
                string left   = processed.Substring(0, selPos);

                // Append the composition string and the cursor character
                if (selected)
                {
                    left += Input.compositionString;
                }

                // Append the text from the selection onwards
                processed = left + processed.Substring(selPos, processed.Length - selPos);

                // Clamped content needs to be adjusted further
                if (selected && label.overflowMethod == UILabel.Overflow.ClampContent && label.maxLineCount == 1)
                {
                    // Determine what will actually fit into the given line
                    int offset = label.CalculateOffsetToFit(processed);

                    if (offset == 0)
                    {
                        mDrawStart = 0;
                        RestoreLabelPivot();
                    }
                    else if (selPos < mDrawStart)
                    {
                        mDrawStart = selPos;
                        SetPivotToLeft();
                    }
                    else if (offset < mDrawStart)
                    {
                        mDrawStart = offset;
                        SetPivotToLeft();
                    }
                    else
                    {
                        offset = label.CalculateOffsetToFit(processed.Substring(0, selPos));

                        if (offset > mDrawStart)
                        {
                            mDrawStart = offset;
                            SetPivotToRight();
                        }
                    }

                    // If necessary, trim the front
                    if (mDrawStart != 0)
                    {
                        processed = processed.Substring(mDrawStart, processed.Length - mDrawStart);
                    }
                }
                else
                {
                    mDrawStart = 0;
                    RestoreLabelPivot();
                }
            }

            label.text = processed;
#if MOBILE
            if (selected && (mKeyboard == null || inputShouldBeHidden))
#else
            if (selected)
#endif
            {
                int start = mSelectionStart - mDrawStart;
                int end   = mSelectionEnd - mDrawStart;

                // Blank texture used by selection and caret
                if (mBlankTex == null)
                {
                    mBlankTex = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                    for (int y = 0; y < 2; ++y)
                    {
                        for (int x = 0; x < 2; ++x)
                        {
                            mBlankTex.SetPixel(x, y, Color.white);
                        }
                    }
                    mBlankTex.Apply();
                }

                // Create the selection highlight
                if (start != end)
                {
                    if (mHighlight == null)
                    {
                        mHighlight              = NGUITools.AddWidget <UITexture>(label.cachedGameObject);
                        mHighlight.name         = "Input Highlight";
                        mHighlight.mainTexture  = mBlankTex;
                        mHighlight.fillGeometry = false;
                        mHighlight.pivot        = label.pivot;
                        mHighlight.SetAnchor(label.cachedTransform);
                    }
                    else
                    {
                        mHighlight.pivot       = label.pivot;
                        mHighlight.mainTexture = mBlankTex;
                        mHighlight.MarkAsChanged();
                        mHighlight.enabled = true;
                    }
                }

                // Create the carter
                if (mCaret == null)
                {
                    mCaret              = NGUITools.AddWidget <UITexture>(label.cachedGameObject);
                    mCaret.name         = "Input Caret";
                    mCaret.mainTexture  = mBlankTex;
                    mCaret.fillGeometry = false;
                    mCaret.pivot        = label.pivot;
                    mCaret.SetAnchor(label.cachedTransform);
                }
                else
                {
                    mCaret.pivot       = label.pivot;
                    mCaret.mainTexture = mBlankTex;
                    mCaret.MarkAsChanged();
                    mCaret.enabled = true;
                }

                if (start != end)
                {
                    label.PrintOverlay(start, end, mCaret.geometry, mHighlight.geometry, caretColor, selectionColor);
                    mHighlight.enabled = mHighlight.geometry.hasVertices;
                }
                else
                {
                    label.PrintOverlay(start, end, mCaret.geometry, null, caretColor, selectionColor);
                    if (mHighlight != null)
                    {
                        mHighlight.enabled = false;
                    }
                }

                // Reset the blinking time
                mNextBlink = RealTime.time + 0.5f;
                mLastAlpha = label.finalAlpha;
            }
            else
            {
                Cleanup();
            }
        }
    }
Exemplo n.º 8
0
    /// <summary>
    /// Update the visual text label.
    /// </summary>

    protected void UpdateLabel()
    {
        if (label != null)
        {
            if (mDoInit)
            {
                Init();
            }
            bool   selected = isSelected;
            string fullText = value;
            bool   isEmpty  = string.IsNullOrEmpty(fullText);
            string processed;

            if (isEmpty)
            {
                processed = selected ? (needsTextCursor ? "|" : "") : mDefaultText;
                RestoreLabelPivot();
            }
            else
            {
                if (inputType == InputType.Password)
                {
                    processed = "";
                    for (int i = 0, imax = fullText.Length; i < imax; ++i)
                    {
                        processed += "*";
                    }
                }
                else
                {
                    processed = fullText;
                }

                // Start with text leading up to the selection
                int    selPos = selected ? Mathf.Min(processed.Length, cursorPosition) : 0;
                string left   = processed.Substring(0, selPos);

                if (selected)
                {
                    // Append the composition string and the cursor character
                    left += Input.compositionString;
                    if (needsTextCursor)
                    {
                        left += "|";
                    }
                }

                // Append the text from the selection onwards
                processed = left + processed.Substring(selPos, processed.Length - selPos);

                if (label.overflowMethod == UILabel.Overflow.ClampContent)
                {
                    // Determine what will actually fit into the given line
                    if (selected)
                    {
                        if (mDrawEnd == 0)
                        {
                            mDrawEnd = selPos;
                        }

                        // Offset required in order to print the part leading up to the cursor
                        string visible    = processed.Substring(0, Mathf.Min(mDrawEnd, processed.Length));
                        int    leftMargin = label.CalculateOffsetToFit(visible);

                        // The cursor is no longer within bounds
                        if (selPos < leftMargin || selPos >= mDrawEnd)
                        {
                            leftMargin = label.CalculateOffsetToFit(left);
                            mDrawStart = leftMargin;
                            mDrawEnd   = left.Length;
                        }
                        else if (leftMargin != mDrawStart)
                        {
                            // The left margin shifted -- happens when deleting or adding characters
                            mDrawStart = leftMargin;
                        }
                    }

                    // If the text doesn't fit, we want to change the label to use a right-hand pivot point
                    if (mDrawStart != 0)
                    {
                        processed = processed.Substring(mDrawStart, processed.Length - mDrawStart);
                        if (mPivot == UIWidget.Pivot.Left)
                        {
                            label.pivot = UIWidget.Pivot.Right;
                        }
                        else if (mPivot == UIWidget.Pivot.TopLeft)
                        {
                            label.pivot = UIWidget.Pivot.TopRight;
                        }
                        else if (mPivot == UIWidget.Pivot.BottomLeft)
                        {
                            label.pivot = UIWidget.Pivot.BottomRight;
                        }
                    }
                    else
                    {
                        RestoreLabelPivot();
                    }
                }
                else
                {
                    RestoreLabelPivot();
                }
            }

            label.text  = processed;
            label.color = (isEmpty && !selected) ? mDefaultColor : activeTextColor;
        }
    }
Exemplo n.º 9
0
 public void UpdateLabel()
 {
     //IL_005c: Unknown result type (might be due to invalid IL or missing references)
     //IL_0067: Unknown result type (might be due to invalid IL or missing references)
     //IL_02cb: Unknown result type (might be due to invalid IL or missing references)
     //IL_02d0: Expected O, but got Unknown
     //IL_02ef: Unknown result type (might be due to invalid IL or missing references)
     //IL_04d9: Unknown result type (might be due to invalid IL or missing references)
     //IL_04df: Unknown result type (might be due to invalid IL or missing references)
     //IL_0520: Unknown result type (might be due to invalid IL or missing references)
     //IL_0526: Unknown result type (might be due to invalid IL or missing references)
     if (label != null)
     {
         if (mDoInit)
         {
             Init();
         }
         bool   isSelected = this.isSelected;
         string value      = this.value;
         bool   flag       = string.IsNullOrEmpty(value) && string.IsNullOrEmpty(Input.get_compositionString());
         label.color = ((!flag || isSelected) ? activeTextColor : mDefaultColor);
         string text;
         if (flag)
         {
             text = ((!isSelected) ? mDefaultText : string.Empty);
             RestoreLabelPivot();
         }
         else
         {
             if (inputType == InputType.Password)
             {
                 text = string.Empty;
                 string str = "*";
                 if (label.bitmapFont != null && label.bitmapFont.bmFont != null && label.bitmapFont.bmFont.GetGlyph(42) == null)
                 {
                     str = "x";
                 }
                 int i = 0;
                 for (int length = value.Length; i < length; i++)
                 {
                     text += str;
                 }
             }
             else
             {
                 text = value;
             }
             int    num  = isSelected ? Mathf.Min(text.Length, cursorPosition) : 0;
             string str2 = text.Substring(0, num);
             if (isSelected)
             {
                 str2 += Input.get_compositionString();
             }
             text = str2 + text.Substring(num, text.Length - num);
             if (isSelected && label.overflowMethod == UILabel.Overflow.ClampContent && label.maxLineCount == 1)
             {
                 int num2 = label.CalculateOffsetToFit(text);
                 if (num2 == 0)
                 {
                     mDrawStart = 0;
                     RestoreLabelPivot();
                 }
                 else if (num < mDrawStart)
                 {
                     mDrawStart = num;
                     SetPivotToLeft();
                 }
                 else if (num2 < mDrawStart)
                 {
                     mDrawStart = num2;
                     SetPivotToLeft();
                 }
                 else
                 {
                     num2 = label.CalculateOffsetToFit(text.Substring(0, num));
                     if (num2 > mDrawStart)
                     {
                         mDrawStart = num2;
                         SetPivotToRight();
                     }
                 }
                 if (mDrawStart != 0)
                 {
                     text = text.Substring(mDrawStart, text.Length - mDrawStart);
                 }
             }
             else
             {
                 mDrawStart = 0;
                 RestoreLabelPivot();
             }
         }
         label.text = text;
         if (isSelected && (mKeyboard == null || inputShouldBeHidden))
         {
             int num3 = mSelectionStart - mDrawStart;
             int num4 = mSelectionEnd - mDrawStart;
             if (mBlankTex == null)
             {
                 mBlankTex = new Texture2D(2, 2, 5, false);
                 for (int j = 0; j < 2; j++)
                 {
                     for (int k = 0; k < 2; k++)
                     {
                         mBlankTex.SetPixel(k, j, Color.get_white());
                     }
                 }
                 mBlankTex.Apply();
             }
             if (num3 != num4)
             {
                 if (mHighlight == null)
                 {
                     mHighlight = NGUITools.AddWidget <UITexture>(label.cachedGameObject);
                     mHighlight.set_name("Input Highlight");
                     mHighlight.mainTexture  = mBlankTex;
                     mHighlight.fillGeometry = false;
                     mHighlight.pivot        = label.pivot;
                     ((UIRect)mHighlight).SetAnchor(label.cachedTransform);
                 }
                 else
                 {
                     mHighlight.pivot       = label.pivot;
                     mHighlight.mainTexture = mBlankTex;
                     mHighlight.MarkAsChanged();
                     mHighlight.set_enabled(true);
                 }
             }
             if (mCaret == null)
             {
                 mCaret = NGUITools.AddWidget <UITexture>(label.cachedGameObject);
                 mCaret.set_name("Input Caret");
                 mCaret.mainTexture  = mBlankTex;
                 mCaret.fillGeometry = false;
                 mCaret.pivot        = label.pivot;
                 ((UIRect)mCaret).SetAnchor(label.cachedTransform);
             }
             else
             {
                 mCaret.pivot       = label.pivot;
                 mCaret.mainTexture = mBlankTex;
                 mCaret.MarkAsChanged();
                 mCaret.set_enabled(true);
             }
             if (num3 != num4)
             {
                 label.PrintOverlay(num3, num4, mCaret.geometry, mHighlight.geometry, caretColor, selectionColor);
                 mHighlight.set_enabled(mHighlight.geometry.hasVertices);
             }
             else
             {
                 label.PrintOverlay(num3, num4, mCaret.geometry, null, caretColor, selectionColor);
                 if (mHighlight != null)
                 {
                     mHighlight.set_enabled(false);
                 }
             }
             mNextBlink = RealTime.time + 0.5f;
             mLastAlpha = label.finalAlpha;
         }
         else
         {
             Cleanup();
         }
     }
 }