macOS GUI Library for the Nim Programming Language

The Nim language is a new programming language that promises to be easy to learn and fast. Its development team has created an interface for Mac OS X, which allows programmers to use the GUI library without having to write any code.

The nim gtk is a GUI library for the Nim programming language. It provides an interface to the GTK+ toolkit, which makes it easy to create graphical user interfaces in Nim.

NimCocoa is a macOS-based experimental implementation of a Native GUI for the Nim programming language.

Rather than relying on low-level calls to objc msgsend and its variations, it employs custom Objective-C code modules wrapped in C-Style methods that Nim may utilize.

The following GUI items are now available:

  • NSWindow

  • NSButton

  • NSCombobox

  • NSLabel

  • NSMenu

  • NSSavedialog

  • NSTextfield

  • NSCheckbox

  • NSDialog

  • NSLine

  • NSMessagebox

  • NSSlider

  • NSListbox

  • NSOpendialog

  • NSTextedit

  • NSRadioButton

  • NSTabView

  • NSContainer is a class that represents a container (Groupbox)

  •  

The doc folder contains preliminary documentation for GUI objects.

Here’s an example of what NimCocoa code looks like:

import Cocoa / [NSWindow, NSTextfield, NSLabel, NSCheckbox, NSButton, NSLine, NSOpendialog, NSFunctions] import json, os, plists, times var mainWin: ID var lblFile, txtFile, btnFile, lblAuthor, txtAuthor, lblApp, txtApp, lblImage, txtImage, btnImage, line1, lblVersion, txtVersion, lblIdent, txtIdent, line2, chkLaunch, btnExec: ID const width:cint = 800 height:cint = 310 winStyle = NSWindowStyleMaskTitled or NSWindowStyleMaskClosable or NSWindowStyleMaskMiniaturizable proc main() = Cocoa_Init() mainWin = newWindow(“macOS Application Bundler”, width, height, winStyle) lblFile = newLabel(mainWin, “Select Executable”,30, 20, 120, 25) txtFile = newTextField(mainWin, “”, 160, 20, 500, 25) btnFile = newButton(mainWin, “Load”, 680, 20, 100, 25, getExecutable) txtFile.anchor=akWidth; btnFile.anchor=akRight lblAuthor = newLabel(mainWin, “Author Name”, 30, 60, 120, 25) txtAuthor = newTextField(mainWin, “”, 160, 60, 500, 25) txtAuthor.anchor=akWidth lblApp = newLabel(mainWin, “Application Name”, 30, 100, 120, 25) txtApp = newTextField(mainWin, “”, 160, 100, 170, 25) txtApp.anchor=akWidth lblImage = newLabel(mainWin, “Select Icon File”, 30, 200, 120, 25) txtImage = newTextField(mainWin, “”, 160, 200, 500, 25) btnImage = newButton(mainWin, “Load”, 680, 200, 100, 25, getImage) txtImage.anchor=akWidth; btnImage.anchor=akRight line1 = newSeparator(mainWin, 30, 140, 750) lblVersion = newLabel(mainWin, “Application Version”, 350, 100, 130, 25) txtVersion = newTextField(mainWin, “”, 490, 100, 170, 25) txtVersion.anchor=akRight; lblVersion.anchor=akRight lblIdent = newLabel(mainWin, “Bundle Identifier”, 30, 160, 120, 25) txtIdent = newTextField(mainWin, “”, 160, 160, 500, 25) # btnCredits = newButton(mainWin, “Load”, 680, 160, 100, 25, nil) txtIdent.anchor=akWidth line2 = newSeparator(mainWin, 20, 240, 750) chkLaunch = newCheckBox(mainWin, “Launch Application?”, 320, 270, 150, 25) btnExec = newButton(mainWin, “Execute”, 680, 270, 100, 25, createAppBundle) chkLaunch.anchor=akLeft + akRight + akBottom; btnExec.anchor=akRight + akBottom Cocoa_Run(mainWin) if isMainModule: main()

As a consequence, the following occurs:

bundler

Another illustration:

Resized version of the same program, demonstrating how items flow depending on their associated ‘anchor’ setting:

Thesaurus-resized

I’m currently describing the accessible objects/functions and providing examples.

Keep an eye out!

GitHub

https://github.com/Airr/nim-cocoa

The nim fidget is a library that allows for the creation of GUI applications in Nim. It has been created by the Nim team and they are currently working on its development.

Related Tags

  • nim gui
  • nigui
  • nim lang
  • nim qt
  • why nim