internal void ButtonSelected(HoverButton button) { // If a heading is clicked, hide/show all buttons below if (button.IsHeading) { if (!button.ChildrenAreHidden) { HideChildren(button); } else { ShowChildren(button); } return; } if (SelectedButton != null) { SelectedButton.Unselect(); } SelectedButton = button; if (ButtonClickedEvent != null) { ButtonClickedEvent(null, button.Text.Trim(), button.Tag); } }
private void HideChildren(HoverButton button) { if (button.IsHeading) { // Hide the children of this heading int currentBottom = button.Bottom; bool haveReachedNextHeading = false; for (int i = button.Index + 1; i < Buttons.Count; i++) { HoverButton nextButton = (HoverButton)Buttons[i]; if (nextButton.IsHeading) { haveReachedNextHeading = true; } if (!haveReachedNextHeading) { nextButton.Visible = false; } else { nextButton.Top = currentBottom; currentBottom += nextButton.Height; } } button.ChildrenAreHidden = true; } else { throw new InvalidOperationException("HideChildren can only be called by Heading buttons."); } }
public void Add(HoverButton button) { Slyce.Common.Utility.CheckForNulls(new object[] { button }, new string[] { "button" }); ButtonHeight = button.Height; button.Width = this.ClientSize.Width; button.ParentList = this; button.Left = 0; if (Buttons.Count > 0) { HoverButton prevButton = (HoverButton)Buttons[Buttons.Count - 1]; button.Top = prevButton.Top + prevButton.Height; } else { button.Top = 0; } panel.Controls.Add(button); Buttons.Add(button); }
private void ShowChildren(HoverButton button) { if (button.IsHeading) { // Hide the children of this heading int currentBottom = button.Bottom; bool haveReachedNextHeading = false; for (int i = button.Index + 1; i < Buttons.Count; i++) { HoverButton nextButton = (HoverButton)Buttons[i]; if (nextButton.IsHeading) { haveReachedNextHeading = true; } if (!haveReachedNextHeading && !nextButton.Visible) { nextButton.Visible = true; nextButton.Top = currentBottom; currentBottom = nextButton.Bottom; } else if (haveReachedNextHeading && nextButton.Visible) { nextButton.Top = currentBottom; currentBottom = nextButton.Bottom; } } button.ChildrenAreHidden = false; } else { throw new InvalidOperationException("HideChildren can only be called by Heading buttons."); } }