Ejemplo n.º 1
0
 private TwoHorizontalPanelsWithResizer(
     Hideability hideable, Tuple <int?, int?> fixedSize, SpacingPolicy?policy,
     int minPanelSizePx = DefaultPanelSizePx)
     : base(hideable, minPanelSizePx, fixedSize, policy)
 {
     Container.SetAttribute(Magics.AttrDataIsHorizontalPanel, "");
 }
Ejemplo n.º 2
0
        private static BuiltPanels <T> Builder <T>(
            T prototype, Hideability hideable, bool showable,
            IFormRenderer <HTMLElement> renderer) where T : TwoPanelsWithResizer
        {
            switch (hideable)
            {
            case Hideability.None:
                return(BuildNonhideable(prototype, renderer));

            case Hideability.First:
            case Hideability.Second:
                return(BuildHideable(
                           prototype,
                           hideable == Hideability.First,
                           showable,
                           renderer));

            default: throw new Exception("unsupported Hideability");
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public TwoHorizontalPanelsWithResizer(
     Hideability hideable, SpacingPolicy policy = SpacingPolicy.Proportional,
     int minPanelSizePx = DefaultPanelSizePx) : this(hideable, null, policy, minPanelSizePx)
 {
 }
Ejemplo n.º 5
0
 public TwoHorizontalPanelsWithResizer(
     Hideability hideable, Tuple <int?, int?> fixedSize, int minPanelSizePx = DefaultPanelSizePx)
     : this(hideable, fixedSize, null, minPanelSizePx)
 {
 }
Ejemplo n.º 6
0
 public static BuiltPanels <TwoHorizontalPanelsWithResizer> BuildHorizontal(
     Hideability hideable, bool showable, IFormRenderer <HTMLElement> renderer,
     Tuple <int?, int?> fixedSize)
 {
     return(Builder(new TwoHorizontalPanelsWithResizer(hideable, fixedSize), hideable, showable, renderer));
 }
Ejemplo n.º 7
0
 public static BuiltPanels <TwoHorizontalPanelsWithResizer> BuildHorizontal(
     Hideability hideable, bool showable, IFormRenderer <HTMLElement> renderer,
     SpacingPolicy policy = SpacingPolicy.Proportional)
 {
     return(Builder(new TwoHorizontalPanelsWithResizer(hideable, policy), hideable, showable, renderer));
 }