Skip to content

Commit

Permalink
Readd example
Browse files Browse the repository at this point in the history
  • Loading branch information
JumpLink committed Feb 11, 2025
1 parent 4535676 commit 1450c1c
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
58 changes: 58 additions & 0 deletions examples/st-15-layout-manager/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* IMPORTANT NOTE:
* This is a demonstration of St.Widget with Layout Manager Generics for GNOME Shell Extensions.
* St (Shell Toolkit) can only be used within GNOME Shell Extensions and cannot be run as a standalone application.
*
* This example shows how to use the generic types in your extension code.
* To test this, you would need to integrate it into a proper GNOME Shell Extension.
*/

import Clutter from 'gi://Clutter';
import St from 'gi://St';
import GObject from 'gi://GObject';

export class GridLayoutWidget extends St.Widget<Clutter.GridLayout> {
static {
GObject.registerClass({
GTypeName: 'GridLayoutWidget',
}, this);
}

constructor() {
super({
layout_manager: new Clutter.GridLayout()
});

// Create and add labels in a grid pattern
const labels = [
'Top Left', 'Top Right',
'Bottom Left', 'Bottom Right'
];

labels.forEach((text, index) => {
const label = new St.Label({ text });
this.layout_manager.attach(
label,
index % 2, // column
Math.floor(index / 2), // row
1, 1
);
});
}
}

/**
* Example usage in your extension:
*
* class Extension {
* enable() {
* this._widget = new GridLayoutWidget();
* Main.uiGroup.add_child(this._widget);
* }
*
* disable() {
* this._widget.destroy();
* this._widget = null;
* }
* }
*/
26 changes: 26 additions & 0 deletions examples/st-15-layout-manager/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@ts-for-gir-example/st-15-layout-manager",
"version": "4.0.0-beta.19",
"description": "Example demonstrating St.Widget with Layout Manager Generics",
"type": "module",
"private": true,
"scripts": {
"build:app": "tsc",
"build": "yarn build:app",
"start:app": "gjs -m dist/main.js",
"start": "yarn build && yarn start:app",
"validate": "yarn validate:types",
"validate:types": "tsc --noEmit",
"clear": "rm -rf dist"
},
"devDependencies": {
"typescript": "^5.6.3"
},
"dependencies": {
"@girs/clutter-15": "workspace:^",
"@girs/gjs": "workspace:^",
"@girs/glib-2.0": "workspace:^",
"@girs/gobject-2.0": "workspace:^",
"@girs/st-15": "workspace:^"
}
}
18 changes: 18 additions & 0 deletions examples/st-15-layout-manager/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"types": ["@girs/gjs", "@girs/gjs/dom", "@girs/st-15", "@girs/clutter-15", "@girs/glib-2.0"],
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"outDir": "./dist"
},
"files": [
"main.ts"
]
}
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13178,6 +13178,19 @@ __metadata:
languageName: unknown
linkType: soft

"@ts-for-gir-example/st-15-layout-manager@workspace:examples/st-15-layout-manager":
version: 0.0.0-use.local
resolution: "@ts-for-gir-example/st-15-layout-manager@workspace:examples/st-15-layout-manager"
dependencies:
"@girs/clutter-15": "workspace:^"
"@girs/gjs": "workspace:^"
"@girs/glib-2.0": "workspace:^"
"@girs/gobject-2.0": "workspace:^"
"@girs/st-15": "workspace:^"
typescript: "npm:^5.6.3"
languageName: unknown
linkType: soft

"@ts-for-gir-example/timers-example@workspace:examples/timers":
version: 0.0.0-use.local
resolution: "@ts-for-gir-example/timers-example@workspace:examples/timers"
Expand Down

0 comments on commit 1450c1c

Please sign in to comment.