From ace0198944942fac5ee91fe053ea7ed5555d5130 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Wed, 4 Apr 2018 13:01:15 +0100 Subject: [PATCH] Fixes #11. Fixes #13. Should be installable via Nimble now. --- .gitmodules | 3 ++ README.md | 52 ++++++++++++----------------------- examples/controllgallery.nim | 3 +- examples/controllgallery2.nim | 3 +- examples/histogram.nim | 3 +- examples/nim.cfg | 1 + examples/toy.nim | 3 +- ui.nimble | 5 +++- ui/libui | 1 + ui/rawui.nim | 9 +++--- 10 files changed, 35 insertions(+), 48 deletions(-) create mode 100644 .gitmodules create mode 100644 examples/nim.cfg create mode 160000 ui/libui diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..84dc714 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ui/libui"] + path = ui/libui + url = https://github.com/Araq/libui diff --git a/README.md b/README.md index 96491a6..a9834c1 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/examples/controllgallery.nim b/examples/controllgallery.nim index bc377bf..9c87b2a 100644 --- a/examples/controllgallery.nim +++ b/examples/controllgallery.nim @@ -1,7 +1,6 @@ # 2 september 2015 -import - "../ui/rawui" +import ui/rawui # TODOs # - rename variables in main() diff --git a/examples/controllgallery2.nim b/examples/controllgallery2.nim index ad714f9..44f1af2 100644 --- a/examples/controllgallery2.nim +++ b/examples/controllgallery2.nim @@ -1,7 +1,6 @@ # Test & show the new high level wrapper -import - "../ui" +import ui proc main*() = var mainwin: Window diff --git a/examples/histogram.nim b/examples/histogram.nim index 602df04..c47d934 100644 --- a/examples/histogram.nim +++ b/examples/histogram.nim @@ -1,7 +1,6 @@ # 13 october 2015 -import - "../ui/rawui", random +import ui/rawui, random var mainwin*: ptr Window diff --git a/examples/nim.cfg b/examples/nim.cfg new file mode 100644 index 0000000..5bb1fab --- /dev/null +++ b/examples/nim.cfg @@ -0,0 +1 @@ +--path:".." \ No newline at end of file diff --git a/examples/toy.nim b/examples/toy.nim index 8eb886a..74225a6 100644 --- a/examples/toy.nim +++ b/examples/toy.nim @@ -1,8 +1,7 @@ # Test & show the new high level wrapper -import - "../ui" +import ui proc main*() = var mainwin: Window diff --git a/ui.nimble b/ui.nimble index e870408..751465e 100644 --- a/ui.nimble +++ b/ui.nimble @@ -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" diff --git a/ui/libui b/ui/libui new file mode 160000 index 0000000..0cc893d --- /dev/null +++ b/ui/libui @@ -0,0 +1 @@ +Subproject commit 0cc893df6f67d6c2f9e2ce3e6c24b66a1efaaf2a diff --git a/ui/rawui.nim b/ui/rawui.nim index 80598a8..512b66c 100644 --- a/ui/rawui.nim +++ b/ui/rawui.nim @@ -1,4 +1,3 @@ - when defined(useLibUiDll): when defined(windows): const @@ -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".} @@ -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".}