Skip to content

Commit

Permalink
Update for libui-node 0_1_0
Browse files Browse the repository at this point in the history
- Use native eventloop
- position got removed
  • Loading branch information
mischnic committed Mar 17, 2018
1 parent 1def076 commit d42ab2b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 86 deletions.
87 changes: 35 additions & 52 deletions docs/component_APIs/window.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Example extends Component {
render() {
return (
<App>
<Window title="Example" size={{w: 500, h: 500}} />
<Window title="Example" size={{ w: 500, h: 500 }} />
</App>
);
}
Expand All @@ -24,18 +24,17 @@ render(<Example />);

## Props

- [title](#title)
- [size](#size)
- [menuBar](#menuBar)
- [margined](#margined)
- [position](#position)
- [fullscreen](#fullscreen)
- [borderless](#borderless)
- [lastWindow](#lastWindow)
- [closed](#closed)
- [onClose](#onClose)
- [onPositionChange](#onPositionChange)
- [onContentSizeChange](#onContentSizeChange)
* [title](#title)
* [size](#size)
* [menuBar](#menuBar)
* [margined](#margined)
* [fullscreen](#fullscreen)
* [borderless](#borderless)
* [lastWindow](#lastWindow)
* [closed](#closed)
* [onClose](#onClose)
* [onPositionChange](#onPositionChange)
* [onContentSizeChange](#onContentSizeChange)

## Reference

Expand All @@ -44,93 +43,77 @@ render(<Example />);
The title of the window. Will be shown at the top left ribbon.

| **Type** | **Required** | **Default** |
| --- | --- | --- |
| string | No | '' |
| -------- | ------------ | ----------- |
| string | No | '' |

### size

How big the window is when the application is first started.

| **Type** | **Required** | **Default** |
| --- | --- | --- |
| object {h: number, w: number} | No | {h: 500, w: 500} |
| **Type** | **Required** | **Default** |
| ----------------------------- | ------------ | ---------------- |
| object {h: number, w: number} | No | {h: 500, w: 500} |

### menuBar

Whether a menubar will be shown on the top of the window.

| **Type** | **Required** | **Default** |
| --- | --- | --- |
| bool | No | true |
| -------- | ------------ | ----------- |
| bool | No | true |

### margined

Whether all children will have a margin around them and the outer edge of the window.

| **Type** | **Required** | **Default** |
| --- | --- | --- |
| bool | No | false |

### position

The location where the window will be started, where (0,0) is top left.

| **Type** | **Required** | **Default** |
| --- | --- | --- |
| object {x: number, y: number} | No | {x: 300, y: 300} |
| -------- | ------------ | ----------- |
| bool | No | false |

### fullscreen

Whether the window will be fullscreen on start.

| **Type** | **Required** | **Default** |
| --- | --- | --- |
| bool | No | false |
| -------- | ------------ | ----------- |
| bool | No | false |

### borderless

Whether the window will have a border on the inside.

| **Type** | **Required** | **Default** |
| --- | --- | --- |
| bool | No | false |
| -------- | ------------ | ----------- |
| bool | No | false |

## lastWindow

Whether the window is the last window. If set to `true`, then the program will quit once the window is closed.

| **Type** | **Required** | **Default** |
| --- | --- | --- |
| bool | No | true |
| -------- | ------------ | ----------- |
| bool | No | true |

### closed

Whether the window is closed. If set to closed, then the window will be closed.

| **Type** | **Required** | **Default** |
| --- | --- | --- |
| bool | No | false |
| -------- | ------------ | ----------- |
| bool | No | false |

### onClose

Called when the window is closed.

| **Type** | **Required** |
| --- | --- |
| function() | No |

### onPositionChange

Called when the window position is changed. The new position is passed as an argument, in an object.

| **Type** | **Required** |
| --- | --- |
| function({x: number, y: number}) | No |
| **Type** | **Required** |
| ---------- | ------------ |
| function() | No |

## onContentSizeChange

Called when the window size is changed by the user. The new size is passed as an argument, in an object.

| **Type** | **Required** |
| --- | --- |
| function({h: number, y: number}) | No |
| **Type** | **Required** |
| -------------------------------- | ------------ |
| function({h: number, y: number}) | No |
1 change: 0 additions & 1 deletion src/components/DesktopComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const functionMappings = {
onToggle: 'onToggled',
onSelect: 'onSelected',
onContentSizeChange: 'onContentSizeChanged',
onPositionChange: 'onPositionChanged',
};

class DesktopComponent {
Expand Down
4 changes: 1 addition & 3 deletions src/components/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import DesktopComponent, {
universalPropTypes,
universalDefaultProps,
} from './DesktopComponent';
import { start } from '../eventLoop';

// This creates the document instance
class Root extends DesktopComponent {
constructor() {
super();
libui.Ui.init();
start();
libui.startLoop();
}
render() {
this.renderChildNode();
Expand Down
33 changes: 3 additions & 30 deletions src/components/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,12 @@ class Window extends DesktopComponent {
if (newProps.margined !== oldProps.margined) {
this.element.margined = newProps.margined;
}
if (newProps.position !== oldProps.position) {
this.element.position.x = newProps.position.x;
this.element.position.y = newProps.position.y;
}
if (newProps.fullscreen !== oldProps.fullscreen) {
this.element.fullscreen = newProps.fullscreen;
}
if (newProps.borderless !== oldProps.borderless) {
this.element.borderless = newProps.borderless;
}
// if (newProps.centered !== oldProps.centered) {
// if (newProps.centered) {
// this.element.center()
// }
// }
if (newProps.closed !== oldProps.closed) {
if (newProps.closed) {
this.element.close();
Expand All @@ -69,29 +60,21 @@ class Window extends DesktopComponent {
this.props.onClose();
this.element.close();
if (this.props.lastWindow) {
stop();
libui.stopLoop();
}
});
this.element.margined = this.props.margined;
this.element.position.x = this.props.position.x;
this.element.position.y = this.props.position.y;
this.element.fullscreen = this.props.fullscreen;
this.element.borderless = this.props.borderless;

if (this.props.centered) {
this.element.center();
}

this.element.onPositionChanged(() => {
this.props.onPositionChange({
x: this.element.position.x,
y: this.element.position.y,
});
});
this.element.onContentSizeChanged(() => {
this.props.onContentSizeChange({
h: this.element.position.h,
w: this.element.position.w,
h: this.element.contentSize.h,
w: this.element.contentSize.w,
});
});
CURRENT_WINDOW = this.element;
Expand All @@ -109,17 +92,12 @@ Window.PropTypes = {
}),
menuBar: PropTypes.bool,
margined: PropTypes.bool,
position: PropTypes.shape({
x: PropTypes.number,
y: PropTypes.number,
}),
fullscreen: PropTypes.bool,
borderless: PropTypes.bool,
//centered: PropTypes.bool,
lastWindow: PropTypes.bool,
closed: PropTypes.bool,
onClose: PropTypes.func,
onPositionChange: PropTypes.func,
onContentSizeChange: PropTypes.func,
};

Expand All @@ -131,17 +109,12 @@ Window.defaultProps = {
},
menuBar: true,
margined: false,
position: {
x: 300,
y: 300,
},
fullscreen: false,
borderless: false,
//centered: true,
lastWindow: true,
closed: false,
onClose: () => {},
onPositionChange: () => {},
onContentSizeChange: () => {},
};

Expand Down

0 comments on commit d42ab2b

Please sign in to comment.