This chapter creates a simple application to exemplify layout operations of the UI Composer.
The procedural flow - beginning with the output of the laid-out contents, to their loading onto the project (PSM Studio project) written in UI Toolkit Programming Guide - Quick Start - will be explained. Create a PSM Studio project in advance following instructions in the UI Toolkit Programming Guide - Quick Start .
Contents
First, create a new UI Composer project. Start up the UI Composer and from the main menu, select [File] - [Create New Project] (Figure 1).
To each item in the dialog for creating a new project, enter as follows (Figure 2).
- For the "Project Name", enter the same name as the project name of the PSM Studio project. In this example, enter "SampleApp".
- For "File Path", enter the folder where the PSM Studio project file (csproj file) is located. In this example, enter "C:\Projects\SampleApp\SampleApp".
When pressing the "OK" button of the dialog for creating a new project, the dialog for creating a new layout will be displayed (Figure 3).
This section creates a layout (destination to place widgets) and the layout canvas (screen for carrying out layout work). Layouts can be added to later on; one layout corresponds to one output class.
To each item in the dialog for creating a new layout, enter as follows (Figure 4).
- "Scene" will be selected by default for a "Class to Layout". This will not be changed in this example.
- For "Class Name", enter the name of the automatically-created class. In this example, enter "SampleScene".
- For "Size", enter the height and width of the class to lay out. Several settings are provided as presets; it is also possible to make a selection out of these. This example specifies a width of 854 px and a height of 480 px from the presets.
When the OK button is selected, a new layout canvas will be displayed in the layout window (Figure 5).
A GUI screen will be laid out with three widgets: Label, Button, and ImageBox.
First, drag-and-drop the Label from the WidgetList window and place it on the layout canvas (Figure 6).
When selecting a Label, the properties of the Label will be displayed in the property window. By editing the Text property, the text displayed to the Label can be edited (Figure 7).
In the same manner as for Label, drag-and-drop the Button from the WidgetList window and place it on the layout canvas.
Lastly, place the ImageBox.
First, open the asset window to select the image file you want to display from the "Import image" button and load the image file as an asset. image.png file is added in this example (Figure 8).
First, select the image read from the asset window and drag-and-drop the image to the layout canvas (Figure 9).
This completes layout operations (Figure 10).
Output the laid-out contents as a source code.
From the UI Composer main menu, select [File] - [Build] to build a project (Figure 11).
With initial settings, the C# source code will be created in the same folder as the UI Composer project file. In this example, 3 files, SampleScene.cs, SampleScene.composer.cs and UIStringTable.cs, will be created.
SampleScene.cs and SampleScene.composer.cs are partial class definitions of the SampleScene class, and layout operation contents carried out in the preceding section are all defined in SampleScene.composer.cs. SampleScene.composer.cs is overwritten with every build; write operations - such as, the event handler being generated by pressing a button - in SampleScene.cs. If SampleScene.cs already exists, it is not newly-generated.
Operations of the UI Composer end here.
Change the PSM Studio project so that the laid-out SampleScene is displayed.
First, load the UI Composer output results and the asset file to the PSM Studio project.
Open the PSM Studio project and add the asset file (image.png) and the C# files (SampleScene.cs, SampleScene.composer.cs, and UIStringTable.cs) output in the above section (Figures 12).
Upon adding an asset file, if the "Add File to Folder" dialog is displayed, select "Keep..." (Figure 13).
The PSM Studio project after an asset file addition will be as follows (Figure 14).
Next, modify the initialization code within the main logic.
Change the sections written to AppMain.cs as follows in UI Toolkit Programming Guide - Quick Start.
// Create scene Scene scene = new Sce.PlayStation.HighLevel.UI.Scene(); Label label = new Label(); label.X = 10.0f; label.Y = 50.0f; label.Text = "Hello World!"; scene.RootWidget.AddChildLast(label); // Set scene UISystem.SetScene(scene, null);Change the above sections as follows. If the class name and namespace created by the UI Composer differ, correct them.
// Create scene var MyScene = new SampleApp.SampleScene(); // Set scene UISystem.SetScene(MyScene, null);Correct the following section of the AppMain.cs file to make the background color white.
// Clear the screen graphics.SetClearColor (0.0f, 0.0f, 0.0f, 0.0f); graphics.Clear ();Change the above sections as follows.
// Clear the screen graphics.SetClearColor (1.0f, 1.0f, 1.0f, 1.0f); graphics.Clear ();In this state, build and execute the application in the same manner as in UI Toolkit Programming Guide - Quick Start; the laid-out screen should be displayed as is (Figure 15).