public void AddCustomControl(GHControl customControl) { if (customControl != null) { // check for prexisting data ; CustomControls.Add(customControl.Name, customControl); customControl.SetAttribute((GHCustomAttributes)m_attributes); } }
/// <summary> /// retrive the value of the custom control by name. /// if the path is invalid or the control is not a parameter then thorws an exception. /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value">the current value of the control</param> /// <param name="path">path to the control</param> /// <returns></returns> public void GetControlData <T>(ref T value, params string[] path) { GHControl control = GetControl(path); if (control is GHParameter) { GHParameter param = (GHParameter)control; value = (T)param.CurrentValue; return; } throw new Exception("Invalid path to control"); }
public GHControl GetControl(params string[] path) { GHControl ct = CustomControls[path[0]]; if (path.Length == 1) { return(ct); } if (ct is IGHPanel) { return(((IGHPanel)ct).GetControl(path.Skip(1))); } throw new Exception("Invalid path."); }
/// <summary> /// get access to the child control in the panel and its children by set of the names (path). /// The path must start with a child name. /// throw exception if the path is not valid /// </summary> /// <param name="gHContainer"></param> /// <param name="path"></param> /// <returns></returns> public static GHControl GetControl(this IGHPanel gHContainer, IEnumerable <string> path) { string name = path.First(); GHControl ct = gHContainer.Items.FirstOrDefault(item => item.Name == name); if (ct == null) { throw new Exception($"Invalid path, unable to find child control in control {gHContainer.Name}"); } if (path.Count() == 1) { return(ct); } else if (ct is IGHPanel) { return(GetControl((IGHPanel)ct, path.Skip(1))); } else { throw new Exception($"Invalid path, Expected an IGHPanel in {gHContainer.Name} found {ct.GetType()}"); } }
/// <summary> /// return the defualt brush based on the control state (enable or disable) /// </summary> /// <param name="control"></param> /// <returns></returns> public static Brush ActiveBrush(this GHControl control) { return((control.Enabled) ? Brushes.Black : Brushes.Gray); }
public void Add(GHControl control) { control.attributes = attributes; Items = Items.Append(control).ToArray(); }