Exemple #1
0
        /// Outputs part of the code generation.
        void WriteFieldCode(StringBuilder sb, ReflectionCache.CachedPropertyInfo info, int idx)
        {
            sb.AppendFormat("                ImGuiCli.Text(\"{0}\");\r\n", info.DisplayName);
            if (string.IsNullOrWhiteSpace(info.Tip))
            {
                sb.AppendFormat("                if (ImGuiCli.IsItemHovered()) ImGuiCli.SetTooltip(\"{0}\");\r\n", info.Tip);
            }

            sb.AppendFormat("                ImGuiCli.PushID({0}+1);\r\n", idx);

            Type pType = info.Property.PropertyType;

            if (pType == typeof(bool))
            {
                sb.AppendFormat("                bool b{0} = obj.{1};\r\n", idx, info.AccessName);
                sb.AppendFormat("                if (ImGuiCli.Checkbox(\"{1}\", ref b{0})) obj.{2} = b{0};\r\n", info.DisplayName, idx, info.AccessName);
                if (!string.IsNullOrEmpty(info.Tip))
                {
                    sb.AppendFormat("                if (ImGuiCli.IsItemHovered()) ImGuiCli.SetTooltip(\"{0}\");\r\n", info.Tip);
                }
            }
            else if (pType == typeof(int))
            {
                sb.AppendFormat("                int b{0} = obj.{1};\r\n", idx, info.AccessName);
                sb.AppendFormat("                if (ImGuiCli.DragInt(\"##{1}\", ref b{0})) obj.{2} = b{0};\r\n", info.DisplayName, idx, info.AccessName);
            }
            else if (pType == typeof(float))
            {
                sb.AppendFormat("                float b{0} = obj.{1};\r\n", idx, info.AccessName);
                sb.AppendFormat("                if (ImGuiCli.DragFloat(\"##{1}\", ref b{0})) obj.{2} = b{0};\r\n", info.DisplayName, idx, info.AccessName);
            }
            else if (pType == typeof(string))
            {
                sb.AppendFormat("                string b{0} = obj.{1};\r\n", idx, info.AccessName);
                sb.AppendFormat("                if (b{0} == null) b{0} = \"\";\r\n", idx);
                sb.AppendFormat("                if (ImGuiCli.InputText(\"##{1}\", ref b{0})) obj.{2} = b{0};\r\n", info.DisplayName, idx, info.AccessName);
            }
            else if (pType == typeof(Vector2))
            {
                sb.AppendFormat("                Vector2 b{0} = obj.{1};\r\n", idx, info.AccessName);
                sb.AppendFormat("                if (ImGuiCli.DragFloat2(\"##{1}\", ref b{0})) obj.{2} = b{0};\r\n", info.DisplayName, idx, info.AccessName);
            }
            else if (pType == typeof(Vector3))
            {
                sb.AppendFormat("                Vector3 b{0} = obj.{1};\r\n", idx, info.AccessName);
                sb.AppendFormat("                if (ImGuiCli.DragFloat3(\"##{1}\", ref b{0})) obj.{2} = b{0};\r\n", info.DisplayName, idx, info.AccessName);
            }
            else if (pType == typeof(Vector4))
            {
                sb.AppendFormat("                Vector4 b{0} = obj.{1};\r\n", idx, info.AccessName);
                sb.AppendFormat("                if (ImGuiCli.DragFloat4(\"##{1}\", ref b{0})) obj.{2} = b{0};\r\n", info.DisplayName, idx, info.AccessName);
            }
            else if (pType == typeof(Color))
            {
                sb.AppendFormat("                Color b{0} = obj.{1};\r\n", idx, info.AccessName);
                sb.AppendFormat("                if (ImGuiCli.InputColor(\"##{1}\", ref b{0})) obj.{2} = b{0};\r\n", info.DisplayName, idx, info.AccessName);
            }
            else if (pType == typeof(Matrix))
            {
                sb.AppendFormat("                Matrix b{0} = obj.{1};\r\n", idx, info.AccessName);
                sb.AppendFormat("                if (ImGuiEx.DragMatrix(ref b{0})) obj.{2} = b{0};\r\n", info.DisplayName, idx, info.AccessName);
            }

            sb.AppendLine("                ImGuiCli.PopID();");
        }
Exemple #2
0
        /// 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);
                }
            }
        }