Example #1
0
        ////////////////

        /// <param name="theme">Appearance style.</param>
        /// <param name="label">Display text.</param>
        /// <param name="url">URL.</param>
        /// <param name="hoverUrl">Indicates if the current element handles its own mouse hover URL display behavior.</param>
        /// <param name="scale">Size multiplier of display text.</param>
        /// <param name="large">'Large' state of display text.</param>
        public UIWebUrl(UITheme theme, string label, string url, bool hoverUrl = true, float scale = 0.85f, bool large = false)
            : base(theme, true)
        {
            this.IsVisited           = false;
            this.Url                 = url;
            this.WillDrawOwnHoverUrl = hoverUrl;
            this.Scale               = scale;
            this.Large               = large;

            this.TextElem           = new UIText(label, scale, large);
            this.TextElem.TextColor = theme.UrlColor;
            this.Append(this.TextElem);

            this.LineElem           = UIWebUrl.GetLineElement(label, scale, large);
            this.LineElem.TextColor = theme.UrlColor;
            this.Append(this.LineElem);

            CalculatedStyle labelSize = this.TextElem.GetDimensions();

            this.Width.Set(labelSize.Width, 0f);
            this.Height.Set(labelSize.Height, 0f);

            UIText textElem = this.TextElem;
            UIText lineElem = this.LineElem;

            this.OnMouseOver += delegate(UIMouseEvent evt, UIElement fromElem) {
                if (textElem.TextColor != theme.UrlVisitColor)
                {
                    textElem.TextColor = theme.UrlLitColor;
                    textElem.TextColor = theme.UrlLitColor;
                }
            };
            this.OnMouseOut += delegate(UIMouseEvent evt, UIElement fromElem) {
                if (textElem.TextColor != theme.UrlVisitColor)
                {
                    textElem.TextColor = theme.UrlColor;
                    textElem.TextColor = theme.UrlColor;
                }
            };

            this.OnClick += delegate(UIMouseEvent evt, UIElement fromElem) {
                try {
                    SystemLibraries.OpenUrl(this.Url);
                    //System.Diagnostics.Process.Start( this.Url );

                    this.IsVisited = true;

                    textElem.TextColor = theme.UrlVisitColor;
                    lineElem.TextColor = theme.UrlVisitColor;
                } catch (Exception e) {
                    Main.NewText(e.Message);
                }
            };

            this.RefreshTheme();
        }
Example #2
0
        ////////////////

        /// <summary>
        /// Sets the display text.
        /// </summary>
        /// <param name="text">New display text.</param>
        public void SetText(string text)
        {
            this.TextElem.SetText(text, this.Scale, this.Large);

            Timers.RunNow(() => {
                this.RemoveChild(this.LineElem);
                this.LineElem.Remove();
            });

            this.LineElem = UIWebUrl.GetLineElement(text, this.Scale, this.Large);
            this.Append(this.LineElem);

            this.Recalculate();
        }