Skip to content
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

WIP: add typings #112

Closed
wants to merge 17 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ nbind.node
*.dll
*.exp
*.lib
.idea
8 changes: 1 addition & 7 deletions examples/control-gallery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
const os = require('os');

const libui = require('..');

Expand Down Expand Up @@ -210,11 +209,6 @@ const winProps = {
onContentSizeChanged: onPositionChanged
};

const onDarwin = os.platform() === 'darwin';
const searchText = {
text: 'Search Entry'
};

win = window(
winProps,
hBox(
Expand All @@ -225,7 +219,7 @@ win = window(
(colorBtn = colorButton({})),
checkBox({text: 'Checkbox'}),
entry({text: 'Entry'}),
onDarwin ? entry(searchText) : searchEntry(searchText),
searchEntry({ text: 'Search Entry' }),
passwordEntry({text: 'Password Entry'}),
label({text: 'Label'}),
separator({}),
Expand Down
85 changes: 85 additions & 0 deletions examples/example-from-napi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const libui = require('..');

const {UiWindow, UiHorizontalBox, UiMultilineEntry} = libui;

libui.onShouldQuit(() => {
libui.stopLoop();
global.gc();
});

function createWindow() {
let win = new UiWindow('Test Window', 800, 600, false);
win.margined = true;
const logEntry = new UiMultilineEntry();

const entry = new UiMultilineEntry();
entry.text = 'A test line\n';
entry.append('A second test line\n');
entry.onChanged(() => {
const msg = `Text changed to ${entry.text}`;
console.log(msg);
logEntry.append(msg + '\n');
});

const box = new UiHorizontalBox();
box.setPadded(true);
box.append(entry, true);
box.append(logEntry, true);

win.setChild(box);

win.onContentSizeChanged(() => {
const size = win.getContentSize();
console.log(`size changed to ${size.width}x${size.height}`);
});
let step = 0;
win.onClosing(() => {
if (win.getTitle() == 'Test Window') {
let interval = setInterval(() => {
if (step === 0) {
win.contentSize = {width: 400, height: 300};
}
if (step === 1) {
win.margined = true;
}
if (step === 2) {
win.margined = false;
win.fullscreen = true;
}
if (step === 3) {
win.fullscreen = false;
win.borderless = true;
}
if (step === 4) {
win.borderless = false;
}

if (step > 4) {
clearInterval(interval);
}

step++;

console.log({
Margined: win.margined,
Fullscreen: win.fullscreen,
Borderless: win.borderless,
});
}, 1000);
box.deleteAt(1);
return win.title = 'Wait some seconds please...';
}
console.log('closing', win.title);
win.close();
win = null;
libui.stopLoop();
});

win.show();
}

createWindow();
libui.startLoop();
setInterval(() => {
global.gc();
}, 10);
251 changes: 251 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
declare namespace LibUINode {
export const enum textWeight {
minimum = 0,
thin = 100,
ultraLight = 200,
light = 300,
book = 350,
normal = 400,
medium = 500,
semiBold = 600,
bold = 700,
ultraBold = 800,
heavy = 900,
ultraHeavy = 950,
maximum = 1000
}

export const enum textItalic {
normal = 0,
oblique = 1,
italic = 2
}

export const enum textStretch {
ultraCondensed = 0,
extraCondensed = 1,
condensed = 2,
semiCondensed = 3,
normal = 4,
semiExpanded = 5,
expanded = 6,
extraExpanded = 7,
ultraExpanded = 8
}

export const enum textAttributeType {
family = 0,
size = 1,
weight = 2,
italic = 3,
stretch = 4,
color = 5,
background = 6,
underline = 7,
underlineColor = 8,
features = 9
}

export const enum textUnderline {
none = 0,
single = 1,
double = 2,
suggestion = 3
}

export const enum textUnderlineColor {
custom = 0,
spelling = 1,
grammar = 2,
auxiliary = 3
}

export const enum textAlign {
left = 0,
center = 1,
right = 2
}

export const enum forEach {
continue = 0,
stop = 1
}

export const enum brushType {
solid = 0,
linearGradient = 1,
radialGradient = 2
// IMPL uiDrawBrushTypeImage = 3
}

export const enum lineCap {
flat = 0,
round = 1,
square = 2
}

export const enum lineJoin {
miter = 0,
round = 1,
bevel = 2
}

export const enum fillMode {
winding = 0,
alternate = 1
}

export const enum modifierKeys {
ctrl = 1 << 0,
alt = 1 << 1,
shift = 1 << 2,
super = 1 << 3
}

export const enum extKeys {
escape = 1,
insert = 2, // equivalent to "Help" on Apple keyboards
delete = 3,
home = 4,
end = 5,
pageUp = 6,
pageDown = 7,
up = 8,
down = 9,
left = 10,
right = 11,
f1 = 12, // F1..F12 are guaranteed to be consecutive
f2 = 13,
f3 = 14,
f4 = 15,
f5 = 16,
f6 = 17,
f7 = 18,
f8 = 19,
f9 = 20,
f10 = 21,
f11 = 22,
f12 = 23,
n0 = 24, // numpad keys; independent of Num Lock state
n1 = 25, // N0..N9 are guaranteed to be consecutive
n2 = 26,
n3 = 27,
n4 = 28,
n5 = 29,
n6 = 30,
n7 = 31,
n8 = 32,
n9 = 33,
nDot = 34,
nEnter = 35,
nAdd = 36,
nSubtract = 37,
nMultiply = 38,
nDivide = 39
}

export function stopLoop(): void;
export function startLoop(): void;

export class FontAttribute {
constructor(other: FontAttribute);

static newUnderlineColor(
type: textUnderlineColor,
color: Color): FontAttribute;

static getFamily(): string|null;

static getSize(): number|null;

static getWeight(): textWeight|null;

static getItalic(): textItalic|null;

static getStretch(): textStretch|null;

static getColor(): Color|null;

static getUnderline(): textUnderline|null;

static getUnderlineColor(): {
type: textAttributeType;
color: Color | null;
}|null;

static getOTFeatures(): OpenTypeFeatures|null;
}

export class OpenTypeFeatures {
add(tag: string, value: number): void;
remove(tag: string): void;
get(tag: string): number;
forEach(
cb: (feat: OpenTypeFeatures, str: string, val: number) => void): void;
static clone(feat: OpenTypeFeatures): OpenTypeFeatures;
}

export class Color {
public r: number;
public g: number;
public b: number;
public a: number;
constructor(r: number, g: number, b: number, a: number);
constructor(other: Color);
}

export class Point {
public x: number;
public y: number;
constructor(x: number, y: number);
constructor(other: Point);
}

export class Size {
public w: number;
public h: number;
constructor(w: number, h: number);
}

export class PointDouble {
public x: number;
public y: number;
constructor(x: number, y: number);
constructor(other: PointDouble);
}

export class SizeDouble {
public w: number;
public h: number;
constructor(w: number, h: number);
}

export class BrushGradientStop {
public pos: number;
public color: Color;
constructor(pos: number, color: Color);
}

export class AttributedString {
constructor(str: string);

toString(): string;
toStringLen(): number;

appendAttributed(str: string): void;
appendUnattributed(str: string): void;
insertAttributed(str: string, start: number): void;
insertUnattributed(str: string, at: number): void;
deleteString(start: number, end: number): void;
setAttribute(attr: FontAttribute, start: number, end: number): void;

// TODO: add cb parameters
forEach(cb: () => void): void;

numGraphemes(): number;
byteIndexToGrapheme(pos: number): number;
graphemeToByteIndex(pos: number): number;
}
}

export = LibUINode;
Loading