From: Jean-Philippe Bruyère Date: Sat, 27 Mar 2021 13:10:39 +0000 (+0100) Subject: measure units preservation while resizing and lock updateMutex X-Git-Tag: v0.9.5-beta~48 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=eb5af95343473183385a4446f1a74c3ac39ad89c;p=jp%2Fcrow.git measure units preservation while resizing and lock updateMutex --- diff --git a/Crow/src/Widgets/Splitter.cs b/Crow/src/Widgets/Splitter.cs index b8d7a2fc..663177d0 100644 --- a/Crow/src/Widgets/Splitter.cs +++ b/Crow/src/Widgets/Splitter.cs @@ -58,29 +58,52 @@ namespace Crow public override void onMouseMove (object sender, MouseMoveEventArgs e) { GenericStack gs = Parent as GenericStack; + Rectangle gsRect = gs.ClientRectangle; Point m = gs.ScreenPointToLocal (e.Position); int ptrSplit = gs.Children.IndexOf (this); if (IFace.IsDown (Glfw.MouseButton.Left) && ptrSplit > 0 && ptrSplit < gs.Children.Count - 1) { - Widget w0 = gs.Children[ptrSplit - 1]; - Widget w1 = gs.Children[ptrSplit + 1]; - if (gs.Orientation == Orientation.Horizontal) { - int x = m.X - Slot.Width / 2 - gs.Spacing; + lock (IFace.UpdateMutex) { + Widget w0 = gs.Children[ptrSplit - 1]; + Widget w1 = gs.Children[ptrSplit + 1]; + if (gs.Orientation == Orientation.Horizontal) { + int x = m.X - Slot.Width / 2 - gs.Spacing; - if (x > w0.Slot.Left + w0.MinimumSize.Width && - x + Slot.Width + 2 * gs.Spacing < w1.Slot.Right - w1.MinimumSize.Width) { - w0.Width = x - w0.Slot.X; - x += Slot.Width + 2 * gs.Spacing; - w1.Width = w1.Slot.Right - x; - } - } else { - int y = m.Y - Slot.Height / 2 - gs.Spacing; + if (x > w0.Slot.Left + w0.MinimumSize.Width && + x + Slot.Width + 2 * gs.Spacing < w1.Slot.Right - w1.MinimumSize.Width) { + if (w0.Width != Measure.Stretched) { + if (w0.Width.IsRelativeToParent) + w0.Width = new Measure((int)Math.Round (100.0 * (x - w0.Slot.X) / (double)gsRect.Width), Unit.Percent); + else + w0.Width = x - w0.Slot.X; + } + if (w1.Width != Measure.Stretched) { + x += Slot.Width + 2 * gs.Spacing; + if (w1.Width.IsRelativeToParent) + w1.Width = new Measure((int)Math.Round (100.0 * (w1.Slot.Right - x) / (double)gsRect.Width), Unit.Percent); + else + w1.Width = w1.Slot.Right - x; + } + } + } else { + int y = m.Y - Slot.Height / 2 - gs.Spacing; - if (y > w0.Slot.Top + w0.MinimumSize.Height && - y + Slot.Height + 2 * gs.Spacing < w1.Slot.Bottom - w1.MinimumSize.Height) { - w0.Height = y - w0.Slot.Top; - y += Slot.Height + 2 * gs.Spacing; - w1.Height = w1.Slot.Bottom - y; + if (y > w0.Slot.Top + w0.MinimumSize.Height && + y + Slot.Height + 2 * gs.Spacing < w1.Slot.Bottom - w1.MinimumSize.Height) { + if (w0.Height != Measure.Stretched) { + if (w0.Height.IsRelativeToParent) + w0.Height = new Measure((int)Math.Round (100.0 * (y - w0.Slot.Top) / (double)gsRect.Height), Unit.Percent); + else + w0.Height = y - w0.Slot.Top; + } + if (w1.Height != Measure.Stretched) { + y += Slot.Height + 2 * gs.Spacing; + if (w1.Height.IsRelativeToParent) + w1.Height = new Measure((int)Math.Round (100.0 * (w1.Slot.Bottom - y) / (double)gsRect.Height), Unit.Percent); + else + w1.Height = w1.Slot.Bottom - y; + } + } } } e.Handled = true;