GUIForms Library

Hi,

In my learning of Unity and I have reached the moment I need to use the GUI, but unfortunately is a bit archaic to use, so I decided to write a library that allows me to use the Unity GUI of a simpler way, with a structure see in WinForms from the .Net Framework, has preliminary name of GUIForms, is developed in C # because that is what I know.

I have decided to release it to the community with a open source MIT license , so they can use for any project. What I am asking you is to place a reference of the author (me).

This library is incomplete and there are many things to develop, so if there are interested can tell me or just send me by this forum the bugs and improvements and additions have been implemented.

That is developed:

  • Modal and Modeless Forms
  • Form window and without window
  • Events (mouse over, mouse out, click, change value)
  • Basic controls (missing a couple of controls to be implemented soon)
  • Works with GUISkins, but is supposed to work with GUIStyles but I have not tried

What I see is pending is:

  • Complete the messagebox form
  • Clean the code
  • Implement som alignment (top, middle, bottom, right, left, center, etc.), fonts
  • Find and eliminate bugs
  • Implement more complex controls: ListBox, DropDownBox, ImageList, MenuBar, and so on.
  • Document and make some tutorials
  • In the latter case if necessary to improve the architecture

I leave the entire project to test and revise it a bit, contains a test scene and all the source code

Cheers!
Marcelo Roca


Hola a todos,

En mi aprendizaje de Unity he llegado al momento que necesito utilizar el GUI, pero lamentablemente es un poco arcaico de utilizar, por lo que decidí escribir una librería que me permita utilizar el GUI de Unity de una manera más sencilla, tratándola de estructurar de una manera perecida a lo que es WinForms de Net Framework, como nombre preliminar tiene GUIForms, está desarrollado en C# ya que es lo que conozco.

Debido a que me parece que es algo que se necesita bastante he decidido liberarla con código abierto para la comunidad, por lo que pueden utilizar para cualquier tipo de proyecto. Lo que les pido que es que coloquen una referencia a la librería y el autor.

Esta librería está bastante incompleta y hay muchas cosas que hay que desarrollar, para lo cual si hay interesados me pueden avisar o simplemente mandarme por este foro los bugs o mejoras y adiciones que hayan implementado.

Que está desarrollado:

  • Formularios Modal y Modeless
  • Formulario en ventana y sin ventana
  • Eventos (mouse over, mouse out, click, change value)
  • Controles básicos del GUI (faltan un par de controles que los implementare pronto)
  • Funciona basado en GUISkins, se supone que funciona con GUIStyles pero no lo he probado

Lo que veo que está pendiente es:

  • Completar el formulario de messagebox
  • Limpiar el código
  • Implementar dentro de los controles
  • alineamiento(top, middle, bottom, right, left, center, etc.)
  • uso de fonts
  • Buscar y eliminar bugs
  • Implementar controles más complejos: ListBox, DropDownBox, ImageList, MenuBar, etc.
  • Documentar y hacer algunos tutoriales
  • En último caso si es necesario mejorar la arquitectura

Les dejo el proyecto completo para que lo prueben y revisen un poco, contiene una escena de prueba y todo el código fuente

Saludos

Marcelo Roca

208677–7679–$testguiforms_203.rar (1.24 MB)

For use the library you need:

1.- copy the folder GUIForms to your project.
2.- Create a script with the definition of the form

example:

TestControlsForm.cs

using System;
using UnityEngine;
using GUIForms;

public partial class TestControlsForm : Form
{
    // define the controls of the form
    private Button ButtonClose;
    private Button ButtonShowMessage;
    private Label LabelTooltip;

    private Box Box1;
    private Button Button1;
    private Label Label1;
    private TextArea TextArea1;
    private TextField TextField1;
    private PasswordField PasswordField1;
    private Toggle Toggle1;
    private VerticalSlider VerticalSlider1;
    private HorizontalSlider HorizontalSlider1;
    
    // initialize the form
    public override void Initialize()
    {
        // set form variables
        // the title
        Text = "Test Controls";
        // if is or not draggable
        Draggable = true;
        // if use window or not
        WindowMode = WindowModes.Window;
        // the size
        Size = new Size(500, 400);
        // location of the form 
        Location = FormsUtility.CenterScreen(this);

        // create the first control a label to show tooltips and messages
        LabelTooltip = (Label)AddControl(new Label());
        // the size
        LabelTooltip.Size = new Size(400, 20);
        // the location
        LabelTooltip.Location = new Point(5, 5);

        // create an button control
        ButtonClose = (Button)AddControl(new Button());
        // the caption
        ButtonClose.Text = "Close";
        // the tooltip message
        ButtonClose.ToolTip = "Press here to close this window";
        ButtonClose.Size = new Size(100, 20);
        ButtonClose.Location = 
            FormsUtility.AlignControl 
            (
            Point.Empty, ButtonClose.Size, ViewSize, 
            HorizontalAlignment.Left, VerticalAlignment.Botton, 
            5, 5, 5, 5
            );
        // assign event handlers 
        ButtonClose.ButtonClick += ButtonClose_OnClick;
        ButtonClose.MouseOver += Control_MouseOver;
        ButtonClose.MouseOut += Control_MouseOut;

        // the others controls are in the same maner

        ButtonShowMessage = (Button)AddControl(new Button());
        ButtonShowMessage.Text = "Show Message";
        ButtonShowMessage.ToolTip = "Press here to test MessageBox";
        ButtonShowMessage.Size = new Size(100, 20);
        ButtonShowMessage.Location = 
            FormsUtility.AlignControl
            (
            Point.Empty, ButtonClose.Size, ViewSize,
            HorizontalAlignment.Left, VerticalAlignment.Botton,
            5, 5, 5, 40
            );
        ButtonShowMessage.ButtonClick += ButtonShowMessage_OnClick;
        ButtonShowMessage.MouseOver += Control_MouseOver;
        ButtonShowMessage.MouseOut += Control_MouseOut;

        Box1 = (Box)AddControl(new Box());
        Box1.Text = "Box";
        Box1.ToolTip = "Box";
        Box1.Size = new Size(70, 50);
        Box1.Location = new Point(5, 30);
        Box1.MouseOver += Control_MouseOver;
        Box1.MouseOut += Control_MouseOut;

        Button1 = (Button)AddControl(new Button());
        Button1.Text = "Button";
        Button1.ToolTip = "Button";
        Button1.Size = new Size(70, 20);
        Button1.Location = new Point(80, 30);
        Button1.MouseOver += Control_MouseOver;
        Button1.MouseOut += Control_MouseOut;

        Label1 = (Label)AddControl(new Label());
        Label1.Text = "Label";
        Label1.ToolTip = "Label";
        Label1.Size = new Size(70, 20);
        Label1.Location = new Point(80, 60);
        Label1.MouseOver += Control_MouseOver;
        Label1.MouseOut += Control_MouseOut;

        TextArea1 = (TextArea)AddControl(new TextArea());
        TextArea1.Text = "TextArea";
        TextArea1.ToolTip = "TextArea";
        TextArea1.Size = new Size(100, 50);
        TextArea1.Location = new Point(150, 30);
        TextArea1.MouseOver += Control_MouseOver;
        TextArea1.MouseOut += Control_MouseOut;

        TextField1 = (TextField)AddControl(new TextField());
        TextField1.Text = "TextField";
        TextField1.ToolTip = "TextField";
        TextField1.Size = new Size(100, 20);
        TextField1.Location = new Point(255, 30);
        TextField1.MouseOver += Control_MouseOver;
        TextField1.MouseOut += Control_MouseOut;

        PasswordField1 = (PasswordField) AddControl(new PasswordField());
        PasswordField1.ToolTip = "PasswordField";
        PasswordField1.Size = new Size(100, 20);
        PasswordField1.Location = new Point(255, 60);
        PasswordField1.MouseOver += Control_MouseOver;
        PasswordField1.MouseOut += Control_MouseOut;

        Toggle1 = (Toggle) AddControl (new Toggle());
        Toggle1.Text = "Toggle";
        Toggle1.ToolTip = "Toggle";
        Toggle1.Size = new Size(100, 20);
        Toggle1.Location = new Point(360, 30);
        Toggle1.MouseOver += Control_MouseOver;
        Toggle1.MouseOut += Control_MouseOut;

        VerticalSlider1 = (VerticalSlider)AddControl(new VerticalSlider());
        VerticalSlider1.Max = 20;
        VerticalSlider1.Max = 50;
        VerticalSlider1.ValueType = GUIForms.ValueType.Float;
        VerticalSlider1.Size = new Size(20, 100);
        VerticalSlider1.Location = new Point(5, 120);
        VerticalSlider1.MouseOver += Control_MouseOver;
        VerticalSlider1.MouseOut += Control_MouseOut;
        VerticalSlider1.ValueChanged += new ValueChangedEventHandler(VerticalSlider1_ValueChanged);

        HorizontalSlider1 = (HorizontalSlider)AddControl(new HorizontalSlider());
        HorizontalSlider1.Min = 0;
        HorizontalSlider1.Max = 10;
        HorizontalSlider1.ValueType = GUIForms.ValueType.Integer;
        HorizontalSlider1.Size = new Size(100, 20);
        HorizontalSlider1.Location = new Point(5, 100);
        HorizontalSlider1.MouseOver += Control_MouseOver;
        HorizontalSlider1.MouseOut += Control_MouseOut;
        HorizontalSlider1.ValueChanged += new ValueChangedEventHandler(HorizontalSlider1_ValueChanged);
    }


    // event handler for the slider, if wee change the value, this event is hired
    void VerticalSlider1_ValueChanged(object sender, ValueChangedEventArgs e)
    {
        LabelTooltip.Text = string.Format("VerticalSlider1={0}", e.Value);
    }

    private void HorizontalSlider1_ValueChanged(object sender, ValueChangedEventArgs e)
    {
        LabelTooltip.Text = string.Format("HorizontalSlider1={0}", e.Value);
    }


    // the event for the button, when the user click the button this event is hired
    private void ButtonClose_OnClick(object source, MouseClickEventArgs e)
    {
        if (e.MouseButton == MouseButtons.Left)
        {
            Close();
        }
    }

    private void ButtonShowMessage_OnClick(object source, MouseClickEventArgs e)
    {

        // show a messagebox (popup modal form)
        MessageBox.Show(gameObject, "Title Message", "this is a test this is a test this is a test", DefaultSkin);
    }

    // the mouseover and mouseout events shows the tooltip on the labeltooltip
    private void Control_MouseOver(object source, EventArgs e)
    {
        LabelTooltip.Text = ((Control)source).ToolTip;
    }

    private void Control_MouseOut(object source, EventArgs e)
    {
        LabelTooltip.Text = "";
    }

}

3.- Call your form

example:

TestControls.cs

using System;
using UnityEngine;
using GUIForms;

// put this script on a component of your scene

public class TestControls : MonoBehaviour
{
    public GUISkin Skin;

    private TestControlsForm Form;

    public void Awake()
    {
        // instantiate the form
        Form = (TestControlsForm)FormsManager.LoadForm(gameObject, typeof(TestControlsForm), Skin);
        // set the title
        Form.Text = "Test Controls";
        // and display it
        Form.Show(); // this is if you want a modeless form
        //Form.ShowModal(); // this is if you want a modal form
    }
}

you can see the demo webplayers in this urls:

Demo projet
http://files.marceware.com/guiforms/guiForms20091014_01.html

TestControls
http://files.marceware.com/guiforms/guiForms_test1.html

Where can i find the download for this project??

You can download on the first post, or in this url:

http://guiforms.marceware.com/downloads

Is there any possibility that you will develop any measurement tools for font sizes? The one thing i am currently having is that when I use a label I need to set the correct size of the height, in order to make it wrap and visible. I would like to:

OR measure my strings so that i can set the height according to calculations

OR that the gui does that itself :stuck_out_tongue:

Btw, some comments:
VerticalScrollbar is right now spelled wrong, you have:
VerticalScroolbar

ContainerControl is spelled wrong, you have:
ContainerControll

just some small things heh

Jan

Can you include such usefulllll thing as tooltip in your framework?

Exactly as there explainded Tooltip - Wikipedia

Jan:

Thanks i will correct the spelling error for the next version, and work on the autosizable controls.

KEMBL

Some Unirty GUI controles support tooltip and are already implemented in the framework, if you put the mouse cursor over a button hires and event mouseover. For more graphics effec is posible to show an label over the control with the tooltip text like are in winforms.

I’m developing some controls for the next week:

toolbar, matrixbuttons, listbox, droopdownlist, dropdownbox, autisize for some controls, and if is possible the tooltip message

marce

wow! Thx! Great news, will try to use your soft!

nice work,keep up!!

nice work,keep up!!

Included new controls in the GUIForms library:

  • Toolbar
  • Selectiongrid
  • ListBox (select one, multiselect)
  • DropDownList (select one, multiselect)

I’m working in others controls:

  • Tabcontrol / tabpanel
  • DropDownBox
  • Tooltip
  • AutoSize

You can view the new demo here:

http://files.marceware.com/guiforms/guiForms_test3.html

Marce

This is really fantastic. I much prefer coding this way for UI elements than:

MakeBox(a tonne of parameters that make the code pretty damn confusing to read)

The only thing i’d change is to call it UnityForms :slight_smile:

Yes, this is the reason to write the library, and because in the future is very simple to build a GUI designer over this framework.

In this moment I’m evaluating how to develop the designer tool, I think is more simple to create an external winform application, something like FarPy a GUI editor for Phyton (open source) http://farpy.holev.com/

I like the name UnityForms, I think I can change to these name for the next version.

Marce

Demo: http://files.marceware.com/guiforms/guiForms_test4.html

History:

25/10/2009

  • Add tooltips to Toolbar and DropDownList
  • Add custom control: TabControl, TabPanel (preliminar)

24/10/2009

  • Add formpanel and implementation SingleFormPanel
  • Delete Window control (not necesary)
  • Add GUI missing controls: Toolbar, SelectionGrid
  • Add custom controls: ListBox, DropDownList
  • Add autosize for Label control
  • Rewrite the Form code
  • Resolve some problems with Style and Skin

13/10/2009

  • Modal and Modeless Forms
  • Form window and without window
  • Events (mouse over, mouse out, click, change value)
  • Basic controls the GUI (missing a couple of controls as soon implementare)
  • Operates based GUISkins, is supposed to work with GUIStyles but I have not tried

212923–7823–$guiforms_20091025_897.rar (1.43 MB)

small problems

  1. in Test Controls, labels very close to border. Needs to be as in textarea.

  2. In listbox, when I try to check main check box, none of daughter check boxes was selected. When I check out main check box, all checks on daughter success cleared.

and big hopes )

  1. Still no realisation of tooltips :frowning:

  2. How about OOP interface for colour scheme changing or Font properties changing?

All other looks good and solid.

Thanks KEMBL,

Yes is in my ToDo list, I need to write some code to calculate the inner size of container controls.

The main check box if for test the single and multi select behaviour, not for select all/unselect all. But the library has these methods to select: select all, clear selection, invert selection

Is working now, you can see in the new demo a preliminar work of this.

Yes is how this must work, you can change the color and other properties in the Style of control (GUIStyle), but I have some problems and I need to rewrite all the Style and Skin stuff.

Please see the new demo and download the source code.

Thanks

Marce

Demo: http://files.marceware.com/guiforms/guiForms_test5.html

////////////

To do:

  • Custom controls: MenuBar, ComboBox
  • Add Clip with correct size (using style) to container controls (tabs, forms, etc.)
  • Revise all GUISkin and GUIStyle stuff (is not working Ok)
  • Control autosize (like Label control)
  • Control alignment
  • Form alignment
  • MultiPanel FormPanel
  • Working MessageBox like on WinForms

History:

26/10/2009

  • Solved overlaying controls, now I can write now the MenuBar control
  • Add tooltip (preliminar)

25/10/2009

  • Add tooltips to Toolbar and DropDownList
  • Add custom control: TabControl, TabPanel (preliminar)

24/10/2009

  • Add formpanel and implementation SingleFormPanel
  • Delete Window control (not necesary)
  • Add GUI missing controls: Toolbar, SelectionGrid
  • Add custom controls: ListBox, DropDownList
  • Add autosize for Label control
  • Rewrite the Form code
  • Resolve some problems with Style and Skin

13/10/2009

  • Modal and Modeless Forms
  • Form window and without window
  • Events (mouse over, mouse out, click, change value)
  • Basic controls the GUI (missing a couple of controls as soon implementare)
  • Operates based GUISkins, is supposed to work with GUIStyles but I have not tried

213136–7829–$guiforms_20091026_981.rar (1.44 MB)

The main check box if for test the single and multi select behaviour, not for select all/unselect all.

Thanks for clear explanation! It is some kind of radio-button realisation, that I was misunderstood.

Very nice tooltips!
What if object in object in object and all have got they own tooltip, аs in listbox, which will be shown when mouse over last of it?

Yes this is how is work for almost all controls, but not for ListBox and ComboListBox controls.

I think I can change for the next version, and the tooltips be working with listbox and combo box.

Marce

am i required to make a form with content or can you also randomly place a label somewhere on the screen?