Skip to content

Commit 6a46dd4

Browse files
authored
library: Add Grid entry (#233)
1 parent 7c98cb9 commit 6a46dd4

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

src/Library/demos/Grid/main.blp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
Adw.StatusPage {
5+
title: "Grid";
6+
description: _("Arrange widgets in rows and columns.");
7+
8+
Box {
9+
halign: center;
10+
Grid {
11+
Button button00 {
12+
name: "button00";
13+
layout { row: 0; column: 0; }
14+
hexpand: false;
15+
Image {
16+
icon-name: "circle-outline-thick-symbolic";
17+
pixel-size: 100;
18+
}
19+
styles ['cell']
20+
}
21+
22+
Button button01 {
23+
name: "button01";
24+
layout { row: 0; column: 1; }
25+
hexpand: false;
26+
Image {
27+
pixel-size: 100;
28+
}
29+
styles ['cell']
30+
}
31+
Button button02 {
32+
name: "button02";
33+
layout { row: 0; column: 2; }
34+
hexpand: false;
35+
Image {
36+
pixel-size: 100;
37+
}
38+
styles ['cell']
39+
}
40+
Button button10 {
41+
name: "button10";
42+
layout { row: 1; column: 0; }
43+
hexpand: false;
44+
Image {
45+
pixel-size: 100;
46+
}
47+
styles ['cell']
48+
}
49+
Button button11 {
50+
name: "button11";
51+
layout { row: 1; column: 1; }
52+
hexpand: false;
53+
Image {
54+
pixel-size: 100;
55+
}
56+
styles ['cell']
57+
}
58+
Button button12 {
59+
name: "button12";
60+
layout { row: 1; column: 2; }
61+
hexpand: false;
62+
Image {
63+
pixel-size: 100;
64+
}
65+
styles ['cell']
66+
}
67+
Button button20 {
68+
name: "button20";
69+
layout { row: 2; column: 0; }
70+
hexpand: false;
71+
Image {
72+
pixel-size: 100;
73+
}
74+
styles ['cell']
75+
}
76+
Button button21 {
77+
name: "button21";
78+
layout { row: 2; column: 1; }
79+
hexpand: false;
80+
Image {
81+
pixel-size: 100;
82+
}
83+
styles ['cell']
84+
}
85+
Button button22 {
86+
name: "button22";
87+
layout { row: 2; column: 2; }
88+
hexpand: false;
89+
Image {
90+
pixel-size: 100;
91+
}
92+
styles ['cell']
93+
}
94+
}
95+
}
96+
}
97+

src/Library/demos/Grid/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.cell {
2+
margin: 6px;
3+
padding: 18px;
4+
}

src/Library/demos/Grid/main.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const button_ids = [
2+
"button00",
3+
"button01",
4+
"button02",
5+
"button10",
6+
"button11",
7+
"button12",
8+
"button20",
9+
"button21",
10+
"button22",
11+
];
12+
13+
for (const id of button_ids) {
14+
const button = workbench.builder.get_object(id);
15+
button.connect("clicked", onClicked);
16+
}
17+
18+
let step = 1;
19+
function onClicked(button) {
20+
//check access for user action
21+
let image = button.get_child();
22+
if (image.icon_name) return;
23+
//store and show user action
24+
image.icon_name = "cross-large-symbolic";
25+
//calculate pc reaction
26+
let pc_is_thinking = true;
27+
while (pc_is_thinking) {
28+
let pc_is_thinking_row = "" + Math.floor(Math.random() * 3);
29+
let pc_is_thinking_col = "" + Math.floor(Math.random() * 3);
30+
//make pc reaction if possible
31+
let temp = workbench.builder.get_object(
32+
"button" + pc_is_thinking_row + pc_is_thinking_col,
33+
);
34+
let temp_image = temp.get_child();
35+
if (!temp_image.icon_name) {
36+
//store and show pc reaction
37+
temp_image.icon_name = "circle-outline-thick-symbolic";
38+
pc_is_thinking = false;
39+
step += 2;
40+
}
41+
if (step >= 8) pc_is_thinking = false;
42+
}
43+
}

src/Library/demos/Grid/main.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "Grid",
3+
"category": "user_interface",
4+
"description": "Arrange widgets in rows and columns.",
5+
"panels": [
6+
"ui",
7+
"preview"
8+
],
9+
"autorun": true
10+
}

src/about.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ ${getBlueprintVersion()}
5656
"Hari Rana (TheEvilSkeleton) https://theevilskeleton.gitlab.io",
5757
"Sriyansh Shivam https://linktr.ee/sonic_here",
5858
"Angelo Verlain https://www.vixalien.com",
59+
"bazylevnik0 https://github.com/bazylevnik0",
5960
// Add yourself as
6061
// "John Doe",
6162
// or

0 commit comments

Comments
 (0)