Beispiel #1
0
        /// <summary>
        /// Called after the view is loaded.
        /// </summary>
        protected override void AfterLoad()
        {
            if (IgnoreObject)
            {
                return;
            }
            base.AfterLoad();

            // hook up input field event system triggers
            TMP_InputFieldComponent.onEndEdit.RemoveAllListeners();
            TMP_InputFieldComponent.onEndEdit.AddListener(TMProInputFieldEndEdit);

            TMP_InputFieldComponent.onValueChanged.RemoveAllListeners();
            TMP_InputFieldComponent.onValueChanged.AddListener(TMProInputFieldValueChanged);

            // fix textmeshpro issue with word wrapping being reset for some reason
            if (!EnableWordWrappingProperty.IsUndefined(InputText))
            {
                EnableWordWrappingProperty.Load(InputText);
            }

            // set initial text
            TextChanged();

            // workaround for textmeshpro issue where caret was not being spawned
            typeof(TMP_InputField).GetMethod("OnEnable", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(TMP_InputFieldComponent, null);
        }
Beispiel #2
0
        /// <summary>
        /// Called when label text changes.
        /// </summary>
        public virtual void TextChanged()
        {
            try
            {
                if (AutoSize != AutoSize.None && EnableWordWrappingProperty.IsUndefined(this))
                {
                    // when autosizing disable wordwrapping so PreferredWidth is calculated correctly
                    EnableWordWrapping = false;
                }

                // adjust label size to text
                if (AutoSize == AutoSize.Width)
                {
                    Width = new ElementSize(PreferredWidth);
                }
                else if (AutoSize == AutoSize.Height)
                {
                    Height = new ElementSize(PreferredHeight);
                }
                else if (AutoSize == AutoSize.WidthAndHeight || AutoSize == AutoSize.Default)
                {
                    Width  = new ElementSize(PreferredWidth);
                    Height = new ElementSize(PreferredHeight);
                }
            }
            catch
            {
                // bugfix of older version of TextMeshPro bug where PreferredWidth / PreferredHeight throws exceptions
            }
        }
Beispiel #3
0
        /// <summary>
        /// Called when label text changes.
        /// </summary>
        public virtual void TextChanged()
        {
            try
            {
                if (AutoSize != AutoSize.None && EnableWordWrappingProperty.IsUndefined(this))
                {
                    // when autosizing disable wordwrapping so PreferredWidth is calculated correctly
                    EnableWordWrapping = false;
                }

                var margin = Margin ?? new ElementMargin();

                // adjust label size to text
                if (AutoSize == AutoSize.Width)
                {
                    Width = new ElementSize(PreferredWidth + margin.Left + margin.Right);
                }
                else if (AutoSize == AutoSize.Height)
                {
                    Height = new ElementSize(PreferredHeight + margin.Top + margin.Bottom);
                }
                else if (AutoSize == AutoSize.WidthAndHeight || AutoSize == AutoSize.Default)
                {
                    if (MaxWidth != null)
                    {
                        // if MaxWidth is set we want the label to expand and then wrap when reaching the max width
                        float actualPreferredWidth = PreferredWidth + margin.Left + margin.Right;
                        if (actualPreferredWidth > MaxWidth)
                        {
                            EnableWordWrapping = true;
                            Width = new ElementSize(MaxWidth);
                        }
                        else
                        {
                            EnableWordWrapping = false;
                            Width = new ElementSize(actualPreferredWidth);
                        }

                        UpdateLayout(false);
                        Height = new ElementSize(PreferredHeight + margin.Top + margin.Bottom);
                    }
                    else
                    {
                        Width  = new ElementSize(PreferredWidth + margin.Left + margin.Right);
                        Height = new ElementSize(PreferredHeight + margin.Top + margin.Bottom);
                    }
                }
            }
            catch
            {
                // bugfix of older version of TextMeshPro bug where PreferredWidth / PreferredHeight throws exceptions
            }
        }