<commit_before>﻿using System;
using OpenGL;

namespace Example10
{
    static class Program
    {
        private static Texture scrollTexture;

        static void Main()
        {
            Window.CreateWindow("OpenGL UI: Example 10", 1280, 720);

            // add a reshape callback to update the UI
            Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height));

            // add a close callback to make sure we dispose of everything properly
            Window.OnCloseCallbacks.Add(OnClose);

            // enable depth testing to ensure correct z-ordering of our fragments
            Gl.Enable(EnableCap.DepthTest);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            // initialize the user interface
            OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height);

            // create the left and right containers
            OpenGL.UI.UIContainer leftContainer = new OpenGL.UI.UIContainer(new OpenGL.UI.Point(Window.Width / 2, Window.Height), "LeftContainer");
            OpenGL.UI.UIContainer rightContainer = new OpenGL.UI.UIContainer(new OpenGL.UI.Point(Window.Width / 2, Window.Height), "RightContainer");

            leftContainer.RelativeTo = OpenGL.UI.Corner.BottomLeft;
            rightContainer.RelativeTo = OpenGL.UI.Corner.BottomRight;

            // add the containers to the user interface
            OpenGL.UI.UserInterface.AddElement(leftContainer);
            OpenGL.UI.UserInterface.AddElement(rightContainer);

            // add some cool stuff to the containers
            scrollTexture = new Texture("data/scrollTexture.png");

            // create a textbox with word wrapping for the left container
            OpenGL.UI.Controls.TextBox textBox = new OpenGL.UI.Controls.TextBox(OpenGL.UI.Controls.BMFont.LoadFont("fonts/font16.fnt"), scrollTexture);
            textBox.Write("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eget vehicula orci. Nulla nibh nulla, suscipit non neque sed, placerat efficitur velit. Sed convallis gravida tincidunt. Praesent vehicula nibh leo, at consequat nisi condimentum ullamcorper. Vivamus pulvinar accumsan maximus. Integer luctus elit porttitor nisi sollicitudin, eget porttitor odio tincidunt. Sed elit justo, suscipit non dui ut, eleifend euismod nibh. Nullam ac fermentum nisl. In convallis id leo sit amet eleifend. Suspendisse eu ligula pulvinar ex facilisis cursus ac ac velit. In ut turpis nec neque vehicula eleifend. Morbi in tempus est. Vivamus nisi nunc, pharetra quis scelerisque ut, tempor id dui.");
            textBox.RelativeTo = OpenGL.UI.Corner.Fill;
            textBox.Padding = new OpenGL.UI.Point(6, 0);
            leftContainer.AddElement(textBox);
            textBox.OnResize();

            // build 10 buttons for the right container
            for (int i = 0; i < 10; i++)
            {
                OpenGL.UI.Controls.Button button = new OpenGL.UI.Controls.Button(200, 30);
                button.Font = OpenGL.UI.Controls.BMFont.LoadFont("fonts/font16.fnt");
                button.Text = string.Format("Button {0}", i);
                button.RelativeTo = OpenGL.UI.Corner.Center;
                button.Position = new OpenGL.UI.Point(0, 200 - i * 40);
                rightContainer.AddElement(button);
                button.OnResize();

                button.OnMouseEnter = (sender, e) => button.BackgroundColor = new Vector4(0.5f, 0.5f, 1.0f, 1.0f);
                button.OnMouseLeave = (sender, e) => button.BackgroundColor = new Vector4(0.3f, 0.3f, 0.3f, 1.0f);
            }

            // add a control to resize the left/right containers
            OpenGL.UI.Controls.Button divider = new OpenGL.UI.Controls.Button(8, Window.Height);
            divider.BackgroundColor = new Vector4(0.3f, 0.3f, 0.3f, 0.5f);
            divider.RelativeTo = OpenGL.UI.Corner.BottomLeft;
            divider.Position = new OpenGL.UI.Point(Window.Width / 2 - divider.Size.x / 2, 0);

            bool onMouseDown = false;

            // handle mouse events on the divider
            divider.OnMouseDown = (sender, e) => onMouseDown = true;
            divider.OnMouseUp = (sender, e) => onMouseDown = false;
            divider.OnMouseMove = (sender, e) =>
                {
                    if (onMouseDown)
                    {
                        int x = divider.Position.x + (e.Location.x - e.LastLocaton.x);
                        x = Math.Min(Window.Width - 110, x);

                        // set the position of the divider
                        divider.Position = new OpenGL.UI.Point(x, divider.Position.y);

                        // update the container sizes
                        x += divider.Size.x / 2;
                        leftContainer.Size = new OpenGL.UI.Point(x, Window.Height);
                        rightContainer.Size = new OpenGL.UI.Point(Window.Width - x, Window.Height);

                        // resize the buttons to make them fit in the right container
                        foreach (var button in rightContainer.Elements)
                            button.Size = new OpenGL.UI.Point(Math.Min(200, rightContainer.Size.x - 16), 30);

                        OpenGL.UI.UserInterface.UIWindow.OnResize();
                    }
                };

            // add the divider to the user interface
            OpenGL.UI.UserInterface.AddElement(divider);

            // subscribe the escape event using the OpenGL.UI class library
            OpenGL.UI.Input.Subscribe((char)27, Window.OnClose);

            while (true)
            {
                Window.HandleEvents();
                OnRenderFrame();
            }
        }

        private static void OnClose()
        {
            // make sure to dispose of everything
            OpenGL.UI.UserInterface.Dispose();
            OpenGL.UI.Controls.BMFont.Dispose();
            scrollTexture.Dispose();
        }

        private static void OnRenderFrame()
        {
            // set up the OpenGL viewport and clear both the color and depth bits
            Gl.Viewport(0, 0, Window.Width, Window.Height);
            Gl.ClearColor(0.2f, 0.2f, 0.2f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // draw the user interface after everything else
            OpenGL.UI.UserInterface.Draw();

            // finally, swap the back buffer to the front so that the screen displays
            Window.SwapBuffers();
        }
    }
}<commit_msg>Make sure to layout the controls after a window resize in Example 10.<commit_after>﻿using System;
using OpenGL;

namespace Example10
{
    static class Program
    {
        private static Texture scrollTexture;
        private static OpenGL.UI.Controls.Button divider;
        private static OpenGL.UI.UIContainer leftContainer, rightContainer;

        static void Main()
        {
            Window.CreateWindow("OpenGL UI: Example 10", 1280, 720);

            // add a reshape callback to update the UI
            Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height));

            // add a close callback to make sure we dispose of everything properly
            Window.OnCloseCallbacks.Add(OnClose);

            // enable depth testing to ensure correct z-ordering of our fragments
            Gl.Enable(EnableCap.DepthTest);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            // initialize the user interface
            OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height);

            // create the left and right containers
            leftContainer = new OpenGL.UI.UIContainer(new OpenGL.UI.Point(Window.Width / 2, Window.Height), "LeftContainer");
            rightContainer = new OpenGL.UI.UIContainer(new OpenGL.UI.Point(Window.Width / 2, Window.Height), "RightContainer");

            leftContainer.RelativeTo = OpenGL.UI.Corner.BottomLeft;
            rightContainer.RelativeTo = OpenGL.UI.Corner.BottomRight;

            // add the containers to the user interface
            OpenGL.UI.UserInterface.AddElement(leftContainer);
            OpenGL.UI.UserInterface.AddElement(rightContainer);

            // add some cool stuff to the containers
            scrollTexture = new Texture("data/scrollTexture.png");

            // create a textbox with word wrapping for the left container
            OpenGL.UI.Controls.TextBox textBox = new OpenGL.UI.Controls.TextBox(OpenGL.UI.Controls.BMFont.LoadFont("fonts/font16.fnt"), scrollTexture);
            textBox.Write("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eget vehicula orci. Nulla nibh nulla, suscipit non neque sed, placerat efficitur velit. Sed convallis gravida tincidunt. Praesent vehicula nibh leo, at consequat nisi condimentum ullamcorper. Vivamus pulvinar accumsan maximus. Integer luctus elit porttitor nisi sollicitudin, eget porttitor odio tincidunt. Sed elit justo, suscipit non dui ut, eleifend euismod nibh. Nullam ac fermentum nisl. In convallis id leo sit amet eleifend. Suspendisse eu ligula pulvinar ex facilisis cursus ac ac velit. In ut turpis nec neque vehicula eleifend. Morbi in tempus est. Vivamus nisi nunc, pharetra quis scelerisque ut, tempor id dui.");
            textBox.RelativeTo = OpenGL.UI.Corner.Fill;
            textBox.Padding = new OpenGL.UI.Point(6, 0);
            leftContainer.AddElement(textBox);
            textBox.OnResize();

            // build 10 buttons for the right container
            for (int i = 0; i < 10; i++)
            {
                OpenGL.UI.Controls.Button button = new OpenGL.UI.Controls.Button(200, 30);
                button.Font = OpenGL.UI.Controls.BMFont.LoadFont("fonts/font16.fnt");
                button.Text = string.Format("Button {0}", i);
                button.RelativeTo = OpenGL.UI.Corner.Center;
                button.Position = new OpenGL.UI.Point(0, 200 - i * 40);
                rightContainer.AddElement(button);
                button.OnResize();

                button.OnMouseEnter = (sender, e) => button.BackgroundColor = new Vector4(0.5f, 0.5f, 1.0f, 1.0f);
                button.OnMouseLeave = (sender, e) => button.BackgroundColor = new Vector4(0.3f, 0.3f, 0.3f, 1.0f);
            }

            // add a control to resize the left/right containers
            divider = new OpenGL.UI.Controls.Button(8, Window.Height);
            divider.BackgroundColor = new Vector4(0.3f, 0.3f, 0.3f, 0.5f);
            divider.RelativeTo = OpenGL.UI.Corner.BottomLeft;
            divider.Position = new OpenGL.UI.Point(Window.Width / 2 - divider.Size.x / 2, 0);

            bool onMouseDown = false;

            // handle mouse events on the divider
            divider.OnMouseDown = (sender, e) => onMouseDown = true;
            divider.OnMouseUp = (sender, e) => onMouseDown = false;
            divider.OnMouseMove = (sender, e) =>
            {
                if (onMouseDown) ResizeControls(e.Location.x - e.LastLocaton.x);
            };

            // make sure to layout the controls if the window is resized
            Window.OnReshapeCallbacks.Add(() => ResizeControls(0));

            // add the divider to the user interface
            OpenGL.UI.UserInterface.AddElement(divider);

            // subscribe the escape event using the OpenGL.UI class library
            OpenGL.UI.Input.Subscribe((char)27, Window.OnClose);

            while (true)
            {
                Window.HandleEvents();
                OnRenderFrame();
            }
        }

        private static void ResizeControls(int dx)
        {
            int x = divider.Position.x + dx;// (e.Location.x - e.LastLocaton.x);
            x = Math.Min(Window.Width - 110, x);

            // set the position of the divider
            divider.Position = new OpenGL.UI.Point(x, divider.Position.y);

            // update the container sizes
            x += divider.Size.x / 2;
            leftContainer.Size = new OpenGL.UI.Point(x, Window.Height);
            rightContainer.Size = new OpenGL.UI.Point(Window.Width - x, Window.Height);

            // resize the buttons to make them fit in the right container
            foreach (var button in rightContainer.Elements)
                button.Size = new OpenGL.UI.Point(Math.Min(200, rightContainer.Size.x - 16), 30);

            OpenGL.UI.UserInterface.UIWindow.OnResize();
        }

        private static void OnClose()
        {
            // make sure to dispose of everything
            OpenGL.UI.UserInterface.Dispose();
            OpenGL.UI.Controls.BMFont.Dispose();
            scrollTexture.Dispose();
        }

        private static void OnRenderFrame()
        {
            // set up the OpenGL viewport and clear both the color and depth bits
            Gl.Viewport(0, 0, Window.Width, Window.Height);
            Gl.ClearColor(0.2f, 0.2f, 0.2f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // draw the user interface after everything else
            OpenGL.UI.UserInterface.Draw();

            // finally, swap the back buffer to the front so that the screen displays
            Window.SwapBuffers();
        }
    }
}
{'fraction_non_alphanumeric': 0.09339339339339339, 'fraction_numerical': 0.013738738738738739, 'mean_word_length': 2.021320027217056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6692227', 'n_tokens_mistral': 3879, 'n_tokens_neox': 3645, 'n_words': 1003}