2.2-The First Window

One of the classes that form the foundation is the window: the window is the heart of the graphical interface because it will have to accommodate the various gadgets and will have to react to certain events such as resizing, closure, iconification, etc., but it can also respond to events from the keyboard and run the associated callback functions.

To try not to confuse you, I will try to introduce the topics and features a little at a time so as to give you time to assimilate the basic concepts, one by one, without any unnecessary frustration.

Here in the first tutorial we will see a few things including the debug system and the instructions needed to open a window in HGui.

The debug system is important to find out if something went wrong. In this first phase of learning I think it is extremely important to understand and observe the debug log as HGui acts upon and executes our instructions.

Create a new script and enter the following program:

; Include the HGui library in your application
@INCLUDE "yourpath/+Includes.hws"
The two includes are used to load the HGui library and other dependencies which HGui needs.
;We activate the debug system with the following code:
DBG.Console.Enable(True, False)
The first line is used to enable the debug system. The first parameter is used to include the millisecond timer on each debug line and the second parameter is used to enable / disable support for the ANSI sequences. If your terminal supports ANSI sequences you should activate it by replacing False with True: this way alerts and errors will be shown with an easily identifiable color.

The second line is used to enable debugging in the HGui library, no other type of debugging will be shown if it is not explicitly activated with the DBG.Console.AddChannel() command. For more information please refer to the documentation for the Debug library.

Now let's see how to create a window object, the window will open when you create it:
Local myFirstWindow = HGui.Window:new({ title = "My First Window!" })

As you can see the method: new() is used to create a window object. This method accepts a table as input that is used to customize the window to be created. In our example, we customized just the title of the window that is what will be shown in the top bar.

Since it returns a window object, we really need to store the handle to be able to use the methods. In this case we have stored it in the local variable myFirstWindow although in our simple example it would not be necessary. If the creation of the window had failed for any reason we would have had a result of False.

Finally, we place an infinite loop that allows us to detect events still:
This ends first tutorial but if you want to try some more, move or resize the window and you will see that events will be detected and displayed in the debug window.
Sign In or Register to comment.