private void GetAllParentsChild(Z80NavBar.NavBarItem clickedItem, Z80NavBar.NavBarItem item, int?parentID) { foreach (var c in item.Childs) { if (c.ID == clickedItem.ID) { if (c.Childs != null && c.Childs.Count > 0) { _parentID_List.Add(c.ID); } else if (parentID != null) { _parentID_List.Add((int)parentID); } _bChildFound = true; return; } if (c.Childs != null && c.Childs.Count > 0) { GetAllParentsChild(clickedItem, c, c.ID); if (_bChildFound) { _parentID_List.Add(c.ID); break; // foreach Exit For } } } }
private void GetAllParents(Z80NavBar.NavBarItem clickedItem) { foreach (var nbi in _navBarItems) { _parentID_List = new List <int>(); if (nbi.ID == clickedItem.ID) { _bChildFound = true; _parentID_List.Add(nbi.ID); break; // foreach Exit For } else { if (nbi.Childs != null && nbi.Childs.Count > 0) { GetAllParentsChild(clickedItem, nbi, nbi.ParentID); if (_bChildFound) { _parentID_List.Add(nbi.ID); break; // foreach Exit For } } } } }
/// <summary> /// Draw child items (Recursive) /// </summary> /// <param name="item"></param> private void DrawChilds(Z80NavBar.NavBarItem item) { if (item.Expanded & item.Visible) { foreach (var c in item.Childs) { if (c.Visible) { NavBarItemPanel mPanel = new NavBarItemPanel(); mPanel.Location = new Point(0, _item_yLocation); mPanel.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; _item_yLocation += c.Height; mPanel.Initialize(c, this.Width, _theme, _childDepth); mPanel.ItemClick += OnItemClick; Panel1.Controls.Add(mPanel); if (c.Childs != null && c.Childs.Count > 0) { _childDepth += 1; DrawChilds(c); _childDepth -= 1; } } } } }
/// <summary> /// Add a new item (always a child) in run-time to navigation control /// </summary> /// <param name="parentID">Parent ID</param> /// <param name="text">Text for this new item</param> /// <param name="itemID">The new item ID. Make sure that new item no longer exist in any other ithem</param> /// <param name="leftChild">Optional value for left text position</param> public void AddItem(int parentID, string text, int itemID, int leftChild = 10) { foreach (var nbi in _navBarItems) { if (nbi.ID == parentID) { if (nbi.Childs == null) { nbi.Childs = new List <Z80NavBar.NavBarItem>(); } Z80NavBar.NavBarItem newItem = new Z80NavBar.NavBarItem { ID = itemID, ParentID = parentID, Text = text }; nbi.Childs.Add(newItem); } else { if (nbi.Childs != null && nbi.Childs.Count > 0) { AddChild(nbi, parentID, text, itemID, leftChild); } } } DrawControlItems(); }
private void GetFirsAvailable(Z80NavBar.NavBarItem clickedItem) { if (clickedItem.Childs[0].Childs != null && clickedItem.Childs.Count > 0) { _parentID_List.Add(clickedItem.Childs[0].ID); GetFirsAvailable(clickedItem.Childs[0]); } }
private void AutoExpand(Z80NavBar.NavBarItem clickedItem, Z80NavBar.NavBarItem item) { foreach (var nbi in item.Childs) { if (_parentID_index == _parentID_List.Count) { break; // foreach Exit For } if (nbi.ID == _parentID_List[_parentID_index]) { _parentID_index += 1; nbi.Selected = true; nbi.Expanded = true; if (_parentID_index < _parentID_List.Count) { AutoExpand(clickedItem, nbi); } else { if (nbi.ParentID == clickedItem.ParentID | (clickedItem.ParentID == null)) { nbi.Content = true; nbi.Childs[0].Selected = true; finalSelectedItem = nbi.Childs[0]; SelectedItem?.Invoke(nbi.Childs[0]); } else { bool selected = false; foreach (var nbic in nbi.Childs) { if ((nbic.ID == clickedItem.ID)) { nbi.Content = true; nbic.Selected = true; nbi.Expanded = true; finalSelectedItem = clickedItem; selected = true; SelectedItem?.Invoke(clickedItem); break; // foreach Exit For } } if (!selected) { nbi.Content = true; nbi.Childs[0].Selected = true; finalSelectedItem = nbi.Childs[0]; SelectedItem?.Invoke(nbi.Childs[0]); } } break; // foreach Exit For } } } }
public void Initialize(Z80NavBar.NavBarItem navItem, int width, Z80NavBar.Themes.ITheme theme, int depth) { _navItem = navItem; _theme = theme; _depth = depth; this.Height = navItem.Height; this.Width = width; this.BackColor = theme.BackgroundColor(depth); _initialized = true; }
private void ResetAll(Z80NavBar.NavBarItem item) { foreach (var c in item.Childs) { c.Selected = false; c.Expanded = false; c.Content = false; if (c.Childs != null && c.Childs.Count > 0) { ResetAll(c); } } }
private void VisibilityItemChild(Z80NavBar.NavBarItem item, bool visible, int itemID) { foreach (var c in item.Childs) { if (c.ID == itemID) { c.Visible = visible; } if (c.Childs != null && c.Childs.Count > 0) { VisibilityItemChild(c, visible, itemID); } } }
private void EnableItemChild(Z80NavBar.NavBarItem item, bool enable, int itemID) { foreach (var c in item.Childs) { if (c.ID == itemID) { c.Enabled = enable; } if (c.Childs != null && c.Childs.Count > 0) { EnableItemChild(c, enable, itemID); } } }
private void ResetAllSelect(Z80NavBar.NavBarItem item, int itemID) { foreach (var c in item.Childs) { c.Selected = false; c.Expanded = false; c.Content = false; if (c.ID == itemID) { _JRIT_item = c; } if (c.Childs != null && c.Childs.Count > 0) { ResetAllSelect(c, itemID); } } }
/// <summary> /// Select item in run-time /// </summary> /// <param name="itemID">item ID we want to select</param> public void ItemSelect(int itemID) { foreach (var nbi in _navBarItems) { nbi.Selected = false; nbi.Expanded = false; nbi.Content = false; if (nbi.ID == itemID) { _JRIT_item = nbi; } if (nbi.Childs != null && nbi.Childs.Count > 0) { ResetAllSelect(nbi, itemID); } } OnItemClick(_JRIT_item); }
private void AddChild(Z80NavBar.NavBarItem item, int parentID, string text, int itemID, int leftChild = 10) { foreach (var c in item.Childs) { if (c.ID == parentID) { if (c.Childs == null) { c.Childs = new List <Z80NavBar.NavBarItem>(); } Z80NavBar.NavBarItem newItem = new Z80NavBar.NavBarItem { ID = itemID, ParentID = parentID, Text = text, LeftChild = leftChild }; c.Childs.Add(newItem); } if (c.Childs != null && c.Childs.Count > 0) { AddChild(c, parentID, text, itemID, leftChild); } } }
/// <summary> /// This item is fired when we click on a NavBarItemPanel UserControl /// </summary> /// <param name="item"></param> private void OnItemClick(Z80NavBar.NavBarItem item) { // By default we 'reset' all items as: // Not selected // Not expanded // Not Content // ----------------------------------------------------------------------------------------- foreach (var nbi in _navBarItems) { nbi.Selected = false; nbi.Expanded = false; nbi.Content = false; if (nbi.Childs != null && nbi.Childs.Count > 0) { ResetAll(nbi); } } // ----------------------------------------------------------------------------------------- _parentID_List = new List <int>(); GetAllParents(item); _parentID_List = _parentID_List.Distinct().ToList(); _parentID_List.Reverse(); _bChildFound = false; // Get the 1st available item : if (item.Childs != null && item.Childs.Count > 0) { GetFirsAvailable(item); } _parentID_index = 0; foreach (var nbi in _navBarItems) { if (nbi.ID == _parentID_List[0]) { _parentID_index += 1; nbi.Selected = true; nbi.Expanded = true; if (_parentID_List.Count == 1) { nbi.Content = true; if (item.ParentID != null) { var p = _navBarItems.Find(c => c.ID == item.ParentID); p.Selected = true; p.Expanded = true; item.Selected = true; finalSelectedItem = item; SelectedItem?.Invoke(item); break; // foreach Exit For } else // autoexpand first child or root { if (nbi.Childs != null && nbi.Childs.Count > 0) { nbi.Childs[0].Selected = true; finalSelectedItem = nbi.Childs[0]; SelectedItem?.Invoke(nbi.Childs[0]); } else { finalSelectedItem = item; SelectedItem?.Invoke(item); } } } else { AutoExpand(item, nbi); } } } _parentID_index = 0; DrawControlItems(); }