... | ... | @@ -4,27 +4,62 @@ |
|
|
|
|
|
Object constructors look like JavaScript constructors, and can take a map of properties. Example:
|
|
|
|
|
|
let actor = new Clutter.Group({ reactive: true, width: 100, height: 100 });
|
|
|
```js
|
|
|
let actor = new Clutter.Group({ reactive: true, width: 100, height: 100 });
|
|
|
```
|
|
|
|
|
|
### Properties
|
|
|
|
|
|
GObject properties may be retrieved and set using JavaScript property style access. Example:
|
|
|
|
|
|
```js
|
|
|
box.y_align = Big.BoxAlignment.CENTER;
|
|
|
```
|
|
|
|
|
|
### Signals
|
|
|
|
|
|
Every gjs object has a "connect" method. Example:
|
|
|
Every objects inherited from GObject have a "connect" method. Example:
|
|
|
|
|
|
actor.connect('button-press-event', function (actor, event) {
|
|
|
...
|
|
|
});
|
|
|
```js
|
|
|
actor.connect('button-press-event', function (actor, event) {
|
|
|
...
|
|
|
});
|
|
|
```
|
|
|
|
|
|
### GProperties
|
|
|
**NOTE:** GJS also includes a signals import for applying signals to native classes:
|
|
|
|
|
|
GObject properties may be retrieved and set using JavaScript property style access. Example:
|
|
|
```js
|
|
|
const Signals = imports.signals;
|
|
|
|
|
|
var MyJSClass = class {
|
|
|
testSignalEmission () {
|
|
|
this.emit("exampleSignal");
|
|
|
this.emit("exampleSignal2", "stringArg", 42);
|
|
|
}
|
|
|
}
|
|
|
Signals.addSignalMethods(MyJSClass.prototype);
|
|
|
|
|
|
let obj = new MyJSObject();
|
|
|
let handlerId = obj.connect("exampleSignal", () => log("exampleSignal emitted"));
|
|
|
obj.connect("exampleSignal2", (stringArg, intArg) => {
|
|
|
log(stringArg);
|
|
|
log(intArg);
|
|
|
});
|
|
|
|
|
|
obj.testSignalEmission();
|
|
|
|
|
|
box.y_align = Big.BoxAlignment.CENTER;
|
|
|
// Disconnecting signals by id or all at once
|
|
|
obj.disconnect(handler);
|
|
|
obj.disconnectAll();
|
|
|
```
|
|
|
|
|
|
## Enumerations and Flags
|
|
|
|
|
|
Both enumerations and flags appear as entries under the namespace, with associated member properties. Example:
|
|
|
|
|
|
Gtk.WindowType.TOPLEVEL;
|
|
|
```js
|
|
|
Gtk.WindowType.TOPLEVEL;
|
|
|
```
|
|
|
|
|
|
## Structures
|
|
|
|
... | ... | @@ -38,10 +73,14 @@ Unions are currently opaque. |
|
|
|
|
|
For functions which have multiple out parameters, the return values are gathered into an array. Example:
|
|
|
|
|
|
// Calling clutter_actor_get_size
|
|
|
let [x, y] = actor.get_size();
|
|
|
```js
|
|
|
// Calling clutter_actor_get_size
|
|
|
let [x, y] = actor.get_size();
|
|
|
```
|
|
|
|
|
|
If the function has a return value, in addition to the out parameters, the return value will be the first element of such array. Example:
|
|
|
|
|
|
// Calling gtk_recent_info_get_application_info
|
|
|
let [success, appExec, count, time] = this._docInfo.get_application_info(appName); |
|
|
\ No newline at end of file |
|
|
```js
|
|
|
// Calling gtk_recent_info_get_application_info
|
|
|
let [success, appExec, count, time] = this._docInfo.get_application_info(appName);
|
|
|
``` |
|
|
\ No newline at end of file |