Skip to content

Commit

Permalink
box
Browse files Browse the repository at this point in the history
  • Loading branch information
parro-it committed Jun 10, 2016
1 parent 28e1827 commit f707048
Show file tree
Hide file tree
Showing 14 changed files with 353 additions and 48 deletions.
8 changes: 8 additions & 0 deletions auto-top.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Automatically generated file. Edits will be lost.
# Based on: autogypi.json

{
"includes": [
"node_modules/nbind/src/nbind-common.gypi"
]
}
11 changes: 11 additions & 0 deletions auto.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Automatically generated file. Edits will be lost.
# Based on: autogypi.json

{
"include_dirs": [
"node_modules/nbind/node_modules/nan"
],
"includes": [
"node_modules/nbind/src/nbind.gypi"
]
}
6 changes: 6 additions & 0 deletions autogypi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": [
"nbind"
],
"includes": []
}
21 changes: 16 additions & 5 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
{
"targets": [
{
"target_name": "liblibui",
"sources": [ "libui.cc" ],
"include_dirs": [
"<!(node -e \"require('nan')\")"
"includes": [
"auto.gypi"
],
"libraries": ["-Wl,-rpath, ../libui/out/libui.so.0"]
"sources": [
"src/Ui.cc",
"src/UiWindow.cc",
"src/UiControl.cc",
"src/UiEntry.cc",
"src/UiBox.cc"
],
"libraries": [
"../libui/build/out/libui.so"

]
}
],
"includes": [
"auto-top.gypi"
]
}
17 changes: 16 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
const libui = require('.');
libui.Ui.init();
const win = new libui.UiWindow('Test window', 800, 600, false);
win.margined = 1;

libui.init();
const box = new libui.UiBox();
const e1 = new libui.UiEntry();
e1.enabled = 0;
box.append(new libui.UiEntry(), 1);
box.append(e1, 0);
box.append(new libui.UiEntry(), 1);
box.append(new libui.UiEntry(), 0);
win.setChild(box);
win.show();
libui.Ui.main();

/*
const win = libui.newWindow('Test window', 800, 600, true);
const entry = libui.newEntry();
libui.windowSetChild(win, entry);
Expand All @@ -11,3 +25,4 @@ libui.windowOnClosing(win, () => {
libui.windowSetMargined(win, false);
libui.controlShow(win);
libui.main();
*/
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
const bindings = require('bindings');
module.exports = bindings('libui');
const nbind = require('nbind');
const binding = nbind.init();

module.exports = binding.lib;
2 changes: 1 addition & 1 deletion libui
Submodule libui updated 134 files
79 changes: 40 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
{
"name": "libui-node",
"version": "0.0.0",
"description": "Node.js bindings for libui",
"repository": "parro-it/libui-node",
"license": "MIT",
"contributors": [
"name": "libui-node",
"version": "0.0.0",
"description": "Node.js bindings for libui",
"repository": "parro-it/libui-node",
"license": "MIT",
"contributors": [
{
"name": "Chan Guan Hao",
"email": "[email protected]",
"url": "http://mavenave.me"
},
{
"name": "Andrea Parodi",
"email": "[email protected]",
"url": "http://www.parro.it"
}

"name": "Chan Guan Hao",
"email": "[email protected]",
"url": "http://mavenave.me"
},
{
"name": "Andrea Parodi",
"email": "[email protected]",
"url": "http://www.parro.it"
}
],
"scripts": {
"test": "LD_LIBRARY_PATH=./libui/out ava && xo",
"start": "LD_LIBRARY_PATH=./libui/out node example.js",
"build-libui": "cd libui && make clean && make",
"build": "node-gyp build"
},
"keywords": [
"libui",
"scripts": {
"test": "ava && xo",
"start": "LD_LIBRARY_PATH=./libui/build/out node example.js",
"autogypi": "autogypi",
"node-gyp": "node-gyp",
"configure": "npm run -- autogypi --init-gyp -p nbind -s src/Ui.cc",
"build": "node-gyp configure build || echo failed"
},
"keywords": [
"libui",
"desktop",
"GUI"
],
"engines": {
"node": ">=5"
},
"files": [
"index.js"
],
"devDependencies": {
"ava": "^0.14.0",
"xo": "^0.14.0"
},
"gypfile": true,
"dependencies": {
"bindings": "^1.2.1",
"nan": "^2.3.3"
}
"engines": {
"node": ">=5"
},
"files": [
"index.js"
],
"devDependencies": {
"ava": "^0.14.0",
"xo": "^0.14.0"
},
"dependencies": {
"autogypi": "^0.2.2",
"nbind": "^0.2.1",
"node-gyp": "^3.3.1"
}
}
29 changes: 29 additions & 0 deletions src/Ui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "../libui/ui.h"
#include "nbind/api.h"
#include "nbind/nbind.h"

struct Ui {
static void main() {
uiMain();
}

static void quit() {
uiQuit();
}

static void init() {
uiInitOptions o;
memset(&o, 0, sizeof (uiInitOptions));
const char *err = uiInit(&o);
if (err != NULL) {
NBIND_ERR(err);
uiFreeInitError(err);
}
}
};

NBIND_CLASS(Ui) {
method(init);
method(main);
method(quit);
}
39 changes: 39 additions & 0 deletions src/UiBox.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "../libui/ui.h"
#include "nbind/api.h"
#include "nbind/nbind.h"
#include "ui-node.h"

UiBox::UiBox() : UiControl( (uiControl*) uiNewVerticalBox() ) {}

void UiBox::append(UiControl *control, int stretchy) {
uiBoxAppend(
(uiBox *) getHandle(),
control->getHandle(),
stretchy
);
}


void UiBox::destroy() { UiControl::destroy(); }
void UiBox::setParent(UiControl *parent) { UiControl::setParent(parent); }
int UiBox::toplevel() { return UiControl::toplevel(); }
int UiBox::getVisible() { return UiControl::getVisible(); }
void UiBox::setVisible(int visible) { UiControl::setVisible(visible); }
int UiBox::getEnabled() { return UiControl::getEnabled(); }
void UiBox::setEnabled(int enabled) { UiControl::setEnabled(enabled); }


NBIND_CLASS(UiBox) {
construct<>();
method(append);
method(destroy);
method(setParent);
method(toplevel);
getset(getVisible, setVisible);
getset(getEnabled, setEnabled);
}





48 changes: 48 additions & 0 deletions src/UiControl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "../libui/ui.h"
#include "nbind/api.h"
#include "nbind/nbind.h"
#include "ui-node.h"

uiControl * UiControl::getHandle() {
return handle;
}

UiControl::UiControl(uiControl* hnd) {
handle = hnd;
}

void UiControl::destroy() {
uiControlDestroy(handle);
}

void UiControl::setParent (UiControl *parent) {
uiControlSetParent(handle, parent->getHandle());
}

int UiControl::toplevel() {
return uiControlToplevel(handle);
}

int UiControl::getVisible() {
return uiControlVisible(handle);
}

void UiControl::setVisible(int visible) {
if (visible == 1) {
uiControlShow(handle);
} else {
uiControlHide(handle);
}
}

int UiControl::getEnabled() {
return uiControlEnabled(handle);
}

void UiControl::setEnabled(int enabled) {
if (enabled == 1) {
uiControlEnable(handle);
} else {
uiControlDisable(handle);
}
}
25 changes: 25 additions & 0 deletions src/UiEntry.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "../libui/ui.h"
#include "nbind/api.h"
#include "nbind/nbind.h"
#include "ui-node.h"


UiEntry::UiEntry() : UiControl( (uiControl*) uiNewEntry() ) {}

void UiEntry::destroy() { UiControl::destroy(); }
void UiEntry::setParent(UiControl *parent) { UiControl::setParent(parent); }
int UiEntry::toplevel() { return UiControl::toplevel(); }
int UiEntry::getVisible() { return UiControl::getVisible(); }
void UiEntry::setVisible(int visible) { UiControl::setVisible(visible); }
int UiEntry::getEnabled() { return UiControl::getEnabled(); }
void UiEntry::setEnabled(int enabled) { UiControl::setEnabled(enabled); }

NBIND_CLASS(UiEntry) {
construct<>();
method(destroy);
method(setParent);
method(toplevel);
getset(getVisible, setVisible);
getset(getEnabled, setEnabled);
}

45 changes: 45 additions & 0 deletions src/UiWindow.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "../libui/ui.h"
#include "ui-node.h"
#include "nbind/api.h"
#include "nbind/nbind.h"


static int closing(uiWindow *w, void *data)
{
uiControlDestroy(uiControl(w));
return 0;
}

UiWindow::UiWindow(const char* title, int width, int height, int hasMenubar) {
win = uiNewWindow(title, width, height, hasMenubar);
uiWindowOnClosing(win, closing, NULL);
}

void UiWindow::show() {
uiControlShow(uiControl(win));
}

void UiWindow::close() {
uiControlDestroy(uiControl(win));
}

void UiWindow::setMargined(int margined) {
uiWindowSetMargined(win, margined);
}

int UiWindow::getMargined() {
return uiWindowMargined(win);
}

void UiWindow::setChild(UiControl *control) {
uiWindowSetChild(win, control->getHandle());
}

NBIND_CLASS(UiWindow) {
construct<const char *, int, int, int>();
method(show);
method(close);
method(setChild);
getset(getMargined, setMargined);
}

Loading

0 comments on commit f707048

Please sign in to comment.