Ejemplo n.º 1
0
        void LayoutChanged()
        {
            var w = RectTransform.Width;
            var h = RectTransform.Height;
            var prevModSplitterPos = _modSplitterPos;

            _modSplitterPos = Math.Min(_splitterMax, Math.Max(_splitterMin, _splitterPos));
            var splitterMaxCollapseThreshold = 100 - (100 - _splitterMax) / 2;

            if (CanCollapse)
            {
                if (_splitterPos < _splitterMin / 2)
                {
                    _modSplitterPos = 0;
                }

                if (_splitterPos > splitterMaxCollapseThreshold)
                {
                    _modSplitterPos = 100;
                }
            }
            _paneA.Active = _modSplitterPos >= _splitterMin;
            _paneB.Active = _modSplitterPos <= _splitterMax;

            bool modSplitterCollapsed = _modSplitterPos <_splitterMin / 2 || _modSplitterPos> splitterMaxCollapseThreshold;
            bool prevModSplitterCollapsed = prevModSplitterPos <_splitterMin / 2 || prevModSplitterPos> splitterMaxCollapseThreshold;

            if (prevModSplitterCollapsed != modSplitterCollapsed)
            {
                CollapsedChanged?.Invoke(modSplitterCollapsed);
            }

            if (_isVertical)
            {
                var splitterOfs = _splitterWidth / 2 + _modSplitterPos * (w - _splitterWidth) / 100.0f;
                _paneA.RectTransform.Size            = new Point(splitterOfs - _splitterWidth / 2, h);
                _paneA.RectTransform.Padding.TopLeft = new Point(splitterOfs / 2 - _splitterWidth / 4, h / 2);

                _paneB.RectTransform.Size            = new Point(w - splitterOfs - _splitterWidth / 2, h);
                _paneB.RectTransform.Padding.TopLeft = new Point(splitterOfs + _splitterWidth / 2 + (w - splitterOfs - _splitterWidth / 2) / 2, h / 2);

                _splittBar.RectTransform.Size         = new Point(_splitterWidth, h - 10);
                _splittBar.RectTransform.Padding.Top  = h / 2;
                _splittBar.RectTransform.Padding.Left = splitterOfs;
            }
            else
            {
                var splitterOfs = _splitterWidth / 2 + _modSplitterPos * (h - _splitterWidth) / 100.0f;
                _paneA.RectTransform.Size            = new Point(w, splitterOfs - _splitterWidth / 2);
                _paneA.RectTransform.Padding.TopLeft = new Point(w / 2, splitterOfs / 2 - _splitterWidth / 4);

                _paneB.RectTransform.Size            = new Point(w, h - splitterOfs - _splitterWidth / 2);
                _paneB.RectTransform.Padding.TopLeft = new Point(w / 2, splitterOfs + _splitterWidth / 2 + (h - splitterOfs - _splitterWidth / 2) / 2);

                _splittBar.RectTransform.Size         = new Point(w - 10, _splitterWidth);
                _splittBar.RectTransform.Padding.Left = w / 2;
                _splittBar.RectTransform.Padding.Top  = splitterOfs;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Event handler for toggling the collapsed state
 /// that can be used on the corresponding HTML element.
 /// </summary>
 /// <param name="args">Click arguments.</param>
 /// <returns>A task for the function.</returns>
 public async Task ToggleClicked(MouseEventArgs args)
 {
     Collapsed = !Collapsed;
     await CollapsedChanged.InvokeAsync(Collapsed);
 }