/// <summary> /// Adds a <see cref="ScoreInfo"/> to this list. /// </summary> /// <param name="score">The <see cref="ScoreInfo"/> to add.</param> /// <param name="isNewLocalScore">Whether this is a score that has just been achieved locally. Controls whether flair is added to the display or not.</param> public ScorePanel AddScore(ScoreInfo score, bool isNewLocalScore = false) { var panel = new ScorePanel(score, isNewLocalScore) { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, PostExpandAction = () => PostExpandAction?.Invoke() }.With(p => { p.StateChanged += s => { if (s == PanelState.Expanded) { SelectedScore.Value = p.Score; } }; }); var trackingContainer = panel.CreateTrackingContainer().With(d => { d.Anchor = Anchor.Centre; d.Origin = Anchor.Centre; d.Hide(); }); flow.Add(trackingContainer); if (IsLoaded) { displayScore(trackingContainer); } return(panel); }
/// <summary> /// Adds a <see cref="ScoreInfo"/> to this list. /// </summary> /// <param name="score">The <see cref="ScoreInfo"/> to add.</param> /// <param name="isNewLocalScore">Whether this is a score that has just been achieved locally. Controls whether flair is added to the display or not.</param> public ScorePanel AddScore(ScoreInfo score, bool isNewLocalScore = false) { var panel = new ScorePanel(score, isNewLocalScore) { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, PostExpandAction = () => PostExpandAction?.Invoke() }.With(p => { p.StateChanged += s => { if (s == PanelState.Expanded) { SelectedScore.Value = p.Score; } }; }); flow.Add(panel.CreateTrackingContainer().With(d => { d.Anchor = Anchor.Centre; d.Origin = Anchor.Centre; })); if (IsLoaded) { if (SelectedScore.Value == score) { SelectedScore.TriggerChange(); } else { // We want the scroll position to remain relative to the expanded panel. When a new panel is added after the expanded panel, nothing needs to be done. // But when a panel is added before the expanded panel, we need to offset the scroll position by the width of the new panel. if (expandedPanel != null && flow.GetPanelIndex(score) < flow.GetPanelIndex(expandedPanel.Score)) { // A somewhat hacky property is used here because we need to: // 1) Scroll after the scroll container's visible range is updated. // 2) Scroll before the scroll container's scroll position is updated. // Without this, we would have a 1-frame positioning error which looks very jarring. scroll.InstantScrollTarget = (scroll.InstantScrollTarget ?? scroll.Target) + ScorePanel.CONTRACTED_WIDTH + panel_spacing; } } } return(panel); }