private bool removeCharacterOrSelection(bool sound = true) { if (InternalText.Length == 0) { return(false); } if (selectionLength == 0 && selectionLeft == 0) { return(false); } int count = MathHelper.Clamp(selectionLength, 1, InternalText.Length); int start = MathHelper.Clamp(selectionLength > 0 ? selectionLeft : selectionLeft - 1, 0, InternalText.Length - count); if (count == 0) { return(false); } if (sound) { audio.Sample.Get(@"Keyboard/key-delete")?.Play(); } foreach (var d in textFlow.Children.Skip(start).Take(count).ToArray()) //ToArray since we are removing items from the children in this block. { textFlow.Remove(d); textContainer.Add(d); d.FadeOut(200); d.MoveToY(d.DrawSize.Y, 200, EasingTypes.InExpo); d.Expire(); } InternalText = InternalText.Remove(start, count); if (selectionLength > 0) { selectionStart = selectionEnd = selectionLeft; } else { selectionStart = selectionEnd = selectionLeft - 1; } cursorAndLayout.Invalidate(); return(true); }
private bool removeCharacterOrSelection(bool sound = true) { if (text.Length == 0) { return(false); } if (selectionLength == 0 && selectionLeft == 0) { return(false); } int count = MathHelper.Clamp(selectionLength, 1, text.Length); int start = MathHelper.Clamp(selectionLength > 0 ? selectionLeft : selectionLeft - 1, 0, text.Length - count); if (count == 0) { return(false); } if (sound) { Game.Audio.Sample.Get(@"Keyboard/key-delete")?.Play(); } textFlow.Children.Skip(start).Take(count).ToList().ForEach(d => { textFlow.Remove(d); TextContainer.Add(d); d.FadeOut(200); d.MoveToY(d.Size.Y, 200, EasingTypes.InExpo); d.Expire(); }); text = text.Remove(start, count); if (selectionLength > 0) { selectionStart = selectionEnd = selectionLeft; } else { selectionStart = selectionEnd = selectionLeft - 1; } cursorAndLayout.Invalidate(); return(true); }
private void newMessages(IEnumerable <Message> newMessages) { if (!IsLoaded) { return; } var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY)); //up to last Channel.MAX_HISTORY messages foreach (Message m in displayMessages) { flow.Add(new ChatLine(m)); } while (flow.Children.Count() > Channel.MAX_HISTORY) { flow.Remove(flow.Children.First()); } }