-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix generics for LayoutManager, fixes #145
- Loading branch information
Showing
6 changed files
with
130 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* 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'; | ||
import GLib from 'gi://GLib'; | ||
|
||
// Define a custom widget class with GridLayout | ||
const GridLayoutWidget = GObject.registerClass( | ||
class GridLayoutWidget extends St.Widget<Clutter.GridLayout> { | ||
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 | ||
); | ||
}); | ||
} | ||
} | ||
); | ||
|
||
// Main loop | ||
const loop = new GLib.MainLoop(null, false); | ||
|
||
// Create main window | ||
const stage = new Clutter.Stage({ | ||
width: 300, | ||
height: 200, | ||
}); | ||
|
||
// Add our widget | ||
const widget = new GridLayoutWidget(); | ||
stage.add_child(widget); | ||
|
||
// Center the widget | ||
widget.set_position( | ||
stage.width / 2 - widget.width / 2, | ||
stage.height / 2 - widget.height / 2 | ||
); | ||
|
||
// Connect signals | ||
stage.connect('destroy', () => loop.quit()); | ||
stage.show(); | ||
|
||
// Start the main loop | ||
loop.run(); |
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,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:^" | ||
} | ||
} |
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/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" | ||
] | ||
} |
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
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