@gjsify/example-gtk-adwaita-storybook 0.36.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/browser-main.js +589 -39
- package/dist/gjs.js +80 -4
- package/dist/gjs.node.mjs +75 -4
- package/package.json +6 -6
- package/src/browser/embed.ts +6 -15
- package/src/browser/main.ts +7 -10
- package/src/browser/overview/widgets.web.ts +118 -0
- package/src/browser/presentation/shortcut-label.web.ts +88 -0
- package/src/browser/stories.ts +4 -0
- package/src/metas.ts +2 -0
- package/src/overview/widgets.meta.ts +56 -0
- package/src/overview/widgets.story.ts +129 -0
- package/src/presentation/shortcut-label.meta.ts +90 -0
- package/src/presentation/shortcut-label.story.ts +92 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Adw.ShortcutLabel — an accelerator drawn as keycaps. original implementation.
|
|
2
|
+
|
|
3
|
+
import Adw from '@girs/adw-1';
|
|
4
|
+
import Gtk from '@girs/gtk-4.0';
|
|
5
|
+
import GObject from '@girs/gobject-2.0';
|
|
6
|
+
import { type StoryArgs, type StoryMeta, type StoryModule, StoryWidget } from '@gjsify/storybook';
|
|
7
|
+
import { SHORTCUT_LABEL_LEVELS, shortcutLabelLevelsMeta, shortcutLabelMeta } from './shortcut-label.meta.js';
|
|
8
|
+
|
|
9
|
+
/** Story: Adw.ShortcutLabel across the four levels of its accelerator grammar. */
|
|
10
|
+
export class ShortcutLabelStory extends StoryWidget {
|
|
11
|
+
private _widget: Adw.ShortcutLabel | null = null;
|
|
12
|
+
|
|
13
|
+
static {
|
|
14
|
+
GObject.registerClass({ GTypeName: 'AdwStorybookShortcutLabel' }, ShortcutLabelStory);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
super(StoryWidget.fromMeta(ShortcutLabelStory.getMetadata(), 'Default'));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static getMetadata(): StoryMeta {
|
|
22
|
+
return { ...shortcutLabelMeta, component: Adw.ShortcutLabel.$gtype };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
initialize(): void {
|
|
26
|
+
this._widget = new Adw.ShortcutLabel({
|
|
27
|
+
accelerator: this.args.accelerator as string,
|
|
28
|
+
disabledText: this.args.disabledText as string,
|
|
29
|
+
halign: Gtk.Align.CENTER,
|
|
30
|
+
valign: Gtk.Align.CENTER,
|
|
31
|
+
});
|
|
32
|
+
this.addContent(this._widget);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
updateArgs(_args: StoryArgs): void {
|
|
36
|
+
if (!this._widget) return;
|
|
37
|
+
this._widget.disabledText = this.args.disabledText as string;
|
|
38
|
+
this._widget.accelerator = this.args.accelerator as string;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
GObject.type_ensure(ShortcutLabelStory.$gtype);
|
|
43
|
+
|
|
44
|
+
/** Story: every grammar level stacked, so the rules are legible side by side. */
|
|
45
|
+
export class ShortcutLabelLevelsStory extends StoryWidget {
|
|
46
|
+
private _widgets: Adw.ShortcutLabel[] = [];
|
|
47
|
+
|
|
48
|
+
static {
|
|
49
|
+
GObject.registerClass({ GTypeName: 'AdwStorybookShortcutLabelLevels' }, ShortcutLabelLevelsStory);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
constructor() {
|
|
53
|
+
super(StoryWidget.fromMeta(ShortcutLabelLevelsStory.getMetadata(), 'Default'));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static getMetadata(): StoryMeta {
|
|
57
|
+
return { ...shortcutLabelLevelsMeta, component: Adw.ShortcutLabel.$gtype };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
initialize(): void {
|
|
61
|
+
// A grid rather than a box per row: the shortcuts line up in one column
|
|
62
|
+
// only if they share it, and the comparison is the point of this story.
|
|
63
|
+
const grid = new Gtk.Grid({ row_spacing: 12, column_spacing: 24 });
|
|
64
|
+
|
|
65
|
+
for (const [row, level] of SHORTCUT_LABEL_LEVELS.entries()) {
|
|
66
|
+
const name = new Gtk.Label({ label: level.label, halign: Gtk.Align.START });
|
|
67
|
+
name.add_css_class('dimmed');
|
|
68
|
+
grid.attach(name, 0, row, 1, 1);
|
|
69
|
+
|
|
70
|
+
const widget = new Adw.ShortcutLabel({
|
|
71
|
+
accelerator: level.accelerator,
|
|
72
|
+
disabledText: this.args.disabledText as string,
|
|
73
|
+
halign: Gtk.Align.END,
|
|
74
|
+
hexpand: true,
|
|
75
|
+
});
|
|
76
|
+
grid.attach(widget, 1, row, 1, 1);
|
|
77
|
+
this._widgets.push(widget);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.addContent(grid);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
updateArgs(_args: StoryArgs): void {
|
|
84
|
+
for (const widget of this._widgets) {
|
|
85
|
+
widget.disabledText = this.args.disabledText as string;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
GObject.type_ensure(ShortcutLabelLevelsStory.$gtype);
|
|
91
|
+
|
|
92
|
+
export const ShortcutLabelStories: StoryModule = { stories: [ShortcutLabelStory, ShortcutLabelLevelsStory] };
|