private IEnumerator <object> DragSeparatorTask(int index) { RaiseDragStarted(); var initialMousePosition = Input.MousePosition; var initialHeights = Nodes.Select(i => i.AsWidget.Height).ToList(); while (Input.IsMousePressed()) { WidgetContext.Current.MouseCursor = MouseCursor.SizeNS; var dragDelta = Input.MousePosition.Y - initialMousePosition.Y; AdjustStretchDelta(initialHeights[index], Nodes[index].AsWidget, ref dragDelta); dragDelta = -dragDelta; AdjustStretchDelta(initialHeights[index + 1], Nodes[index + 1].AsWidget, ref dragDelta); dragDelta = -dragDelta; for (int i = 0; i < Nodes.Count; i++) { var d = (i == index) ? dragDelta : ((i == index + 1) ? -dragDelta : 0); if (i == Stretches.Count) { Stretches.Add(0); } Stretches[i] = initialHeights[i] + d; } Layout.InvalidateConstraintsAndArrangement(); yield return(null); } RaiseDragEnded(); }
public void Add(TrackStretch stretch) { if (stretch == null) { throw new ArgumentNullException(nameof(stretch)); } if (Stretches.Count > 0 && stretch.End.Station.Equals(Stretches.Last().Start.Station)) { Stretches.Insert(0, stretch); } else { Stretches.Add(stretch); } }
public double DistanceToStation(Station station) { if (station == null) { throw new ArgumentNullException(nameof(station)); } if (station.Equals(Stretches[0].Start.Station)) { return(0); } var stretch = Stretches.FirstOrDefault(s => s.End.Station.Equals(station)); if (stretch == null) { throw new ArgumentOutOfRangeException(nameof(station), string.Format(CultureInfo.CurrentCulture, Resources.Strings.TheStationNameIsNotPartOfTheStretch, station.Name)); } return(Stretches.Take(Stretches.IndexOf(stretch) + 1).Sum(s => s.Distance)); }
public override string ToString() { return(string.Format(CultureInfo.CurrentCulture, "{0}: {1} - {2}", Number, Stretches[0].Start.Station, Stretches.Last().End.Station)); }