Exemplo n.º 1
0
    private void ShowTestWindow(ref bool open)
    {
        WindowFlags window_flags = WindowFlags.None;

        if (no_titlebar)
        {
            window_flags |= WindowFlags.NoTitleBar;
        }
        if (no_resize)
        {
            window_flags |= WindowFlags.NoResize;
        }
        if (no_move)
        {
            window_flags |= WindowFlags.NoMove;
        }
        if (no_scrollbar)
        {
            window_flags |= WindowFlags.NoScrollbar;
        }
        if (no_collapse)
        {
            window_flags |= WindowFlags.NoCollapse;
        }

        if (!GUI.Begin("ImGui Demo", ref open, (650, 20), (550, 680), bg_alpha, window_flags))
        {
            // Early out if the window is collapsed, as an optimization.
            GUI.End();
            return;
        }
        GUILayout.Label("ImGui says hello.");
        GUILayout.Space("Space~1", 5);
        if (GUILayout.CollapsingHeader("Help", ref helpOn))
        {
            ShowUserGuide();
        }

        if (GUILayout.CollapsingHeader("Window options", ref windowsOptionsOn))
        {
            GUILayout.PushID("_WindowOptions");
            no_titlebar  = GUILayout.Toggle("no titlebar", no_titlebar);
            no_border    = GUILayout.Toggle("no border", no_border);
            no_resize    = GUILayout.Toggle("no resize", no_resize);
            no_move      = GUILayout.Toggle("no move", no_move);
            no_scrollbar = GUILayout.Toggle("no scrollbar", no_scrollbar);
            bg_alpha     = GUILayout.Slider("background alpha", bg_alpha, 0.0, 1.0);
            if (GUILayout.TreeNode("Style", ref styleEditorOpen))
            {
                ShowStyleEditor();
                GUILayout.TreePop();
            }
            if (GUILayout.TreeNode("Logging", ref loggingOpen))
            {
                GUILayout.Text("TODO");
                GUILayout.TreePop();
            }
            //TODO logging
            GUILayout.PopID();
        }

        if (GUILayout.CollapsingHeader("Widgets", ref widgetsOn))
        {
            GUILayout.PushID("_Widgets");
            if (GUILayout.TreeNode("Trees", ref open1))
            {
                if (GUILayout.TreeNode("Basic trees", ref open2))
                {
                    for (int i = 0; i < openChild.Length; i++)
                    {
                        if (GUILayout.TreeNode(string.Format("Child {0}", i), ref openChild[i]))
                        {
                            GUILayout.BeginHorizontal("HGroup");
                            GUILayout.Label("blah blah");
                            if (GUILayout.Button("print"))
                            {
                                System.Console.WriteLine(@"Child {0} pressed", i);
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.TreePop();
                        }
                    }
                    GUILayout.TreePop();
                }
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Collapsing Headers", ref open4))
            {
                if (GUILayout.CollapsingHeader("Header", ref open5))
                {
                    closable_group = GUILayout.Toggle("Enable extra group", closable_group);
                    for (int i = 0; i < 5; i++)
                    {
                        GUILayout.Label("Some content {0}", i);
                    }
                }
                if (GUILayout.CollapsingHeader("Header with a close button", ref closable_group))
                {
                    for (int i = 0; i < 5; i++)
                    {
                        GUILayout.Label("More content {0}", i);
                    }
                }
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Bullets", ref open6))
            {
                GUILayout.BulletText("Bullet point 1");
                GUILayout.BulletText("Bullet point 2\nOn multiple lines");
                GUILayout.PushStyle(StylePropertyName.CellSpacingHorizontal, 0);//remove horizontal cell spacing of following groups.
                GUILayout.BeginHorizontal("HGroup~1"); GUILayout.Bullet("_Bullet"); GUILayout.Text("Bullet point 3 (two calls)"); GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal("HGroup~2"); GUILayout.Bullet("_Bullet"); GUILayout.Button("Button"); GUILayout.EndHorizontal();
                GUILayout.PopStyle();
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Colored Text", ref open7))
            {
                // Using shortcut. You can use GUILayout.PushFontColor() for more flexibility.
                GUILayout.Label(new Color(1.0f, 0.0f, 1.0f, 1.0f), "Pink");
                GUILayout.Label(new Color(1.0f, 1.0f, 0.0f, 1.0f), "Yellow");
                GUILayout.LabelDisabled("Disabled");
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Word Wrapping", ref open8))
            {
                //TODO
                GUILayout.Label("TODO");
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Non-ASCII Text", ref open9))
            {
                //TODO wrapped Label
                GUILayout.Label("Hiragana: カククケコ (kakikukeko)");
                GUILayout.Label("Kanjis: 日本語 (nihongo)");
                buf = GUILayout.InputText("Unicode input", buf);
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Images", ref open10))
            {
                GUILayout.Image("images/trees.jpg");
                GUILayout.Text("Some textured buttons:");
                GUILayout.BeginHorizontal("HGroup~1");
                for (int i = 0; i < 8; i++)
                {
                    GUILayout.PushID(i);
                    if (GUILayout.ImageButton("images/trees.jpg", new Size(32, 32),
                                              new Vector(32.0f * i, 0)))
                    {
                        pressed_count += 1;
                    }
                    GUILayout.PopID();
                }
                GUILayout.EndHorizontal();
                GUILayout.Label("Pressed {0} times.", pressed_count);
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Selectables", ref open11))
            {
                if (GUILayout.TreeNode("Basic", ref basicSelectableOpen))
                {
                    selected[0] = GUILayout.Selectable("1. I am selectable", selected[0]);
                    selected[1] = GUILayout.Selectable("2. I am selectable", selected[1]);
                    GUILayout.Text("3. I am not selectable");
                    selected[2] = GUILayout.Selectable("4. I am selectable", selected[2]);
                    GUILayout.TreePop();
                }
                GUILayout.Label("more TODO");
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Filtered Text Input", ref open12))
            {
                defaultText     = GUILayout.InputText("default", defaultText);
                decimalText     = GUILayout.InputText("decimal", decimalText, InputTextFlags.CharsDecimal);
                hexadecimalText = GUILayout.InputText("hexadecimal", hexadecimalText, InputTextFlags.CharsHexadecimal | InputTextFlags.CharsUppercase);
                uppercaseText   = GUILayout.InputText("uppercase", uppercaseText, InputTextFlags.CharsUppercase);
                noBlankText     = GUILayout.InputText("no blank", noBlankText, InputTextFlags.CharsNoBlank);
                customText      = GUILayout.InputText("\"imgui\" letters", customText, 0, (c) => "imguiIMGUI".IndexOf(c) >= 0);
                GUILayout.Text("Password input");
                password = GUILayout.InputText("password", password, InputTextFlags.Password | InputTextFlags.CharsNoBlank);
                password = GUILayout.InputText("password (clear)", password, InputTextFlags.CharsNoBlank);
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Multi-line Text Input", ref open13))
            {
                GUILayout.PushPadding((0, 0, 0, 0));
                read_only = GUILayout.CheckBox("Read-only", read_only);
                GUILayout.PopStyle(4);
                GUILayout.PushStyle(StylePropertyName.HorizontalStretchFactor, 1);
                if (read_only)
                {
                    GUILayout.InputTextMultiline("Text Box", new Size(120, 200), multiLineText);
                }
                else
                {
                    multiLineText = GUILayout.InputTextMultiline("Text Box", new Size(120, 200), multiLineText);
                }
                GUILayout.PopStyle();
                GUILayout.TreePop();
            }

            using (GUILayout.HScope("HGroup~button_show_text"))
            {
                if (GUILayout.Button("Button"))
                {
                    System.Console.WriteLine("Clicked");
                    a ^= true;
                }
                if (a)
                {
                    GUILayout.Label("Thanks for clicking me!");
                }
            }

            check = GUILayout.CheckBox("checkbox", check);

            GUILayout.BeginHorizontal("HGroup~radios");
            {
                GUILayout.RadioButton("Radio 0", ref active_id, 0);
                GUILayout.RadioButton("Radio 1", ref active_id, 1);
                GUILayout.RadioButton("Radio 2", ref active_id, 2);
            }
            GUILayout.EndHorizontal();

            // Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
            GUILayout.BeginHorizontal("HGroup~click buttons");
            {
                for (int i = 0; i < 7; i++)
                {
                    GUILayout.PushID(i);
                    GUILayout.PushStyle(StylePropertyName.BackgroundColor, Color.HSV(i / 7.0f, 0.6f, 0.6f), GUIState.Normal);
                    GUILayout.PushStyle(StylePropertyName.BackgroundColor, Color.HSV(i / 7.0f, 0.7f, 0.7f), GUIState.Hover);
                    GUILayout.PushStyle(StylePropertyName.BackgroundColor, Color.HSV(i / 7.0f, 0.8f, 0.8f), GUIState.Active);
                    GUILayout.Button("Click");
                    GUILayout.PopStyle(3);
                    GUILayout.PopID();
                }
            }
            GUILayout.EndHorizontal();

            //TODO tooltip
            //GUILayout.BeginHorizontal("HGroup~tooltips");
            //GUILayout.Text("Hover over me");
            //if (GUI.IsItemHovered())
            //    GUI.SetTooltip("I am a tooltip");

            //if (GUI.IsItemHovered())
            //{
            //    GUILayout.BeginTooltip();
            //    //...
            //    GUILayout.EndTooltip();
            //}
            //GUILayout.EndHorizontal();

            GUILayout.Separator("Separator~1");

            GUILayout.LabelText("label", "Value");

            //TODO combo

            str0 = GUILayout.InputText("input text", str0);
            i0   = GUILayout.InputInt("input int", i0);
            f0   = GUILayout.InputFloat("input float", f0);
            col1 = GUILayout.ColorField("color 1", col1);//TODO no alpha color field
            col2 = GUILayout.ColorField("color 2", col2);
            currentListBoxItem = GUILayout.ListBox <string>("listbox\n(single select)", listBoxItems, currentListBoxItem);

            if (GUILayout.TreeNode("Sliders", ref open14))
            {
                GUILayout.Label("Horizontal Slider");
                sliderValue = GUILayout.Slider("slider", sliderValue, 0.0, 1.0);
                GUILayout.Label("Vertical Slder");
                vSliderValue = GUILayout.VSlider("vslider", vSliderValue, 0.0, 1.0);
                GUILayout.TreePop();
            }

            GUILayout.PopID();
        }

        if (GUILayout.CollapsingHeader("Graphs widgets", ref graphicsWidgetsOn))
        {
            GUILayout.PushID("_GraphsWidgets");
            animate = GUILayout.CheckBox("Animate", animate);
            GUILayout.PushStyle(StylePropertyName.HorizontalStretchFactor, 1);//+1
            if (animate)
            {
                progress += progress_dir * 0.4f * deltaTime / 1000.0;
                if (progress >= +1.1f)
                {
                    progress = +1.1f; progress_dir *= -1.0f;
                }
                if (progress <= -0.1f)
                {
                    progress = -0.1f; progress_dir *= -1.0f;
                }
            }
            double progress_saturated = (progress < 0.0) ? 0.0 : (progress > 1.0f) ? 1.0 : progress;

            var percentText = string.Format("{0}%", (int)(progress_saturated * 100));
            GUILayout.BeginHorizontal("HGroup~1");
            GUILayout.BeginVertical("ProgressBars");
            GUILayout.ProgressBar("ProgressBar %", progress, (400, 20), percentText);

            const int total        = 1753;
            var       progressText = string.Format("{0}/{1}", (int)(progress_saturated * total), total);
            GUILayout.ProgressBar("ProgressBar /", progress, (400, 20), progressText);
            GUILayout.EndVertical();
            GUILayout.PushFixedWidth(100); //+2
            GUILayout.Text("Progress");
            GUILayout.PopStyle(2);         //-2
            GUILayout.EndHorizontal();

            GUILayout.PopStyle();//-1
            GUILayout.PopID();
        }

        if (GUILayout.CollapsingHeader("Layout", ref layoutOn))
        {
            GUILayout.PushID("_Layout");

            if (GUILayout.TreeNode("Child regions", ref childRegionsOpen))
            {
                GUILayout.Text("Without border");
                bool goto_line = GUILayout.Button("Goto");
                GUILayout.PushFixedWidth(100);//+2
                var newLine = GUILayout.InputInt("##Line", line);
                if (newLine != line)
                {
                    goto_line = true;
                }
                GUILayout.PopStyle(2);//-2

                using (GUILayout.HScope("HGroup~1"))
                {
                    if (GUILayout.BeginChild("Sub1", GUILayout.Height(300).ExpandWidth(true)))
                    {
                        for (int i = 0; i < 50; i++)
                        {
                            GUILayout.Text("{0,4}: scrollable region", i);
                            if (goto_line && line == i)
                            {
                                //SetScrollHere();//TODO
                            }
                        }
                        if (goto_line && line >= 10)
                        {
                            //SetScrollHere();//TODO
                        }
                        GUILayout.EndChild();
                    }

                    if (GUILayout.BeginChild("Sub2", GUILayout.Height(300).ExpandWidth(true)))
                    {
                        GUILayout.Text("With border");
                        for (int i = 0; i < 50; i++)
                        {
                            GUILayout.Button(string.Format("0x{0:X8}", i * 5731));
                        }
                        GUILayout.EndChild();
                    }
                }
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Stack layout", ref stackLayoutOpen))
            {
                GUILayout.Label("Three buttons of default size.");
                GUILayout.BeginHorizontal("H~~~1");
                {
                    GUILayout.Button("1~");
                    GUILayout.Button("2~~");
                    GUILayout.Button("3~~~");
                }
                GUILayout.EndHorizontal();
                GUILayout.Label("Three fixed-width (100 pixels) buttons.");
                GUILayout.BeginHorizontal("H~~~2");
                {
                    GUILayout.PushFixedWidth(100);
                    GUILayout.Button("1");
                    GUILayout.Button("2");
                    GUILayout.Button("3");
                    GUILayout.PopStyle(2);
                }
                GUILayout.EndHorizontal();
                GUILayout.Label("Three stretched sized buttons with 1/2/3 stretch factor.");
                GUILayout.BeginHorizontal("H~~~3");
                {
                    GUILayout.PushStyle(StylePropertyName.HorizontalStretchFactor, 1);
                    GUILayout.Button("1");
                    GUILayout.PopStyle();
                    GUILayout.PushStyle(StylePropertyName.HorizontalStretchFactor, 2);
                    GUILayout.Button("2");
                    GUILayout.PopStyle();
                    GUILayout.PushStyle(StylePropertyName.HorizontalStretchFactor, 3);
                    GUILayout.Button("3");
                    GUILayout.PopStyle();
                }
                GUILayout.EndHorizontal();
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Layout scopes", ref layoutScopesOpen))
            {
                /*
                 * H(V)Scope is a wrapper of BeginHorizontal(Vertical)/EndHorizontal(Vertical) API.
                 * It employs IDisposable so we don't need to call EndHorizontal(Vertical),
                 * because it is called automatically when H(V)Scope goes out of scope.
                 */
                using (GUILayout.HScope("HorizontalScope~", GUILayout.ExpandWidth(false)))
                {
                    GUILayout.Button("H1");
                    using (GUILayout.VScope("VerticalScope~", GUILayout.ExpandWidth(false)))
                    {
                        GUILayout.Button("V1");
                        GUILayout.Button("V2");
                    }
                    GUILayout.Button("H2");
                    GUILayout.Button("H3");
                }
                GUILayout.TreePop();
            }

            GUILayout.PopID();
        }

        if (GUILayout.CollapsingHeader("Style & Skin", ref skinOn))
        {
            GUILayout.PushID("_Skin");

            GUILayout.Button("MyButton1", this.smallRed);
            GUILayout.Button("MyButton2", new LayoutOptions().FontColor(Color.Blue).FontSize(40));

            GUILayout.PushBorder((10, 20, 30, 40));
            GUILayout.PushPadding((40, 30, 20, 10));
            GUILayout.PushStyle(StylePropertyName.BorderTopColor, Color.Red);
            GUILayout.PushStyle(StylePropertyName.BorderRightColor, Color.Green);
            GUILayout.PushStyle(StylePropertyName.BorderBottomColor, Color.Blue);
            GUILayout.PushStyle(StylePropertyName.BorderLeftColor, Color.Yellow);
            GUILayout.Button("Box Model", GUILayout.Width(161).Height(100));
            GUILayout.PopStyle(4 + 4 + 4);

            if (GUILayout.TreeNode("Default", ref defaultSkinOpen))
            {
                using (GUILayout.HScope("HorizontalScope~", GUILayout.ExpandWidth(false)))
                {
                    GUILayout.Button("Button 1");
                    GUILayout.Button("Button 2");
                    GUILayout.Button("Button 3");
                }
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("dear imgui", ref dearImGuiSkinOpen))
            {
                GUI.SetSkin(dearImGuiSkinRules);
                using (GUILayout.HScope("HorizontalScope~", GUILayout.ExpandWidth(false)))
                {
                    GUILayout.Button("Button 1");
                    GUILayout.Button("Button 2");
                    GUILayout.Button("Button 3");
                }
                GUILayout.TreePop();
            }

            GUI.SetDefaultSkin();

            if (GUILayout.TreeNode("Windows 10", ref win10SkinOpen))
            {
                GUI.SetSkin(win10SkinRules);
                using (GUILayout.HScope("HorizontalScope~", GUILayout.ExpandWidth(false)))
                {
                    GUILayout.Button("Button 1");
                    GUILayout.Button("Button 2");
                    GUILayout.Button("Button 3");
                }
                GUILayout.TreePop();
            }

            GUI.SetDefaultSkin();

            GUILayout.PopID();
        }

        if (GUILayout.CollapsingHeader("Header", ref headerOn))
        {
            GUILayout.Button("Button A");
            GUILayout.Button("Button B");
            GUILayout.Button("Button C");
        }
        GUI.End();
    }