Skip to content

Commit 8ed5a8c

Browse files
authored
library: Adds toolbarview entry (#487)
1 parent 408a19a commit 8ed5a8c

File tree

5 files changed

+315
-4
lines changed

5 files changed

+315
-4
lines changed

src/Library/demos/Center Box/main.blp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ using Adw 1;
33

44
Adw.StatusPage {
55
title: _("Center Box");
6-
description: _("Displays three child widgets, while keeping the middle centered");
6+
description: _("Displays three child widgets, while keeping the middle one centered");
77

88
child: Box {
99
spacing: 24;
1010
orientation: vertical;
1111

1212
Adw.Clamp {
13-
maximum-size: bind width_adjustment.value;
14-
child: CenterBox {
13+
maximum-size: bind width_adjustment.value;
14+
child: CenterBox {
1515
shrink-center-last: true;
1616

1717
[start]
@@ -39,7 +39,7 @@ Adw.StatusPage {
3939
}
4040

4141
LinkButton {
42-
label: "API Reference";
42+
label: _("API Reference");
4343
uri: "https://docs.gtk.org/gtk4/class.CenterBox.html";
4444
}
4545
};
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
Adw.Window {
5+
width-request: 360;
6+
height-request: 640;
7+
default-width: 640;
8+
default-height: 640;
9+
10+
Adw.ToolbarView toolbar_view {
11+
extend-content-to-bottom-edge: bind extend_bottom.active;
12+
extend-content-to-top-edge: bind extend_top.active;
13+
top-bar-style: bind barstyle_select.selected;
14+
bottom-bar-style: bind barstyle_select.selected;
15+
reveal-top-bars: bind reveal_topbar.active;
16+
reveal-bottom-bars: bind reveal_bottombar.active;
17+
18+
// In this demo we are using the API to set the header bars
19+
// you can use the [top] and [bottom] child types directly instead
20+
// [top]
21+
// Adw.HeaderBar {
22+
// title-widget: Adw.WindowTitle {
23+
// title: _("Header Bar");
24+
// };
25+
// }
26+
27+
28+
content: Adw.ViewStack stack {
29+
Adw.ViewStackPage page_defualt {
30+
name: "page_default";
31+
title: _("Toolbar View");
32+
icon-name: "toolbars-symbolic";
33+
child: Adw.StatusPage{
34+
Box {
35+
halign: center;
36+
orientation: vertical;
37+
spacing: 18;
38+
Label {
39+
label: _("Toolbar View");
40+
styles ["title-1"]
41+
}
42+
Label {
43+
wrap: true;
44+
label: _("A widget containing a page, as well as top and/or bottom bars.");
45+
}
46+
LinkButton {
47+
label: _("API Reference");
48+
uri: "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.ToolbarView.html";
49+
}
50+
ListBox list_box {
51+
styles ["boxed-list"]
52+
selection-mode: none;
53+
Adw.ComboRow topbar_select {
54+
title: _("Top bar");
55+
model: StringList {
56+
strings [_("Header Bar"),_("Tab Bar"),_("View Switcher Bar"),_("Action Bar"),_("PopOverMenu Bar"),_("Search Bar"),_("Gtk Box")]
57+
};
58+
selected: 0;
59+
}
60+
Adw.ComboRow bottombar_select {
61+
title: _("Bottom bar");
62+
model: StringList {
63+
strings [_("Header Bar"),_("Tab Bar"),_("View Switcher Bar"),_("Action Bar"),_("PopOverMenu Bar"),_("Search Bar"),_("Gtk Box")]
64+
};
65+
selected: 2;
66+
}
67+
Adw.ComboRow barstyle_select {
68+
title: _("Style");
69+
model: StringList {
70+
strings [_("Flat"), _("Raised"), _("Raised-Border")]
71+
};
72+
}
73+
Adw.SwitchRow reveal_topbar {
74+
title: _("Reveal Top Bar");
75+
active: true;
76+
}
77+
Adw.SwitchRow reveal_bottombar {
78+
title: _("Reveal Bottom Bar");
79+
active: true;
80+
}
81+
Adw.SwitchRow extend_top {
82+
title: _("Extend content behind top bar");
83+
active: false;
84+
}
85+
Adw.SwitchRow extend_bottom {
86+
title: _("Extend content behind bottom bar");
87+
active: false;
88+
}
89+
}
90+
}
91+
};
92+
}
93+
94+
Adw.ViewStackPage page1 {
95+
name: "page1";
96+
title: _("Page 1");
97+
icon-name: "explore2-symbolic";
98+
use-underline: true;
99+
child: Adw.StatusPage{
100+
title: _("Hello");
101+
};
102+
}
103+
104+
Adw.ViewStackPage page2 {
105+
name: "page2";
106+
title: _("Page 2");
107+
icon-name: "explore2-symbolic";
108+
use-underline: true;
109+
child: Adw.StatusPage {
110+
title: _("from");
111+
};
112+
}
113+
114+
Adw.ViewStackPage page3 {
115+
name: "page3";
116+
title: _("Page 3");
117+
icon-name: "explore2-symbolic";
118+
use-underline: true;
119+
child: Adw.StatusPage {
120+
title: _("Workbench");
121+
};
122+
}
123+
};
124+
}
125+
}
126+
127+
Adw.HeaderBar header_bar {
128+
title-widget: Adw.WindowTitle {
129+
title: _("Header Bar");
130+
};
131+
}
132+
133+
ActionBar action_bar {
134+
revealed: true;
135+
valign: end;
136+
137+
[start]
138+
Button start_widget {
139+
icon-name: "call-start-symbolic";
140+
}
141+
142+
[center]
143+
DropDown {
144+
model: StringList {
145+
strings ["Center Widget","👁️", "❤️", "💼", "🪑"]
146+
};
147+
}
148+
149+
[end]
150+
Button end_widget {
151+
icon-name: "padlock2-symbolic";
152+
}
153+
}
154+
155+
Adw.ViewSwitcherBar switcher_bar {
156+
stack: stack;
157+
reveal: true;
158+
}
159+
160+
PopoverMenuBar popover {
161+
menu-model: menu_app;
162+
}
163+
164+
menu menu_app {
165+
section {
166+
item {
167+
label: _("Keyboard Shortcuts");
168+
action: "app.shortcuts";
169+
}
170+
171+
item {
172+
label: _("About Workbench");
173+
action: "app.about";
174+
}
175+
}
176+
}
177+
178+
SearchBar search_bar {
179+
search-mode-enabled: true;
180+
show-close-button: true;
181+
SearchEntry {
182+
placeholder-text: _("Start Searching…");
183+
}
184+
}
185+
186+
Box gtk_box {
187+
name: "gtk_box";
188+
halign: fill;
189+
height-request: 20;
190+
}
191+
192+
Adw.TabBar tab_bar {
193+
view: tab_view;
194+
}
195+
196+
Adw.TabView tab_view {
197+
Adw.TabPage main_tab_page {
198+
title: _("First Page");
199+
child: Adw.StatusPage {
200+
hexpand: true;
201+
vexpand: true;
202+
title: _("Tab View");
203+
description: _("A dynamic tabbed container");
204+
};
205+
}
206+
207+
Adw.TabPage main_tab_page2 {
208+
title: _("Second Page");
209+
child: Adw.StatusPage {
210+
hexpand: true;
211+
vexpand: true;
212+
title: _("Tab View");
213+
description: _("A dynamic tabbed container");
214+
};
215+
}
216+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#gtk_box {
2+
background-color: purple;
3+
}
4+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import Gio from "gi://Gio";
2+
import Gdk from "gi://Gdk";
3+
import GObject from "gi://GObject";
4+
import Gtk from "gi://Gtk";
5+
import Adw from "gi://Adw";
6+
7+
const topbar_select = workbench.builder.get_object("topbar_select");
8+
const bottombar_select = workbench.builder.get_object("bottombar_select");
9+
const toolbar_view = workbench.builder.get_object("toolbar_view");
10+
11+
let top_bar;
12+
let bottom_bar;
13+
14+
function changeTopBar(name) {
15+
const new_top_bar = workbench.builder.get_object(name);
16+
top_bar && toolbar_view.remove(top_bar);
17+
toolbar_view.add_top_bar(new_top_bar);
18+
top_bar = new_top_bar;
19+
}
20+
21+
function changeBottomBar(name) {
22+
const new_bottom_bar = workbench.builder.get_object(name);
23+
bottom_bar && toolbar_view.remove(bottom_bar);
24+
toolbar_view.add_bottom_bar(new_bottom_bar);
25+
bottom_bar = new_bottom_bar;
26+
}
27+
28+
topbar_select.connect("notify::selected-item", selectTopBar);
29+
bottombar_select.connect("notify::selected-item", selectBottomBar);
30+
31+
selectTopBar();
32+
selectBottomBar();
33+
34+
function selectTopBar() {
35+
switch (topbar_select.selected) {
36+
case 0:
37+
changeTopBar("header_bar");
38+
break;
39+
case 1:
40+
changeTopBar("tab_bar");
41+
break;
42+
case 2:
43+
changeTopBar("switcher_bar");
44+
break;
45+
case 3:
46+
changeTopBar("action_bar");
47+
break;
48+
case 4:
49+
changeTopBar("popover");
50+
break;
51+
case 5:
52+
changeTopBar("search_bar");
53+
break;
54+
case 6:
55+
changeTopBar("gtk_box");
56+
break;
57+
}
58+
}
59+
60+
function selectBottomBar() {
61+
switch (bottombar_select.selected) {
62+
case 0:
63+
changeBottomBar("header_bar");
64+
break;
65+
case 1:
66+
changeBottomBar("tab_bar");
67+
break;
68+
case 2:
69+
changeBottomBar("switcher_bar");
70+
break;
71+
case 3:
72+
changeBottomBar("action_bar");
73+
break;
74+
case 4:
75+
changeBottomBar("popover");
76+
break;
77+
case 5:
78+
changeBottomBar("search_bar");
79+
break;
80+
case 6:
81+
changeBottomBar("gtk_box");
82+
break;
83+
}
84+
}
85+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "layout",
3+
"description": "A widget containing a page, as well as top and/or bottom bars.",
4+
"panels": ["ui", "preview"],
5+
"autorun": true
6+
}

0 commit comments

Comments
 (0)