From 671366cd56e7d6b2a2afb0839e7fb0f895cb2df3 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Wed, 21 Oct 2015 12:03:07 +0200 Subject: [PATCH] reset scrollX and Y when scroller child is group and it's children have been cleared --- src/GraphicObjects/Group.cs | 5 +++++ src/GraphicObjects/Scroller.cs | 33 +++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 78378aa8..bf04617d 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -19,6 +19,10 @@ namespace go } #endregion + #region EVENT HANDLERS + public event EventHandler ChildrenCleared; + #endregion + bool _multiSelect = false; List children = new List(); @@ -63,6 +67,7 @@ namespace go Children.Remove(g); } this.RegisterForLayouting ((int)LayoutingType.Sizing); + ChildrenCleared.Raise (this, new EventArgs ()); } public void putWidgetOnTop(GraphicObject w) { diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index b0fdc120..8c2303cc 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -105,20 +105,41 @@ namespace go #region GraphicObject Overrides void OnChildLayoutChanges (object sender, LayoutChangeEventArgs arg) { + int maxScroll = MaximumScroll; if (_verticalScrolling) { - if (arg.LayoutType == LayoutingType.Height) - ValueChanged.Raise(this, new ValueChangeEventArgs("MaximumScroll", MaximumScroll)); - }else if (arg.LayoutType == LayoutingType.Width) - ValueChanged.Raise(this, new ValueChangeEventArgs("MaximumScroll", MaximumScroll)); + if (arg.LayoutType == LayoutingType.Height) { + if (maxScroll < ScrollY) { + Debug.WriteLine ("scrolly={0} maxscroll={1}", ScrollY, maxScroll); + ScrollY = 0; + } + ValueChanged.Raise (this, new ValueChangeEventArgs ("MaximumScroll", maxScroll)); + } + } else if (arg.LayoutType == LayoutingType.Width) { + if (maxScroll < ScrollX) + ScrollX = 0; + ValueChanged.Raise (this, new ValueChangeEventArgs ("MaximumScroll", maxScroll)); + } + } + void onChildListCleared(object sender, EventArgs e){ + ScrollY = 0; + ScrollX = 0; } public override T SetChild (T _child) { GraphicObject c = child as GraphicObject; - if (c != null) + Group g = child as Group; + if (c != null) { c.LayoutChanged -= OnChildLayoutChanges; + if (g != null) + g.ChildrenCleared -= onChildListCleared; + } c = _child as GraphicObject; - if (c != null) + g = _child as Group; + if (c != null) { c.LayoutChanged += OnChildLayoutChanges; + if (g != null) + g.ChildrenCleared += onChildListCleared; + } return base.SetChild (_child); } #endregion -- 2.47.3