From 325ef7a8d48f50d1363d162851ad364487b0c095 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Sun, 19 Aug 2018 17:52:04 -0500 Subject: [PATCH] Initial version --- .gitignore | 5 +++++ LICENSE | 21 ++++++++++++++++++++ README.md | 39 ++++++++++++++++++++++++++++++++++++ nimui.cfg | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ nimui.nimble | 30 ++++++++++++++++++++++++++++ tests/tui.nim | 13 ++++++++++++ 6 files changed, 163 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 nimui.cfg create mode 100644 nimui.nimble create mode 100644 tests/tui.nim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d138b19 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +nimui +nimcache +*.exe +*.swp +tui* \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..69dd3a7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Ganesh Viswanathan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ce1e621 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +Nimui is a [Nim](https://nim-lang.org/) wrapper for the [libui](https://github.com/andlabs/libui) library. + +Nimui is distributed as a [Nimble](https://github.com/nim-lang/nimble) package and depends on [nimgen](https://github.com/genotrance/nimgen) and [c2nim](https://github.com/nim-lang/c2nim/) to generate the wrappers. The libui source code is downloaded using Git so having ```git``` in the path is required. + +__Installation__ + +Nimui is currently a work in progress. It can be installed via [Nimble](https://github.com/nim-lang/nimble): + +``` +> nimble install nimgen + +> git clone https://github.com/genotrance/nimui +> cd nimui +> nimble install -y +``` + +This will download, wrap and install nimui in the standard Nimble package location, typically ~/.nimble. Once installed, it can be imported into any Nim program. + +__Usage__ + +TBD + +```nim +import nimui/ui + +var opts: UiInitOptions +if uiInit(addr opts) != nil: + quit(1) +``` + +__Credits__ + +Nimui wraps the [libui](https://github.com/andlabs/libui) library and all its licensing terms apply to the usage of this package. + +Credits go out to [c2nim](https://github.com/nim-lang/c2nim/) as well without which this package would be greatly limited in its abilities. + +__Feedback__ + +Nimui is a work in progress and any feedback or suggestions are welcome. It is hosted on [GitHub](https://github.com/genotrance/nimui) with an MIT license so issues, forks and PRs are most appreciated. \ No newline at end of file diff --git a/nimui.cfg b/nimui.cfg new file mode 100644 index 0000000..a2a3248 --- /dev/null +++ b/nimui.cfg @@ -0,0 +1,55 @@ +[n.global] +output = nimui + +[n.include] +nimui +nimui/common + +[n.prepare] +git = "https://github.com/andlabs/libui" +execute-win = "windres nimui/examples/resources.rc nimui/examples/resources.o" + +[ui.h] +preprocess = true +defines = true + +recurse = true + +compile = "nimui/common/*.c" +compile-win = "nimui/windows/*.cpp" +compile-lin = "nimui/unix/*.c" + +pragma.passC = "passC: \"--std=c++11\"" +pragma-win.passL = "passL: \"-luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme -lmsimg32 -lcomdlg32 -ld2d1 -ldwrite -lole32 -loleaut32 -loleacc -luuid -lwindowscodecs -lstdc++\"" +pragma-win.rc = "link: \"nimui/examples/resources.o\"" + +flags = "--cdecl --nep1" + +[ui.nim] +regex.1 = """([u]int[\d]+)T""" +replace.1 = "$1" + +regex.2 = """([u]int)ptrT""" +replace.2 = "ptr $1" + +regex.3 = """U(.*?)\* = [a-zA-Z]+\n""" +replace.3 = """U$1* = object +""" + +regex.4 = """ (?:UiInitOptions|UiControl|UiAreaDrawParams|UiAreaMouseEvent|UiAreaKeyEvent|UiAreaHandler|UiDrawMatrix)+\* = object""" +replace.4 = "" + +regex.5 = """ (?:UiDrawBrushGradientStop|UiDrawBrush|UiDrawStrokeParams|UiFontDescriptor|UiDrawTextLayoutParams)+\* = object""" +replace.5 = "" + +regex.6 = """ (?:UiTableModelHandler|UiTableTextColumnOptionalParams|UiTableParams)+\* = object""" +replace.6 = "" + +regex.7 = """((?s: (?:UiAreaDrawParams|UiAreaMouseEvent|UiModifiers|UiAreaKeyEvent|UiExtKey)+\* .*?\n\n))""" +move.7 = "UiArea* = object\n" + +search.8 = "type\nconst\n" +replace.8 = "const\n" + +search.9 = "{.compile: \"nimui/common/OLD_table.c\".}" +comment.9 = 1 \ No newline at end of file diff --git a/nimui.nimble b/nimui.nimble new file mode 100644 index 0000000..bdf8ffd --- /dev/null +++ b/nimui.nimble @@ -0,0 +1,30 @@ +# Package + +version = "0.1.0" +author = "genotrance" +description = "libui wrapper for Nim" +license = "MIT" + +skipDirs = @["tests"] + +# Dependencies + +requires "nimgen >= 0.4.0" + +import distros + +var cmd = "" +var ldpath = "" +var ext = "" +if detectOs(Windows): + cmd = "cmd /c " + ext = ".exe" + +task setup, "Download and generate": + exec cmd & "nimgen nimui.cfg" + +before install: + setupTask() + +task test, "Test nimui": + exec "nim cpp --app:gui tests/tui.nim" \ No newline at end of file diff --git a/tests/tui.nim b/tests/tui.nim new file mode 100644 index 0000000..661abfa --- /dev/null +++ b/tests/tui.nim @@ -0,0 +1,13 @@ +import nimui/ui + +var opts: UiInitOptions +if uiInit(addr opts) != nil: + quit(1) + +# var +# mainwin: ptr UiWindow = uiNewWindow("libui Control Gallery", 640, 480, 1) + +# uiWindowSetMargined(mainwin, 1) + +# uiControlShow(cast[ptr UiControl](mainwin)) +# uiMain()