From 59aa41ad707a814ea7145248c52f6f16b1c895d3 Mon Sep 17 00:00:00 2001 From: trustable-code Date: Sat, 1 Jul 2017 14:24:18 +0200 Subject: first public preview version --- examples/example_01_basic_app.nim | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 examples/example_01_basic_app.nim (limited to 'examples/example_01_basic_app.nim') diff --git a/examples/example_01_basic_app.nim b/examples/example_01_basic_app.nim new file mode 100755 index 0000000..97109c2 --- /dev/null +++ b/examples/example_01_basic_app.nim @@ -0,0 +1,61 @@ +# This example shows the basic use of the NiGui toolkit. + +import nigui +# First, import the library. + +app.init() +# Initialization is mandatory. + +var window = newWindow("NiGui Example") +# Create a window with a given title: +# By default, a window is empty and not visible. +# It is played at the center of the screen. +# A window can contain only one control. +# A container can contain multiple controls. + +window.width = 600 +window.height = 400 +# Set the size of the window + +# window.iconPath = "example_01_basic_app.png" +# The window icon can be specified this way. +# The default value is the name of the executable file without extension + ".png" + +var container = newLayoutContainer(Layout_Vertical) +# Create a container for controls. +# By default, a container is empty. +# It's size will adapt to it's child controls. +# A LayoutContainer will automatically align the child controls. +# The layout is set to clhorizontal. + +window.add(container) +# Add the container to the window. + +var button = newButton("Button 1") +# Create a button with a given title. + +container.add(button) +# Add the button to the container. + +var textArea = newTextArea() +# Create a multiline text box. +# By default, a text area is empty and editable. + +container.add(textArea) +# Add the text area to the container. + +button.onClick = proc(event: ClickEvent) = +# Set an event handler for the "onClick" event (here as anonymous proc). + + textArea.addLine("Button 1 clicked, message box opened.") + window.alert("This is a simple message box.") + textArea.addLine("Message box closed.") + +window.show() +# Make the window visible on the screen. +# Controls (containers, buttons, ..) are visible by default. + +app.run() +# At last, run the main loop. +# This processes incoming events until the application quits. +# To quit the application, dispose all windows or call "app.quit()". -- cgit v1.2.3