Example #1
0
        public UISlider(Transform transform, Texture2D barSprite, Texture2D handleSprite, EventArg onValueChanged, float value, Screen screen) : base(transform, null, screen)
        {
            this.value          = MathHelper.Clamp(value, 0f, 1f);
            this.totalWidth     = transform.Width;
            this.onValueChanged = onValueChanged;

            //The actual bar:
            AddUIElement(new UIElement(
                             new Transform(transform.Size),
                             barSprite,
                             screen
                             )).SetColor(new Color(48, 48, 48));

            //The handle:
            var handleElement = AddUIElement(new UISliderHandle(
                                                 new Transform(new Vector2(50)),
                                                 handleSprite,
                                                 new EventArg0(UpdateHandle),
                                                 this,
                                                 screen
                                                 ));

            handle = GetGroupElement(handleElement);

            UpdateHandle();
        }
Example #2
0
        public UIScrollbar(Transform transform, Texture2D backgroundSprite, Texture2D handleSprite, EventArg onValueChanged, IScrollable scrollable, Screen screen) : base(transform, backgroundSprite, screen)
        {
            this.scrollable     = scrollable;
            this.onValueChanged = onValueChanged;

            var handleElement = AddUIElement(new UIScrollbarHandle(
                                                 new Transform(transform.Position, new Vector2(transform.Width)),
                                                 handleSprite,
                                                 null,
                                                 this,
                                                 screen
                                                 ));

            handleElement.SetColor(new Color(66, 134, 244));

            //Get the handle group element:
            handle = GetGroupElement(handleElement);

            CalculateScrollbarHandlePosition();
        }