Skip to content

Commit 587fb7d

Browse files
authored
library: Add ViewSwitcher entry (#236)
1 parent 5e5d023 commit 587fb7d

3 files changed

Lines changed: 193 additions & 0 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
Adw.Window {
5+
modal: true;
6+
width-request: 360;
7+
height-request: 360;
8+
content:
9+
Box {
10+
orientation: vertical;
11+
12+
Adw.HeaderBar {
13+
centering-policy: strict;
14+
title-widget:
15+
Adw.ViewSwitcherTitle switcher_title {
16+
stack: stack;
17+
title: _("AdwViewSwitcher Demo");
18+
};
19+
}
20+
21+
Adw.ViewStack stack {
22+
vexpand: true;
23+
24+
Adw.ViewStackPage page1 {
25+
name: "page1";
26+
title: _("Favorites");
27+
icon-name: "star-filled-rounded-symbolic";
28+
use-underline: true;
29+
child:
30+
31+
Adw.StatusPage{
32+
title: bind page1.title;
33+
icon-name: bind page1.icon-name;
34+
child:
35+
36+
Box{
37+
orientation: vertical;
38+
valign: center;
39+
40+
LinkButton {
41+
label: "API Reference";
42+
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.2/class.ViewSwitcher.html";
43+
}
44+
LinkButton {
45+
label: "Human Interface Guidelines";
46+
uri: "https://developer.gnome.org/hig/patterns/nav/view-switchers.html";
47+
}
48+
};
49+
};
50+
}
51+
52+
Adw.ViewStackPage page2 {
53+
name: "page2";
54+
title: _("Recents");
55+
icon-name: "clock-alt-symbolic";
56+
use-underline: true;
57+
child:
58+
59+
Adw.StatusPage{
60+
title: bind page2.title;
61+
icon-name: bind page2.icon-name;
62+
child:
63+
64+
Box{
65+
orientation: vertical;
66+
valign: center;
67+
68+
LinkButton {
69+
label: "API Reference";
70+
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.2/class.ViewSwitcher.html";
71+
}
72+
LinkButton {
73+
label: "Human Interface Guidelines";
74+
uri: "https://developer.gnome.org/hig/patterns/nav/view-switchers.html";
75+
}
76+
};
77+
};
78+
}
79+
80+
81+
Adw.ViewStackPage page3 {
82+
name: "page3";
83+
title: _("Notifications");
84+
icon-name: "bell-symbolic";
85+
badge-number: 0;
86+
needs-attention: true;
87+
use-underline: true;
88+
child:
89+
90+
Adw.StatusPage{
91+
title: bind page3.title;
92+
valign: start;
93+
margin-start: 15;
94+
margin-end: 15;
95+
child:
96+
97+
Adw.Clamp{
98+
maximum-size: 500;
99+
ListBox notification_list{
100+
halign: baseline;
101+
styles["boxed-list"]
102+
103+
}
104+
};
105+
};
106+
}
107+
108+
Adw.ViewStackPage page4{
109+
name: "page4";
110+
title: _("Account");
111+
icon-name: "person-symbolic";
112+
use-underline: true;
113+
child:
114+
115+
Adw.StatusPage{
116+
title: bind page4.title;
117+
icon-name: bind page4.icon-name;
118+
child:
119+
120+
Box{
121+
orientation: vertical;
122+
valign: center;
123+
124+
LinkButton {
125+
label: "API Reference";
126+
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.2/class.ViewSwitcher.html";
127+
}
128+
129+
LinkButton {
130+
label: "Human Interface Guidelines";
131+
uri: "https://developer.gnome.org/hig/patterns/nav/view-switchers.html";
132+
}
133+
};
134+
};
135+
}
136+
}
137+
138+
Adw.ViewSwitcherBar switcher_bar {
139+
stack: stack;
140+
reveal: bind switcher_title.title-visible;
141+
}
142+
};
143+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Adw from "gi://Adw";
2+
import Gtk from "gi://Gtk";
3+
4+
const notifications_page = workbench.builder.get_object("page3");
5+
const notification_list = workbench.builder.get_object("notification_list");
6+
7+
let notification_count = 5;
8+
notifications_page.badge_number = notification_count;
9+
10+
for (let i = 0; i < notification_count; i++) {
11+
let notification_row = new Adw.ActionRow({
12+
selectable: false,
13+
});
14+
15+
notification_row.title = "Notification";
16+
17+
let button = new Gtk.Button({
18+
halign: "center",
19+
valign: "center",
20+
margin_top: "10",
21+
margin_bottom: "10",
22+
icon_name: "check-plain-symbolic",
23+
});
24+
25+
button.connect("clicked", () => {
26+
notifications_page.badge_number = --notification_count;
27+
notification_list.remove(notification_row);
28+
29+
if (notifications_page.badge_number === 0) {
30+
notifications_page.needs_attention = false;
31+
}
32+
});
33+
34+
notification_row.add_suffix(button);
35+
36+
notification_list.append(notification_row);
37+
}
38+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "View Switcher",
3+
"category": "user_interface",
4+
"description": "View Switchers allow users to switch between different predefined pages",
5+
"panels": [
6+
"code",
7+
"ui",
8+
"preview"
9+
],
10+
"autorun": false
11+
}
12+

0 commit comments

Comments
 (0)