... | @@ -5,7 +5,13 @@ |
... | @@ -5,7 +5,13 @@ |
|
Object constructors look like JavaScript constructors, and can take a map of properties. Example:
|
|
Object constructors look like JavaScript constructors, and can take a map of properties. Example:
|
|
|
|
|
|
```js
|
|
```js
|
|
let actor = new Clutter.Group({ reactive: true, width: 100, height: 100 });
|
|
let label = new Gtk.Label({
|
|
|
|
label: '<a href="https://www.gnome.org">Gnome.org</a>',
|
|
|
|
halign: Gtk.Align.CENTER,
|
|
|
|
hexpand: true,
|
|
|
|
use_markup: true,
|
|
|
|
visible: true
|
|
|
|
});
|
|
```
|
|
```
|
|
|
|
|
|
> **PC** I'd suggest moving towards examples that aren't Clutter, or taken from GNOME Shell code (e.g. `Big.BoxAlignment`.) The focus should be on GTK and friends, so `Gtk.Label` with some properties might be appropriate here.
|
|
> **PC** I'd suggest moving towards examples that aren't Clutter, or taken from GNOME Shell code (e.g. `Big.BoxAlignment`.) The focus should be on GTK and friends, so `Gtk.Label` with some properties might be appropriate here.
|
... | @@ -15,7 +21,9 @@ let actor = new Clutter.Group({ reactive: true, width: 100, height: 100 }); |
... | @@ -15,7 +21,9 @@ let actor = new Clutter.Group({ reactive: true, width: 100, height: 100 }); |
|
GObject properties may be retrieved and set using JavaScript property style access. Example:
|
|
GObject properties may be retrieved and set using JavaScript property style access. Example:
|
|
|
|
|
|
```js
|
|
```js
|
|
box.y_align = Big.BoxAlignment.CENTER;
|
|
if (label.halign === Gtk.Align.CENTER) {
|
|
|
|
label.halign = Gtk.Align.FILL;
|
|
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
### Signals
|
|
### Signals
|
... | @@ -23,11 +31,18 @@ box.y_align = Big.BoxAlignment.CENTER; |
... | @@ -23,11 +31,18 @@ box.y_align = Big.BoxAlignment.CENTER; |
|
Every object inherited from GObject has `connect()`, `disconnect()` and `emit()` methods. Example:
|
|
Every object inherited from GObject has `connect()`, `disconnect()` and `emit()` methods. Example:
|
|
|
|
|
|
```js
|
|
```js
|
|
let handlerId = actor.connect('button-press-event', function (actor, event) {
|
|
let handlerId = label.connect('activate-link', (label, uri) => {
|
|
...
|
|
Gtk.show_uri_on_window(
|
|
|
|
this.get_top_level(),
|
|
|
|
uri,
|
|
|
|
Gdk.get_current_time()
|
|
|
|
);
|
|
|
|
return false;
|
|
});
|
|
});
|
|
|
|
|
|
actor.disconnect(handlerId);
|
|
label.emit('activate-link', 'https://www.gnome.org');
|
|
|
|
|
|
|
|
label.disconnect(handlerId);
|
|
```
|
|
```
|
|
|
|
|
|
**NOTE:** GJS also includes a built-in [`signals`](Modules#signals) module for applying signals to native JavaScript classes.
|
|
**NOTE:** GJS also includes a built-in [`signals`](Modules#signals) module for applying signals to native JavaScript classes.
|
... | | ... | |