Skip to content

Fixes #11. Fixes #13. Should be installable via Nimble now. #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ui/libui"]
path = ui/libui
url = https://github.com/Araq/libui
52 changes: 18 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,30 @@
# UI

This package wraps the [libui](https://github.com/andlabs/libui) C library.
This package wraps the [libui](https://github.com/andlabs/libui) C library. It
also provides a high-level Nim binding for it.

In order to make use of it you will need to do:
To get started, install using Nimble:

```bash
nimble install ui
```
cd ui
cd .. # ensure libui is a sibling of your ui directory
git clone https://github.com/araq/libui
cd ui
nim c -r examples/controllgallery2.nim
```


## Using the wrapper

Test that everything works by using this code sample:
or add it to your project's Nimble file:

```nim
requires "ui"
```

import
ui

proc main() =
var mainwin = newWindow("libui Control Gallery", 640, 480, true)
mainwin.margined = true
mainwin.onClosing = (proc (): bool = return true)

let box = newVerticalBox(true)
mainwin.setChild(box)

var group = newGroup("Basic Controls", true)
box.add(group, false)

var inner = newVerticalBox(true)
group.child = inner
You should then be able to compile the sample code in the
[``examples/``](https://github.com/nim-lang/ui/tree/master/examples)
directory successfully.

inner.add newButton("Button", proc() = msgBox(mainwin, "Info", "button clicked!"))
## Static vs. dynamic linking

show(mainwin)
mainLoop()
This library installs the C sources for libui and statically compiles them
into your application.

init()
main()
```
Static compilation is the default behaviour, but if you would prefer to depend
on a DLL instead, pass the ``-d:useLibUiDll`` to the Nim compiler. You will
then need to bundle your application with a libui.dll, libui.dylib, or libui.so
for Windows, macOS, and Linux respectively.
3 changes: 1 addition & 2 deletions examples/controllgallery.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# 2 september 2015

import
"../ui/rawui"
import ui/rawui

# TODOs
# - rename variables in main()
Expand Down
3 changes: 1 addition & 2 deletions examples/controllgallery2.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Test & show the new high level wrapper

import
"../ui"
import ui

proc main*() =
var mainwin: Window
Expand Down
3 changes: 1 addition & 2 deletions examples/histogram.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# 13 october 2015

import
"../ui/rawui", random
import ui/rawui, random

var mainwin*: ptr Window

Expand Down
1 change: 1 addition & 0 deletions examples/nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--path:".."
3 changes: 1 addition & 2 deletions examples/toy.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

# Test & show the new high level wrapper

import
"../ui"
import ui

proc main*() =
var mainwin: Window
Expand Down
5 changes: 4 additions & 1 deletion ui.nimble
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Package

version = "0.9"
version = "0.9.2"
author = "Andreas Rumpf"
description = "Nim\'s official UI library"
license = "MIT"

installDirs = @["ui"]
installFiles = @["ui.nim"]

# Dependencies

requires "nim >= 0.16.1"
Expand Down
1 change: 1 addition & 0 deletions ui/libui
Submodule libui added at 0cc893
9 changes: 4 additions & 5 deletions ui/rawui.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

when defined(useLibUiDll):
when defined(windows):
const
Expand All @@ -21,11 +20,11 @@ else:
{.passC: cflags.}
{.passL: lflags.}

{.compile: ("../../libui/common/*.c", "common_$#.obj").}
{.compile: ("./libui/common/*.c", "common_$#.obj").}
when defined(windows):
{.compile: ("../../libui/windows/*.cpp", "win_$#.obj").}
{.compile: ("./libui/windows/*.cpp", "win_$#.obj").}
elif defined(macosx):
{.compile: ("../../libui/darwin/*.m", "osx_$#.obj").}
{.compile: ("./libui/darwin/*.m", "osx_$#.obj").}

{.passL: "-framework OpenGL".}
{.passL: "-framework CoreAudio".}
Expand All @@ -35,7 +34,7 @@ else:
{.passL: "-framework IOKit".}
{.passL: "-framework Cocoa".}
else:
{.compile: ("../../libui/unix/*.c", "unix_$#.obj").}
{.compile: ("./libui/unix/*.c", "unix_$#.obj").}
when defined(gcc) and defined(windows):
#{.passL: r"C:\Users\rumpf\projects\mingw64\x86_64-w64-mingw32\lib\liboleaut32.a".}
{.passL: r"-lwinspool".}
Expand Down