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); }
public static void AddResizeEventListener(this Element self, Action action) { DocumentUtil.AddElementResizeListener(self, action); }