private void ChangeTool(Type type, Property property) { ImGui.OpenPopup("Tool Picker"); if (ImGui.BeginPopup("Tool Picker")) { var allTools = this.ToolSelector.GetAllTools(type); var bestTool = this.ToolSelector.GetBestTool(type, this.changingState); var index = Array.IndexOf(allTools.Tools, bestTool); if (ImGui.Combo("Tools", ref index, allTools.Names, allTools.Names.Length)) { this.changingState.Name = allTools.Tools[index].Name; } ImGui.Separator(); this.changingState = bestTool.Configure(this.changingState); ImGui.Separator(); if (ImGui.Button("Save")) { this.LinkedTools.Link(property, this.changingState); this.Deactivate(); } ImGui.SameLine(); if (ImGui.Button("Cancel")) { this.Deactivate(); } ImGui.EndPopup(); } }
private void ToolRow(Property property, ToolState state, ITool tool, Type type) { if (ToolUtils.ButtonRowWithTooltip($"Tool: {tool.Name}", $"Type: {type.Name}, Path: {property.Path}", "change tool")) { this.Activate(property); this.changingState = state; } }
public bool Details(ref object value, ToolState tool, Property propertyPath) { var specific = (T)value; var changed = this.Details(ref specific, tool); value = specific !; return(changed); }
public bool HeaderValue(ref object value, ToolState tool) { var specific = (T)value; var changed = this.HeaderValue(ref specific, tool); value = specific !; return(changed); }
public virtual ToolState Configure(ToolState tool) => tool;
public virtual bool Details(ref T value, ToolState tool) => false;
public abstract bool HeaderValue(ref T value, ToolState tool);
public ITool GetBestTool(Type type, ToolState toolState) { var tools = this.GetAllTools(type); return(tools.Tools.FirstOrDefault(t => t.Name == toolState.Name) ?? tools.Tools[0]); }
private static bool Header(ref object value, out bool open, Property property, ITool tool, ToolState toolState) { ImGui.AlignTextToFramePadding(); open = ImGui.TreeNode(property.Name); ImGui.NextColumn(); ImGui.AlignTextToFramePadding(); var changed = false; if (value == null) { ImGui.Text("null"); } else { changed = tool.HeaderValue(ref value, toolState); } ImGui.NextColumn(); return(changed); }
private void Link(string sortKey, ToolState tool) { this.KnownTools.Add(sortKey); this.Tools[sortKey] = tool; }
public void Link(Property property, ToolState tool) => this.Link(property.SortKey, tool);
private record ToolPair(string Key, ToolState Value);