-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new pure TypeScript compiler example, fixes #183
- Loading branch information
Showing
20 changed files
with
262 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare module '*.ui' { | ||
const content: string | ||
export default content | ||
} | ||
|
||
declare module '*.css' { | ||
const content: string | ||
export default content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
window { | ||
background-color: green; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env gjs -m | ||
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later | ||
// SPDX-FileCopyrightText: 2021 Andy Holmes <[email protected]> | ||
// Based on https://gitlab.gnome.org/GNOME/gjs/-/blob/master/examples/gtk4-template.js | ||
|
||
import GObject from 'gi://GObject?version=2.0'; | ||
import GLib from 'gi://GLib?version=2.0'; | ||
import Gtk from 'gi://Gtk?version=4.0'; | ||
import Gdk from 'gi://Gdk?version=4.0'; | ||
|
||
import Template from './gtk4-template.ui'; | ||
import Style from './gtk4-template.css'; | ||
|
||
Gtk.init(); | ||
|
||
const ExampleWindow = GObject.registerClass({ | ||
GTypeName: 'ExampleWindow', | ||
Template: Template, | ||
Children: [ | ||
'box', | ||
], | ||
InternalChildren: [ | ||
'button', | ||
], | ||
}, class ExampleWindow extends Gtk.Window { | ||
|
||
box: Gtk.Box | null = null; | ||
_button: Gtk.Button | null = null; | ||
|
||
constructor() { | ||
super(); | ||
|
||
// The template has been initialized and you can access the children | ||
if (this.box) this.box.visible = true; | ||
|
||
// Internal children are set on the instance prefixed with a `_` | ||
if (this._button) this._button.visible = true; | ||
|
||
this.initStyles() | ||
} | ||
|
||
// The signal handler bound in the UI file | ||
_onButtonClicked(button: Gtk.Button) { | ||
if (this instanceof Gtk.Window) | ||
log('Callback scope is bound to `ExampleWindow`'); | ||
|
||
button.label = 'Button was clicked!'; | ||
} | ||
|
||
/** Load the stylesheet in a CssProvider and add it to the Gtk.StyleContext */ | ||
protected initStyles() { | ||
const provider = new Gtk.CssProvider(); | ||
console.log("Style", Style) | ||
provider.load_from_string(Style) | ||
const display = Gdk.Display.get_default() | ||
|
||
if (!display) { | ||
console.error('No display found') | ||
return | ||
} | ||
|
||
Gtk.StyleContext.add_provider_for_display( | ||
display, | ||
provider, | ||
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION | ||
); | ||
} | ||
}); | ||
|
||
|
||
// Create a window that stops the program when it is closed | ||
const loop = GLib.MainLoop.new(null, false); | ||
|
||
const win = new ExampleWindow(); | ||
win.connect('close-request', () => loop.quit()); | ||
win.present(); | ||
|
||
loop.run(); | ||
|
2 changes: 1 addition & 1 deletion
2
examples/gtk-4-template/package.json → examples/gtk-4-template-esbuild/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ESNext"], | ||
"types": ["@girs/gjs", "@girs/gjs/dom", "@girs/gio-2.0", "@girs/glib-2.0", "@girs/gtk-4.0"], | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"noImplicitThis": true, | ||
"alwaysStrict": true, | ||
}, | ||
"files": [ | ||
"main.ts", | ||
], | ||
"include": ["env.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
window { | ||
background-color: yellow; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!-- SPDX-License-Identifier: MIT OR LGPL-2.0-or-later --> | ||
<!-- SPDX-FileCopyrightText: 2021 Andy Holmes <[email protected]> --> | ||
<interface> | ||
<!-- Template | ||
* class: must be the `GTypeName` given in the class definition, or the | ||
class name prefixed with `Gjs_` if not given (eg `Gjs_ExampleWinow`) | ||
* parent: the GType name of the derived class | ||
--> | ||
<template class="ExampleWindow" parent="GtkWindow"> | ||
<property name="default-width">480</property> | ||
<property name="default-height">320</property> | ||
<child> | ||
<object class="GtkBox" id="box"> | ||
<property name="visible">True</property> | ||
<child> | ||
<object class="GtkButton" id="button"> | ||
<property name="label">Button</property> | ||
<property name="halign">center</property> | ||
<property name="hexpand">True</property> | ||
<property name="valign">center</property> | ||
<property name="visible">True</property> | ||
|
||
<!-- Signals | ||
* name: the signal name | ||
* handler: the name of method on the subclass to call when emitted | ||
* swapped: must always be "no" in GJS applications | ||
* object: the object bound to `this` in the callback. This is | ||
usually the template class (eg. `ExampleClass`) but may also be | ||
an object ID (eg. `box` or `button`). | ||
--> | ||
<signal name="clicked" | ||
handler="_onButtonClicked" | ||
swapped="no" | ||
object="ExampleWindow"/> | ||
</object> | ||
</child> | ||
</object> | ||
</child> | ||
</template> | ||
</interface> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@ts-for-gir-example/gtk-4-template-tsc", | ||
"version": "4.0.0-beta.10", | ||
"description": "Simple GJS Gtk 4 example app to demonstrate how you can use .ui template XML files over GJS itself", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build:app": "tsc", | ||
"build": "yarn build:app", | ||
"start:app": "gjs -m dist/main.js", | ||
"debug:app": "GTK_DEBUG=interactive yarn start:app", | ||
"start": "yarn build && yarn start:app", | ||
"validate": "yarn validate:types", | ||
"validate:types": "tsc --noEmit", | ||
"clear": "rm -rf dist @types" | ||
}, | ||
"author": "Pascal Garber <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"typescript": "^5.5.3" | ||
}, | ||
"dependencies": { | ||
"@girs/gio-2.0": "workspace:^", | ||
"@girs/gjs": "workspace:^", | ||
"@girs/glib-2.0": "workspace:^", | ||
"@girs/gtk-4.0": "workspace:^" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,10 @@ | |
// SPDX-FileCopyrightText: 2021 Andy Holmes <[email protected]> | ||
// Based on https://gitlab.gnome.org/GNOME/gjs/-/blob/master/examples/gtk4-template.js | ||
|
||
import '@girs/gjs'; | ||
import '@girs/gjs/dom'; | ||
|
||
import GObject from '@girs/gobject-2.0'; | ||
import GLib from '@girs/glib-2.0'; | ||
import Gtk from '@girs/gtk-4.0'; | ||
import Gdk from '@girs/gdk-4.0' | ||
import GObject from 'gi://GObject?version=2.0'; | ||
import GLib from 'gi://GLib?version=2.0'; | ||
import Gtk from 'gi://Gtk?version=4.0'; | ||
import Gdk from 'gi://Gdk?version=4.0'; | ||
|
||
import Template from './gtk4-template.ui?raw'; | ||
import Style from './gtk4-template.css?inline'; | ||
|
@@ -33,15 +30,12 @@ const ExampleWindow = GObject.registerClass({ | |
constructor() { | ||
super(); | ||
|
||
this.onStartup = this.onStartup.bind(this) | ||
|
||
// The template has been initialized and you can access the children | ||
if (this.box) this.box.visible = true; | ||
|
||
// Internal children are set on the instance prefixed with a `_` | ||
if (this._button) this._button.visible = true; | ||
|
||
// this.connect('startup', this.onStartup) | ||
this.initStyles() | ||
} | ||
|
||
|
@@ -53,10 +47,6 @@ const ExampleWindow = GObject.registerClass({ | |
button.label = 'Button was clicked!'; | ||
} | ||
|
||
protected onStartup(): void { | ||
this.initStyles() | ||
} | ||
|
||
/** Load the stylesheet in a CssProvider and add it to the Gtk.StyleContext */ | ||
protected initStyles() { | ||
const provider = new Gtk.CssProvider(); | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.