On the previous page we covered setting up your D compiler and DFL, choosing an editor or IDE, and compiling example DFL source files. Now we will cover writing some of your own DFL code.
Below is the helloworld.d from the examples:
import dfl.all; int main() { Form myForm; Label myLabel; myForm = new Form; myForm.text = "DFL Example"; myLabel = new Label; myLabel.font = new Font("Verdana", 14f); myLabel.text = "Hello, DFL World!"; myLabel.location = Point(15, 15); myLabel.autoSize = true; myLabel.parent = myForm; Application.run(myForm); return 0; }
This code can be compiled with the following command:
dfl -gui helloworld.d
Then run it with helloworld to get the following program:
Now we will go through the above code and see what it means. The parts of the code will be linked to the documentation, so you can easily click to get more information about it and what's related.
import dfl.all; - gives you access to all of DFL's public interface.
int main() { - the program's entry point function.
Form myForm; Label myLabel; - declaring a couple variables; a Form (window/dialog) and a Label (text display widget).
myForm = new Form; - to construct the Form.
myForm.text = "DFL Example"; - sets the Form's text property, which sets the window caption/title.
myLabel = new Label; - constructing the Label.
myLabel.font ? = new Font("Verdana", 14f); - sets the Label's Font: font "Verdana" at 14 points.
myLabel.text = "Hello, DFL World!"; - sets the text property of the Label, which is what is displayed on the control.
myLabel.location = Point(15, 15); - sets the location property of the Label to a Point, with x = 15 and y = 15 offset, in pixels, from the top left of its parent.
myLabel.autoSize = true; - enables the autoSize property of the Label, which causes it to automatically resize its width and height to precisely fit the text at all times.
myLabel.parent = myForm; - sets the parent property of the Label, making the label a child control of the form; this makes the label be contained within the form and be bound and relative to its dimensions.
Application.run(myForm); - this enters the main event loop and shows the form; it does not return until it gets an exit signal, such as by closing the main form (the one passed to run).
return 0; } - we return from the main function.
Entice Designer is a drag-and-drop GUI builder and code editor. Entice can be used to create the above example without writing a single line of code, simply by using point and click RAD.