Skip to content

Latest commit

 

History

History
77 lines (61 loc) · 3.14 KB

1.md

File metadata and controls

77 lines (61 loc) · 3.14 KB

LERN/LGUI2/1

This example, like most LGUI2 examples, consists of a controller object in LavishScript (in 1.iss) and a LavishGUI 2 package file (1.json)

Run the script with run lern/lgui2/1.

When this script runs, the LavishGUI 2 package file will be loaded via LGUI2:LoadPackage[filename], producing a window with the content "Hello World!"

This script will remain running until specifically ended, even if the window is closed by clicking its close button. End the script with end 1 when finished; the full path is not required.

When the script is ended, the LavishGUI 2 package file will be unloaded via LGUI2:UnloadPackage[filename], and thereby removing the window that was loaded.

LavishGUI 2 Packages

A LavishGUI 2 Package is a JSON object that can contain a list of UI elements, and other related data.

Schema

A $schema property is specified in order to have validation, tooltips and auto-complete while editing the JSON.

    "$schema": "http://www.lavishsoft.com/schema/lgui2Package.json",

Elements array

An elements array will specify each of the root-level GUI elements to create when this package is loaded.

    "elements": []

Element definitions

In this example, we create a window with a small handful of properties.

{
    "$schema": "http://www.lavishsoft.com/schema/lgui2Package.json",
    "elements": [
        {
            "type":"window",
            "title":"LGUI2 Example 1",
            "name": "example1.window",
            "content":"Hello World!",
            "width":200,
            "height":60
        }
    ]
}

Most of these properties are optional, however type must always be provided, and for UnloadPackage to destroy the UI elements, a name must be provided.

This is still a valid UI element that can be unloaded via UnloadPackage:

{
    "type":"window",
    "name": "example1.window"
}

Element definitions, as strings

It is also worth noting that LavishGUI 2 elements can also be represented by a string, instead of by a JSON Object. Here, content is actually accepting a UI element definition, which we have given as "Hello World!". Any element defined as a string instead of a JSON object will automatically be a textblock element, defined like so:

{
    "type":"textblock",
    "text":"Hello World!"
}

Exercises

  1. Change the content text, and run the example again

  2. Change the content to a JSON object that defines a textblock, instead of just a string

  3. Did we mention that title is also a UI element? Change the title to a JSON object that defines a textblock, instead of just a string

  4. Create your own LavishGUI 2 Package .json file with a window, and a .iss file to LoadPackage and UnloadPackage

References