Skip to content
enderger edited this page Jun 15, 2020 · 2 revisions

Getting Started

Prerequisites

Currently, nimx uses SDL2 for all platforms except web, so make sure SDL2 is installed and linkable.

Install nimx

Nimx is a regular nimble package, so you could either install it or add it as a dependency to your project

# If you want to install nimx
nimble install -y nimx

# Or you could add it as a project dependency
echo 'requires "nimx"' >> MYPROJECT.nimble
# And then tell nimble to update your project dependencies
nimble install -dy

Hello, World!

Create a file called helloworld.nim with the following contents:

import nimx / [ window, layout, button, text_field ]

runApplication:
   let w = newWindow(newRect(50, 50, 500, 150))
   w.makeLayout:
      - Label as greetingLabel:
         center == super
         width == 300
         height == 15
         text: "Press the 'Greet' button to see the greeting"
       - Button:
          centerX == super
          top == prev.bottom + 5
          width == 100
          height == 25
          title: "Greet"
          onAction:
              greetingLabel.text = "Hello, world!"

Compile and run: nim c -r --threads:on helloworld

The application should launch and look like this:

https://github.com/yglukhov/nimx/blob/master/doc/hello-world-app.png?raw=true