protected internal override void ExecuteDefaultAction(EventBase evt) { base.ExecuteDefaultAction(evt); if (evt.GetEventTypeId() == PostLayoutEvent.TypeId()) { OnGeometryChanged((PostLayoutEvent)evt); } }
private void OnGeometryChanged(PostLayoutEvent evt) { // Only affected by dimension changes if (evt.oldRect.size == evt.newRect.size) { return; } if (contentContainer.layout.width > Mathf.Epsilon) { horizontalScroller.Adjust(contentViewport.layout.width / contentContainer.layout.width); } if (contentContainer.layout.height > Mathf.Epsilon) { verticalScroller.Adjust(contentViewport.layout.height / contentContainer.layout.height); } // Set availability horizontalScroller.SetEnabled(contentContainer.layout.width - layout.width > 0); verticalScroller.SetEnabled(contentContainer.layout.height - layout.height > 0); // Expand content if scrollbars are hidden contentViewport.style.positionRight = needsVertical ? verticalScroller.layout.width : 0; horizontalScroller.style.positionRight = needsVertical ? verticalScroller.layout.width : 0; contentViewport.style.positionBottom = needsHorizontal ? horizontalScroller.layout.height : 0; verticalScroller.style.positionBottom = needsHorizontal ? horizontalScroller.layout.height : 0; if (needsHorizontal) { horizontalScroller.lowValue = 0.0f; horizontalScroller.highValue = scrollableWidth; } else { horizontalScroller.value = 0.0f; } if (needsVertical) { verticalScroller.lowValue = 0.0f; verticalScroller.highValue = scrollableHeight; } else { verticalScroller.value = 0.0f; } // Set visibility and remove/add content viewport margin as necessary if (horizontalScroller.visible != needsHorizontal) { horizontalScroller.visible = needsHorizontal; if (needsHorizontal) { contentViewport.AddToClassList("HorizontalScroll"); } else { contentViewport.RemoveFromClassList("HorizontalScroll"); } } if (verticalScroller.visible != needsVertical) { verticalScroller.visible = needsVertical; if (needsVertical) { contentViewport.AddToClassList("VerticalScroll"); } else { contentViewport.RemoveFromClassList("VerticalScroll"); } } UpdateContentViewTransform(); }