Hello world! example¶
To show the basics of the Scolvo script language, we create a very simple content consisting of a menu, a menu item and appropriate event to be invoked by the Scolvo Virtual Machine when activating the menu item. In this example we use a page and a dictionary to show simple content on a client device.
The project structure is the following:
mobile.scolvo - Scolvo script file serving as the entry point of a script set of a mobile device.
mobile_dictionary_en.properties - A dictionary file containing keywords used for UI construction and values in english.
Definition of the HelloWold page¶
The logic defined in the above example function onHelloWorld is to ivoke the display(pageName, pageData, originId) built-in function of the SVM to show a page on the UI. The name of the page definition is HelloWorldPage what has to be defined in the Scolvo script file. For more details on page element please check the relevant Page element page on the Scolvo script API documentation.
Here we define a simple page for this example, having the default (general) template and vertical layout. The content consists of one label using the display1Primary template defining how the text should look like.
All page elements have lifecycle management and the Scolvo Client Framework executes automatically the appropriate event. Here the onHelloWorldPageLoaded function is executed just after the page is loaded. Actually we do not define logic for this function.
1page HelloWorldPage {
2 layout: vertical;
3 template: general;
4 settingsVisible: true;
5 scolvoMenuVisible: true;
6
7 label HelloWorldLabel {
8 template: display1Primary;
9 alignment: center;
10 }
11}
12
13function onHelloWorldPageLoaded(originId) {}
More details about the attributes of the page, and aligment of the label can be found in API documentation (Label element). We will have the settings page (included by default in all applications) navigation visible and menu will also be visible even though we will only have one item in it. Our page will consist of one label using the display1Primary template, which defines how the text will look like.
The application’s dictionary¶
A dictionary could contain key-value pairs. Scolvo Development Platform supportssupport multilingual applications, where based on the actually selected language the system looks for keys for e.g. to construct the UI. The naming pattern of a dictionary file is <clientType>_dictionary_<language>.properties.
The UI related keys reflect the structure of the pages, so the text of the menu is defined by the key menu_HelloWorld_label and the value of the lable on the page is defined by the key page_HelloWorldPage_HelloWorldLabel_defaultText.
1menu_HelloWorld_label=HelloWorld
2page_HelloWorldPage_HelloWorldLabel_defaultText=Hello world!
Content of the Scolvo scripts¶
During our lesson we’ve created two files
mobile.scolvo
and mobile_dictionary_en.properties
with the content below.
1menu defaultItem HelloWorld {
2 item HelloWorld
3}
4
5function onHelloWorld(originId) {
6 display(HelloWorldPage, {}, originId);
7}
8
9page HelloWorldPage {
10 layout: vertical;
11 template: general;
12 settingsVisible: true;
13 scolvoMenuVisible: true;
14
15 label HelloWorldLabel {
16 template: display1Primary;
17 alignment: center;
18 }
19}
20
21function onHelloWorldPageLoaded(originId) {}
1menu_HelloWorld_label=HelloWorld
2page_HelloWorldPage_HelloWorldLabel_defaultText=Hello world!
Screen shots¶
The UI resulted of the above code on different client types should look as below:
Using browser with light theme
The result in browser with light theme
Using browser with dark theme
The result in browser with dark theme
Using mobile browser with light theme
The result in mobile browser with light theme
Using mobile browser with dark theme
The result in mobile browser with dark theme
Using mobile with light theme
The result in mobile with light theme
Using mobile with dark theme
The result in mobile with dark theme