private void UpdateThumbHeight(object sender, EventArgs e) { if (ScrollNeeded) { ScrollThumb.UpdateHeight(sender as ScrollBar, _ownerContents); } }
public void Initialize() { ScrollBar = new ScrollBar(); ScrollBar.Width = _style.ScrollBarWidth; ScrollBar.Height = _owner.Bounds.Height - _owner.DragBounds.Height; ScrollBar.AnchorTo(_owner, PositionType.Inside_Top_Right, -8, 27, AnchorType.Bounds); if (_style.ScrollUpButtonStyle != null && _style.ScrollDownButtonStyle != null) { ScrollUpBtn = new Button(_style.ScrollUpButtonStyle); ScrollUpBtn.AnchorTo( ScrollBar, PositionType.Inside_Top_Left, 0, 0, AnchorType.Bounds ); ScrollDownBtn = new Button(_style.ScrollDownButtonStyle); ScrollDownBtn.AnchorTo( ScrollBar, PositionType.Inside_Bottom_Left, 0, 0, AnchorType.Bounds ); HasButtons = true; } ScrollThumb = new ScrollThumb(this, _style); ScrollThumb.EnableDragging = true; ScrollThumb.MoveTo(new Vector2(ScrollBarArea.X, ScrollBarArea.Y)); ScrollThumb.Width = _style.ScrollThumbWidth; ScrollThumb.UpdateHeight(ScrollBar, _ownerContents); ScrollThumb.OnScrolled += Scroll; // USE CASES FOR UPDATING THE SCROLL THUMB HEIGHT HERE: _owner.ContentManager.OnItemAdded += UpdateThumbHeight; _owner.ContentManager.OnItemRemoved += UpdateThumbHeight; if (_owner.ContentManager.Contents[0] != null) { _containerKeyItem = _owner.ContentManager.Contents[0]; _containerStartPosition = _containerKeyItem.Position; } // Input Handlers var contents = new Contents(); contents.Add(ScrollBar); contents.Add(ScrollThumb); if (HasButtons) { contents.Add(ScrollUpBtn); contents.Add(ScrollDownBtn); } _input = new InputHandler(contents); Initialized = true; }