/// For use when in a custom window, draws the menu-bar. public void DrawMenuBar() { ImGuiCli.BeginMenuBar(); ImGuiCli.PushItemWidth(ImGuiCli.GetContentRegionAvailWidth() * 0.65f); filter_.Draw(ICON_FA.FILTER + " Filter"); ImGuiCli.SameLine(); ImGuiCli.SetCursorPosX(ImGuiCli.GetWindowWidth() - ImGuiCli.CalcTextSize(ICON_FA.EYE + ICON_FA.SORT_ALPHA_DOWN + " ").X - ImGuiStyle.FramePadding.X * 3); if (ImGuiCli.Button(IsAlphabetical ? ICON_FA.OBJECT_GROUP : ICON_FA.SORT_ALPHA_DOWN)) { IsAlphabetical = !IsAlphabetical; } if (ImGuiCli.IsItemHovered()) { ImGuiCli.SetTooltip(IsAlphabetical ? "Group fields" : "Order alphabetically"); } if (ImGuiCli.Button(IsAdvanced ? ICON_FA.EYE : ICON_FA.EYE_SLASH)) { IsAdvanced = !IsAdvanced; } if (ImGuiCli.IsItemHovered()) { ImGuiCli.SetTooltip(IsAdvanced ? "Showing advanced fields" : "Hiding advanced fields"); } ImGuiCli.EndMenuBar(); }
public void DrawAsWindow(string title) { if (ImGuiCli.Begin(title, ImGuiWindowFlags_.ResizeFromAnySide)) { Draw(); } ImGuiCli.End(); }
/// Makes ImGui calls to display as a window. public virtual void DrawAsWindow(string windowName) { if (ImGuiCli.Begin(windowName, ImGuiWindowFlags_.ResizeFromAnySide | ImGuiWindowFlags_.MenuBar)) { DrawMenuBar(); Draw(Inspecting); } ImGuiCli.End(); }
/// <summary> /// /// </summary> /// <param name="obj">Object the node is for</param> /// <param name="text">Desired text, not required to use</param> /// <param name="isSelected">Selection status of the node</param> protected virtual void DrawNodeObject(object obj, string text, bool isSelected) { // Insert an image here, preceded by an ImGuiCli.Sameline ImGuiCli.SameLine(); ImGuiCli.Selectable(text, isSelected); if (Selection != null && ImGuiCli.IsItemClicked(0)) { if (ImGuiIO.KeyCtrl) { if (isSelected) { Selection.Deselect(obj); } else { Selection.Select(obj, true); } } else { Selection.Select(obj, false); } } else if (ImGuiCli.IsItemClicked(1) && ContextMenu != null) { ImGuiCli.OpenPopup("###tree_ctx"); } if (ImGuiCli.BeginPopup("###tree_ctx", ImGuiWindowFlags_.None)) { ContextMenu(obj); ImGuiCli.EndPopup(); } if (DragConverter != null) { if (!ImGuiCli.IsPopupOpen() && ImGuiCli.BeginDragDropSource()) { ImGuiCli.SetDragDropPayload("U_TREE", DragConverter(obj)); ImGuiCli.Text(text); ImGuiCli.EndDragDropSource(); } else if (ImGuiCli.BeginDragDropTarget()) { string data = null; if (ImGuiCli.AcceptDragDropPayload("U_TREE", ref data)) { Selection.Drop(obj, data); } } } }
void Draw(IList list, int depth) { for (int i = 0; i < list.Count; ++i) { int id = unchecked (depth << 15 + i); ImGuiCli.PushID(id); object obj = list[i]; var listFields = cache_.GetAlphabetical(obj.GetType()).Where(f => typeof(IList).IsAssignableFrom(f.Type)).ToArray(); bool isLeaf = listFields == null || listFields.Length == 0; if (listFields.Length == 1) { isLeaf |= (listFields[0].GetValue(obj) as IList).Count == 0; } string text = StringConverter != null?StringConverter(obj) : obj.ToString(); ImGuiTreeNodeFlags_ nodeFlags = isLeaf ? ImGuiTreeNodeFlags_.Leaf : 0; bool isSelected = Selection != null?Selection.IsSelected(obj) : false; if (isSelected) { nodeFlags |= ImGuiTreeNodeFlags_.Selected; } bool open = ImGuiCli.TreeNodeEx("##" + id, nodeFlags); DrawNodeObject(obj, text, isSelected); if (open && listFields != null) { if (listFields.Length == 1) { Draw(listFields[0].GetValue(obj) as IList, unchecked (depth * 36 + i)); } else { // poly tree for (int listIdx = 0; listIdx < listFields.Length; ++listIdx) { if (ImGuiCli.TreeNode(listFields[listIdx].DisplayName)) { Draw(listFields[listIdx].GetValue(obj) as IList, depth + 1); ImGuiCli.TreePop(); } } } ImGuiCli.TreePop(); } ImGuiCli.PopID(); } }
public void DrawMenuBar() { ImGuiCli.BeginMenuBar(); if (!CurrentDirectory.EndsWith(":") && !CurrentDirectory.EndsWith(":\\")) { //ImGuiEx.PushBoldFont(); if (ImGuiCli.Button(ICON_FA.LEVEL_UP_ALT, new Vector2(32, 0))) { CurrentDirectory = System.IO.Directory.GetParent(CurrentDirectory).FullName; UpdateItems(); } if (ImGuiCli.IsItemHovered()) { ImGuiCli.SetTooltip("To parent directory"); } //ImGuiEx.PopFont(); } ImGuiCli.Text(CurrentDirectory); ImGuiCli.PushItemWidth(ImGuiCli.GetContentRegionAvailWidth() * 0.7f - 70); filter_.Draw(ICON_FA.FILTER + " Filter"); ImGuiCli.PopItemWidth(); //ImGuiEx.PushBoldFont(); ImGuiCli.SetCursorPosX(ImGuiCli.GetWindowWidth() - ImGuiCli.CalcTextSize(ICON_FA.LIST_UL + " + " + ICON_FA.STAR).X); //70); if (ImGuiCli.Button(ICON_FA.LIST_UL)) { asDetail_ = !asDetail_; } if (ImGuiCli.IsItemHovered()) { ImGuiCli.SetTooltip("Toggle details view"); } if (ImGuiCli.Button("+" + ICON_FA.STAR)) { if (!Favorites.Contains(CurrentDirectory)) { Favorites.Add(CurrentDirectory); } } if (ImGuiCli.IsItemHovered()) { ImGuiCli.SetTooltip("Add to favorites"); } //ImGuiEx.PopFont(); ImGuiCli.EndMenuBar(); }
void DrawTree(DirEntry entry) { float imgSize = ImGuiCli.GetFontSize(); for (int i = 0; i < entry.children_.Count; ++i) { string itemPath = entry.children_[i].directory_; string displayName = entry.children_[i].shortName_; string labelLessText = "##" + displayName; bool isLeaf = entry.children_[i].children_.Count == 0; bool isOpen = ImGuiCli.TreeNodeEx(labelLessText, isLeaf ? ImGuiTreeNodeFlags_.Leaf : ImGuiTreeNodeFlags_.None); ImGuiCli.SameLine(); bool isSelected = CurrentDirectory == itemPath; bool wasSelected = isSelected; isSelected = ImGuiCli.Selectable(labelLessText + "_select", wasSelected, ImGuiSelectableFlags_.SpanAllColumns); Texture2D thumbnail = thumbCache_.GetOrCreateThumbnail(itemPath); if (thumbnail != null) { ImGuiCli.SameLine(); ImGuiCli.Image(thumbnail, new Vector2(imgSize, imgSize)); } ImGuiCli.SameLine(); ImGuiCli.Text(displayName); if (isSelected != wasSelected) { CurrentDirectory = itemPath; UpdateItems(); } if (isOpen) { if (!isLeaf) { DrawTree(entry.children_[i]); } ImGuiCli.TreePop(); } } }
public void Draw() { if (newDirectory_ != null && newDirectory_ != CurrentDirectory) { CurrentDirectory = newDirectory_; UpdateItems(); } // Left hand side, draw the local roots, favorites and recent float totalWidth = ImGuiCli.GetContentRegionAvailWidth(); float w = totalWidth; float fontHeight = ImGuiCli.GetFontSize(); float fSize = fontHeight * 16; w = Math.Min(w * 0.33f, fSize); float yAvail = ImGuiCli.GetContentRegionAvail().Y; ImGuiCli.BeginChild("##folder_tree", new Vector2(w, yAvail), true); //ImGuiEx.PushBoldFont(); bool localOpen = ImGuiCli.CollapsingHeader(ICON_FA.FOLDER + " LOCAL"); //ImGuiEx.PopFont(); if (localOpen) { DrawTree(rootEntry_); } //ImGuiEx.PushBoldFont(); bool favoritesOpen = ImGuiCli.CollapsingHeader(ICON_FA.STAR + " FAVORITES"); //ImGuiEx.PopFont(); if (favoritesOpen) { ImGuiCli.Indent(); for (int i = 0; i < Favorites.Count; ++i) { ImGuiCli.PushID(i + 1); Texture2D thumbnail = thumbCache_.GetOrCreateThumbnail(Favorites[i]); if (thumbnail != null) { ImGuiCli.Image(thumbnail, new Vector2(fontHeight, fontHeight)); ImGuiCli.SameLine(); } string dispValue = Favorites[i].Substring(Favorites[i].Substring(0, Favorites[i].LastIndexOf("\\")).LastIndexOf("\\") + 1); ImGuiCli.Text(dispValue); if (ImGuiCli.IsItemClicked(0)) { CurrentDirectory = Favorites[i]; UpdateItems(); } else if (ImGuiCli.IsItemClicked(1)) { ImGuiCli.OpenPopup("#favorite_ctx"); } if (ImGuiCli.BeginPopup("#favorite_ctx", ImGuiWindowFlags_.None)) { if (ImGuiCli.MenuItem(ICON_FA.MINUS + " Remove")) { Favorites.RemoveAt(i); --i; } ImGuiCli.EndPopup(); } ImGuiCli.PopID(); } ImGuiCli.Unindent(); } //ImGuiEx.PushBoldFont(); bool recentOpen = ImGuiCli.CollapsingHeader(ICON_FA.CLOCK + " RECENT"); //ImGuiEx.PopFont(); if (recentOpen) { ImGuiCli.Indent(); for (int i = 0; i < Recents.Count; ++i) { ImGuiCli.PushID(i + 1); Texture2D thumbnail = thumbCache_.GetOrCreateThumbnail(Recents[i]); if (thumbnail != null) { ImGuiCli.Image(thumbnail, new Vector2(fontHeight, fontHeight)); ImGuiCli.SameLine(); } string dispValue = Recents[i].Substring(Recents[i].Substring(0, Recents[i].LastIndexOf("\\")).LastIndexOf("\\") + 1); ImGuiCli.Text(dispValue); if (ImGuiCli.IsItemClicked(0)) { CurrentDirectory = Recents[i]; UpdateItems(); } else if (ImGuiCli.IsItemClicked(1)) { ImGuiCli.OpenPopup("#Recents_ctx"); } if (ImGuiCli.BeginPopup("#Recents_ctx", ImGuiWindowFlags_.None)) { if (ImGuiCli.MenuItem(ICON_FA.MINUS + " Remove")) { Recents.RemoveAt(i); --i; } ImGuiCli.EndPopup(); } ImGuiCli.PopID(); } ImGuiCli.Unindent(); } ImGuiCli.EndChild(); ImGuiCli.SameLine(); // Right hand side, list the current items float contentWidth = totalWidth - w - ImGuiStyle.WindowPadding.X; ImGuiCli.BeginChild("##dir_content_region", new Vector2(contentWidth, yAvail), true); float itemSize = asDetail_ ? 48 : 128; int columns = (int)(contentWidth / (asDetail_ ? 256.0f : 128.0f)); columns = columns < 1 ? 1 : columns; ImGuiCli.Columns(columns, false); for (int i = 0; i < currentItems_.Count; ++i) { string item = currentItems_[i]; if (item == "." || item == "..") { continue; } if (ExcludeFilesystemItem(item)) { continue; } string displayName = item.Substring(item.LastIndexOf('\\') + 1); if (filter_.IsActive && !filter_.PassFilter(displayName)) { continue; } ImGuiCli.PushID(i); ImGuiCli.BeginGroup(); Texture2D thumbnail = thumbCache_.GetOrCreateThumbnail(item); if (thumbnail != null) { ImGuiCli.ImageButton(thumbnail, new Vector2(itemSize - 20, itemSize - 16)); } else { ImGuiCli.Button("???", new Vector2(itemSize - 20, itemSize - 16)); } if (!ImGuiCli.IsPopupOpen() && ImGuiCli.BeginDragDropSource()) { if (Recents.Contains(CurrentDirectory)) { Recents.Remove(CurrentDirectory); } Recents.Insert(0, CurrentDirectory); ImGuiCli.SetDragDropPayload("U_ASSET", item); if (thumbnail != null) { ImGuiCli.Image(thumbnail, new Vector2(128, 128)); } ImGuiCli.Text(displayName); ImGuiCli.EndDragDropSource(); } if (ImGuiCli.IsItemDoubleClicked(0)) { System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(item); if (dirInfo.Exists) { newDirectory_ = dirInfo.FullName; } } else if (ImGuiCli.IsItemClicked(1)) { ImGuiCli.OpenPopup("##asset_browser_popup"); } if (ImGuiCli.BeginPopup("##asset_browser_popup", ImGuiWindowFlags_.None)) { string ext = System.IO.Path.GetExtension(item); if (ImGuiCli.MenuItem("Open (system)")) { System.Diagnostics.Process.Start(item); } //TODO: custom handlers ImGuiCli.EndPopup(); } if (asDetail_) { ImGuiCli.SameLine(); } ImGuiCli.TextWrapped(displayName); if (!asDetail_ && ImGuiCli.IsItemHovered()) { ImGuiCli.SetTooltip(item); } ImGuiCli.EndGroup(); ImGuiCli.PopID(); ImGuiCli.NextColumn(); } ImGuiCli.EndChild(); }
public void Draw() { if (Objects == null || Objects.Count == 0) { ImGuiCli.Text("< no objects selected >"); return; } if (objectsDirty_) { infos = null; tables = new List <ReflectionCache.CachedPropertyInfo> [Objects.Count]; for (int i = 0; i < Objects.Count; ++i) { if (infos == null) { tables[i] = reflectCache_.GetAlphabetical(Objects[i].GetType()); if (!IsAdvanced) { tables[i] = tables[i].Where(p => p.IsAdvanced == false).ToList(); } infos = tables[i].Select(s => s.DisplayName).ToList(); } else { tables[i] = reflectCache_.GetAlphabetical(Objects[i].GetType()); if (!IsAdvanced) { tables[i] = tables[i].Where(p => p.IsAdvanced == false).ToList(); } infos = infos.Intersect(tables[i].Select(s => s.DisplayName).ToList()).ToList(); } } } if (infos.Count == 0) { ImGuiCli.Text("< no common fields to edit >"); return; } ImGuiCli.PushItemWidth(-1); bool useColumns = infos.Count > 1; if (useColumns) { ImGuiCli.Columns(infos.Count); } for (int i = 0; i < infos.Count; ++i) { ImGuiCli.Text(infos[i]); float w = ImGuiCli.CalcTextSize(infos[i]).X; if (useColumns && ImGuiCli.GetColumnWidth(i) < (w + 10) && ImGuiCli.IsItemHovered()) { ImGuiCli.SetTooltip(infos[i]); } if (useColumns) { ImGuiCli.NextColumn(); } } ImGuiCli.Separator(); ImGuiCli.PushStyleVar(ImGuiStyleVar_.ItemSpacing, 0); ImGuiCli.PushStyleVar(ImGuiStyleVar_.FramePadding, 0); for (int o = 0; o < Objects.Count; ++o) { for (int i = 0; i < infos.Count; ++i) { var cacheInfo = tables[o].FirstOrDefault(c => c.DisplayName == infos[i]); ImGuiCli.PushID(o * infos.Count + infos[i]); ImGuiCli.PushItemWidth(-1); DrawField(cacheInfo, Objects[o], false); ImGuiCli.PopItemWidth(); ImGuiCli.PopID(); if (useColumns) { ImGuiCli.NextColumn(); } } ImGuiCli.Separator(); } ImGuiCli.PopStyleVar(2); ImGuiCli.PopItemWidth(); }
/// Draws a field from cache info. protected void DrawField(ReflectionCache.CachedPropertyInfo info, object target, bool withLabel) { if (filter_.IsActive && !filter_.PassFilter(info.DisplayName)) { return; } Type pType = info.Type; if (pType != typeof(bool) && withLabel) { ImGuiCli.Text(info.DisplayName); if (!string.IsNullOrWhiteSpace(info.Tip))// && ImGuiCli.IsItemHovered()) { ImGuiCli.SameLine(); ImGuiCli.Text(ICON_FA.INFO_CIRCLE); if (ImGuiCli.IsItemHovered()) { ImGuiCli.SetTooltip(info.Tip); } } } string labelLessName = "##" + info.DisplayName; if (pType == typeof(bool)) { bool value = (bool)info.GetValue(target); string lbl = withLabel ? info.DisplayName : "##" + info.DisplayName; if (ImGuiCli.Checkbox(lbl, ref value)) { info.SetValue(target, value); } if (!string.IsNullOrWhiteSpace(info.Tip) && ImGuiCli.IsItemHovered()) { ImGuiCli.SetTooltip(info.Tip); } } else if (pType == typeof(int)) { int value = (int)info.GetValue(target); if (ImGuiCli.DragInt(labelLessName, ref value)) { info.SetValue(target, value); } } else if (pType == typeof(uint)) { int value = (int)info.GetValue(target); if (ImGuiCli.DragInt(labelLessName, ref value, 1, 0, int.MaxValue)) { info.SetValue(target, (int)value); } } else if (pType == typeof(float)) { float value = (float)info.GetValue(target); if (ImGuiCli.DragFloat(labelLessName, ref value)) { info.SetValue(target, value); } } else if (pType == typeof(double)) { float value = (float)info.GetValue(target); if (ImGuiCli.DragFloat(labelLessName, ref value)) { info.SetValue(target, (double)value); } } else if (pType == typeof(string)) { string value = (string)info.GetValue(target); if (value == null) { value = ""; } if (ImGuiCli.InputText(labelLessName, ref value)) { info.SetValue(target, value); } } else if (pType == typeof(Color)) { Color value = (Color)info.GetValue(target); if (ImGuiCli.InputColor(labelLessName, ref value)) { info.SetValue(target, value); } } else if (pType == typeof(Vector2)) { Vector2 value = (Vector2)info.GetValue(target); if (ImGuiEx.DragFloatN_Colored(labelLessName, ref value)) { info.SetValue(target, value); } } else if (pType == typeof(Vector3)) { Vector3 value = (Vector3)info.GetValue(target); if (ImGuiEx.DragFloatN_Colored(labelLessName, ref value)) { info.SetValue(target, value); } } else if (pType == typeof(Vector4)) { if (info.EditType == PropertyData.EditorType.Color) { Vector4 value = (Vector4)info.GetValue(target); if (ImGuiCli.InputColor(labelLessName, ref value)) { info.SetValue(target, value); } } else { Vector4 value = (Vector4)info.GetValue(target); if (ImGuiCli.DragFloat4(labelLessName, ref value)) { info.SetValue(target, value); } } } else if (pType == typeof(Matrix)) { if (info.EditType == PropertyData.EditorType.Transform) { Matrix value = (Matrix)info.GetValue(target); if (ImGuiEx.MatrixTransform(ref value, true)) { info.SetValue(target, value); } } else { Matrix value = (Matrix)info.GetValue(target); if (ImGuiEx.DragMatrix(ref value)) { info.SetValue(target, value); } } } else if (pType.IsEnum) { int value = (int)info.GetValue(target); if (ImGuiCli.Combo(labelLessName, ref value, info.enumNames)) { info.SetValue(target, Enum.GetValues(info.Type).GetValue(value)); } } else { PropertyData.ImPropertyHandler foundHandler = null; if (reflectCache_.TypeHandlers.TryGetValue(pType, out foundHandler)) { foundHandler.EmitUI(info, target); } } }
/// For use when in a custom window, draws for the given target. public void Draw(object target) { if (target == null) { ImGuiCli.Text("< nothing to edit >"); return; } // Check if there's a "complete" handler for the object PropertyData.ImPropertyObjectPage page = null; if (reflectCache_.DefinedPages.TryGetValue(target.GetType(), out page)) { page.EmitEditPage(target); return; } if (IsAlphabetical) { List <ReflectionCache.CachedPropertyInfo> properties = reflectCache_.GetAlphabetical(target.GetType()); if (!IsAdvanced) { properties = properties.Where(p => p.IsAdvanced == false).ToList(); } ImGuiCli.PushItemWidth(-1); for (int p = 0; p < properties.Count; ++p) { ImGuiCli.PushID(p + 1); DrawField(properties[p], target, true); ImGuiCli.PopID(); } ImGuiCli.PopItemWidth(); } else { List <ReflectionCache.PropertyGrouping> groups = reflectCache_.GetGrouped(target.GetType()); ImGuiCli.PushItemWidth(-1); for (int i = 0; i < groups.Count; ++i) { var props = groups[i].Properties; if (!IsAdvanced) { props = props.Where(p => p.IsAdvanced == false).ToList(); } if (props.Count == 0) { continue; } if (ImGuiCli.CollapsingHeader(groups[i].GroupName)) { ImGuiCli.Indent(); for (int p = 0; p < props.Count; ++p) { ImGuiCli.PushID(p + 1); DrawField(props[p], target, true); ImGuiCli.PopID(); } ImGuiCli.Unindent(); } } ImGuiCli.PopItemWidth(); } }