Пример #1
0
        protected TwoPanelsWithResizer(
            Hideability hideable, int minPanelSizePx, Tuple <int?, int?> fixedSize, SpacingPolicy?spacingPolicy)
        {
            MinPanelSizePx = minPanelSizePx;

            if (fixedSize == null && !spacingPolicy.HasValue ||
                fixedSize != null && spacingPolicy.HasValue ||
                fixedSize != null && fixedSize.Item1.HasValue && fixedSize.Item2.HasValue ||
                fixedSize != null && !fixedSize.Item1.HasValue && !fixedSize.Item2.HasValue)
            {
                throw new Exception("Either spacing policy needs to be provided OR exactly one fixedSize dimension");
            }

            Hideable             = hideable;
            _fixedSize           = fixedSize;
            _spacingPolicy       = spacingPolicy;
            _container.ClassName = GetType().FullName;
            _container.Id        = UniqueIdGenerator.GenerateAsString();
            _splitter.ClassName  = Magics.CssClassSplitter;

            _container.AppendChild(FirstPanel);
            _container.AppendChild(_splitter);
            _container.AppendChild(SecondPanel);

            _splitter.OnTouchStart += x => {
                if (!x.HasHtmlTarget())
                {
                    return;
                }

                var htmlTarget = x.HtmlTarget();

                if (!htmlTarget.IsElementOrItsDescendant(_splitter))
                {
                    return;
                }

                _isDragging = true;
                _touchId    = x.TargetTouches[0].Identifier;
                Logger.Debug(GetType(), "TouchStart {0}", _touchId);
            };

            _splitter.OnTouchEnd += ev => {
                _isDragging = false;
                _touchId    = 0;
                Logger.Debug(GetType(), "TouchEnd {0}", _touchId);
            };

            _splitter.OnTouchMove += ev => {
                if (!_isDragging)
                {
                    return;
                }

                var touch = ev.Touches.FirstOrDefault(x => x.Identifier == _touchId);

                Logger.Debug(GetType(), "TouchMove {0} present?={1}", _touchId, touch != null);

                if (touch == null)
                {
                    return;
                }

                var sizes = CalculateSizesOnUserResize(touch.PageX, touch.PageY);

                if (sizes.Item1 < minPanelSizePx || sizes.Item2 < minPanelSizePx)
                {
                    return;
                }
                Logger.Debug(GetType(), "updating sizes for panelType={0} id={1} to ({2}; {3})", GetType().FullName, _container.Id, sizes.Item1, sizes.Item2);

                _container.AddClasses(Magics.CssClassActive);
                ev.PreventDefault();
                Sizes = sizes;
                SetPanelsSize(sizes);
            };

            DocumentUtil.AddMouseDownListener(_splitter, x => {
                if (!x.HasHtmlTarget())
                {
                    return;
                }

                var htmlTarget = x.HtmlTarget();

                if (!htmlTarget.IsElementOrItsDescendant(_splitter))
                {
                    return;
                }

                _isDragging = true;
                x.PreventDefault();
            });

            DocumentUtil.AddMouseUpListener(_splitter, x => {
                _isDragging = false;
            });

            DocumentUtil.AddMouseMoveListener(_splitter, ev => {
                if (!_isDragging)
                {
                    return;
                }
                ev.PreventDefault();

                var sizes = CalculateSizesOnUserResize(ev.PageX, ev.PageY);

                if (sizes.Item1 < minPanelSizePx || sizes.Item2 < minPanelSizePx)
                {
                    return;
                }
                Logger.Debug(GetType(), "updating sizes for panelType={0} id={1} to ({2}; {3})", GetType().FullName, _container.Id, sizes.Item1, sizes.Item2);

                _container.AddClasses(Magics.CssClassActive);

                Sizes = sizes;
                SetPanelsSize(sizes);
            });

            DocumentUtil.AddElementAttachedToDocumentListener(_container, InitializeWidthsOnAttachOrResize);
            DocumentUtil.AddElementResizeListener(_container, InitializeWidthsOnAttachOrResize);
        }
Пример #2
0
        private HorizontalTabbedView(Action <HorizontalTabbedView> addTabs)
        {
            _container = new HTMLDivElement {
                Id        = UniqueIdGenerator.GenerateAsString(),
                ClassName = GetType().FullName
            };

            _tabHandleContainer = new HTMLDivElement {
                ClassName = Magics.CssClassTabHandleContainer
            };

            _tabContentContainer = new HTMLDivElement {
                ClassName = Magics.CssClassTabContentContainer
            };

            _container.AppendChild(_tabHandleContainer);
            _container.AppendChild(_tabContentContainer);

            _tabHandleContainer.OnClick += ev => {
                if (!ev.HasHtmlTarget())
                {
                    return;
                }

                var target = ev.HtmlTarget();

                if (target == _tabHandleContainer)
                {
                    return;
                }

                var newActiveTabHandle = target.GetParentElementHavingParent(_tabHandleContainer);
                var newActiveTabIdx    = _tabHandleContainer.Children.IndexOfUsingEquals(newActiveTabHandle);

                if (_activeTab == newActiveTabIdx)
                {
                    Logger.Debug(GetType(), "already active tab selected {0}", _activeTab);
                    return;
                }

                Logger.Debug(GetType(), "switching tab from {0} to {1}", _activeTab, newActiveTabIdx);

                if (newActiveTabIdx < 0 || newActiveTabIdx >= _tabContents.Count)
                {
                    Logger.Error(GetType(), "there's no tab at index {0}. ignoring tab switch", newActiveTabIdx);
                    return;
                }

                if (_activeTab >= 0)
                {
                    _tabHandleContainer.Children[_activeTab].ClassList.Remove(Magics.CssClassActive);
                    _tabContentContainer.RemoveAllChildren();
                }

                ActivateTab(newActiveTabIdx);
            };

            addTabs(this);

            DocumentUtil.AddElementAttachedToDocumentListener(_container, () => {
                if (_measured)
                {
                    return;
                }

                var formerlyFocused = Document.ActiveElement;
                Logger.Debug(GetType(), "Measuring tab heights in onAttached");

                // measure tab content
                var oldVis = _tabContentContainer.Style.Visibility;
                _tabContentContainer.Style.Visibility = Visibility.Hidden;

                _tabContents.ForEachI((i, tab) => {
                    _tabContentContainer.RemoveAllChildren();
                    _tabContentContainer.AppendChild(tab);
                });

                _tabContentContainer.RemoveAllChildren();
                _tabContentContainer.Style.Visibility = oldVis;
                _measured = true;

                //assure that focused element within tab stays focused(it may have been lost during measurement process above)
                if (_tabContents.Any())
                {
                    ActivateTab(_activeTab);
                    if (formerlyFocused != Document.ActiveElement)
                    {
                        formerlyFocused.TryFocusElement();
                    }
                }
            });

            //activate first tab
            if (_tabContents.Any())
            {
                ActivateTab(0);
            }
        }
Пример #3
0
 public static void AddAttachedToDocumentEventListener(this Element self, Action action)
 {
     DocumentUtil.AddElementAttachedToDocumentListener(self, action);
 }