Example #1
0
        public ScrollView(Vector3 position, Vector2 size, ScrollViewOptions opts)
            : base(position, size, opts.Sprite, opts)
        {
            _clip = new Rect(
                opts.Border.x,
                opts.Border.y + opts.HScrollBarHeight,
                size.x - opts.Border.x - opts.Border.z - opts.VScrollBarWidth,
                size.y - opts.Border.y - opts.Border.w - opts.HScrollBarHeight
                );
            _extents = _clip;
            _opts    = opts;

            var clip = this.Clip;

            // vertical scroll bar
            if (opts.VScrollBarWidth > 0f)
            {
                _vScroll = new Image(
                    new Rect(clip.xMax, clip.yMin, opts.VScrollBarWidth, clip.height),
                    position.z - 0.1f,
                    opts.VScrollBarSprite,
                    new VisualOptions {
                    Name       = "vscroll",
                    Parent     = this,
                    PixelAlign = true
                });
                var knobSize = opts.VKnobSize;
                if (knobSize.x <= 0f)
                {
                    knobSize.x = opts.VScrollBarWidth;
                }
                if (knobSize.y <= 0f)
                {
                    _vAutoSize = true;
                    knobSize.y = clip.height;
                }
                var x = (clip.xMax + opts.VScrollBarWidth / 2f) - knobSize.x / 2f;
                _vKnob = new Button(
                    new Rect(x, clip.yMin, knobSize.x, knobSize.y),
                    position.z - 0.9f,
                    new ButtonOptions {
                    NormalSprite  = opts.VKnobSprite,
                    OverSprite    = opts.VKnobOverSprite,
                    PressedSprite = opts.VKnobPressedSprite,
                    Name          = "vscrollknob",
                    Parent        = this,
                    PixelAlign    = !_vAutoSize
                });
            }
            // horizontal scroll bar
            if (opts.HScrollBarHeight > 0f)
            {
                _hScroll = new Image(
                    new Rect(clip.xMin, clip.yMin - opts.HScrollBarHeight, clip.width, opts.HScrollBarHeight),
                    position.z - 0.1f,
                    opts.HScrollBarSprite,
                    new VisualOptions {
                    Name       = "hscroll",
                    Parent     = this,
                    PixelAlign = false
                });
                var knobSize = opts.VKnobSize;
                if (knobSize.y <= 0f)
                {
                    knobSize.y = opts.HScrollBarHeight;
                }
                if (knobSize.x <= 0f)
                {
                    _hAutoSize = true;
                    knobSize.x = clip.width;
                }
                var y = (clip.yMin - opts.HScrollBarHeight / 2f) - knobSize.y / 2f;
                _hKnob = new Button(
                    new Rect(clip.xMin, y, knobSize.x, knobSize.y),
                    position.z - 0.9f,
                    new ButtonOptions {
                    NormalSprite  = opts.HKnobSprite,
                    OverSprite    = opts.HKnobOverSprite,
                    PressedSprite = opts.HKnobPressedSprite,
                    Name          = "hscrollknob",
                    Parent        = this,
                    PixelAlign    = !_hAutoSize
                });
            }
        }
Example #2
0
 public ScrollView(Rect bounds, float depth, ScrollViewOptions opts) :
     this(new Vector3(bounds.x, bounds.y, depth), new Vector2(bounds.width, bounds.height), opts)
 {
 }