You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This should nicely finish up the overrides for Adw and GTK 4, while also making sure to test them. This commit removes old GTK 3 tests, which are necessary to test GTK 4. As GTK 3 is obsolete, this is an easy choice to make.
This commit also updates the GTK documentation to note the overridden behaviour, with examples.
Copy file name to clipboardExpand all lines: docs/gtk.md
+74Lines changed: 74 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,6 +49,8 @@ GTK 4 gets rid of the Container class, making it somewhat more complicated to in
49
49
-`Gtk.FlowBox`
50
50
-`Gtk.ListBox`
51
51
-`Gtk.Stack`
52
+
-`Gtk.Notebook`
53
+
-`Gtk.Grid`
52
54
53
55
An example of instantiating a `Gtk.Box` with its own children:
54
56
@@ -62,6 +64,48 @@ An example of instantiating a `Gtk.Box` with its own children:
62
64
63
65
This creates a `Gtk.Box` containing four children. Note that `box`'s `orientation` property was set to `Gtk.Orientation.VERTICAL` as well in the same constructor. For specific container widgets, this creates a programmer experience not unlike using `Gtk.Builder` for creating widget hierarchies, but with a syntax ressembling Blueprint.
64
66
67
+
### `Gtk.Notebook` Children
68
+
69
+
To construct an instance of `Gtk.Notebook` with children, special consideration must be undertaken. Adding children to this widget requires a label to be provided. Additionally, an optional menu may be provided as well. To do this, each child in the constructor must be a table with a GTK widget in the first slot, a `.tab_label` item with a child widget, and optionally a `.menu_label` item with a child widget.
70
+
71
+
local notebook = Gtk.Notebook {
72
+
{
73
+
Gtk.TextView(),
74
+
tab_label = Gtk.Label { label = "Tab 1" },
75
+
},
76
+
{
77
+
Gtk.ScrolledWindow(),
78
+
tab_label = Gtk.Label { label = "Tab 2" },
79
+
menu_label = Gtk.MenuButton(),
80
+
},
81
+
}
82
+
83
+
This example creates a `Gtk.Notebook` containing two tabs, labelled "Tab 1" and "Tab 2". Tab 2 also has a menu widget.
84
+
85
+
For convenience, this override also allows a child's `.tab_label` item to be a string. In this case, LuaGObject automatically wraps this into a `Gtk.Label` with the `.label` property set the given value. Thus, the previous example can be rewritten as:
86
+
87
+
local notebook = Gtk.Notebook {
88
+
{ Gtk.TextView(), tab_label = "Tab 1" },
89
+
{
90
+
Gtk.ScrolledWindow(),
91
+
tab_label = "Tab 2",
92
+
menu = Gtk.MenuButton(),
93
+
},
94
+
}
95
+
96
+
### `Gtk.Grid` Children
97
+
98
+
Like with `Gtk.Notebook`, the `Gtk.Grid` class also requires special consideration when adding children in its constructor. Each child added this way must be a table containing a widget in the array part, as well as integer values for `.column` and `.row`. A `.width` and/or `.height` may optionally be specified, and both will default to 1 if not given.
Gtk.Button.new_with_label "1–2, 2 (spans two columns)",
105
+
column = 1, row = 2, width = 2,
106
+
},
107
+
}
108
+
65
109
### Advanced Example: Removing Children
66
110
67
111
Many container widgets implement a `:remove()` method which takes a child `Gtk.Widget` as its argument. Without the GTK 4 override, removing a child in this way can be somewhat tricky—one may need to call a function like `:get_child_at_index()`, including adjusting the index to account for 0-indexing.
@@ -89,6 +133,7 @@ Certain classes only exist in later versions of libadwaita. These version requir
89
133
90
134
Like `Gtk.Box` and related classes, LuaGObject overrides certain Adw classes to allow specifying children to be added in constructor tables. The following widgets are supported:
91
135
136
+
-`Adw.Carousel`
92
137
-`Adw.PreferencesDialog`
93
138
- Must only contain `Adw.PreferencesPage` children.
94
139
-`Adw.PreferencesPage`
@@ -100,6 +145,8 @@ Like `Gtk.Box` and related classes, LuaGObject overrides certain Adw classes to
100
145
- Must only contain `Adw.ShortcutsSection` children.
101
146
-`Adw.ShortcutsSection` (Adw 1.8 and later)
102
147
- Must only contain `Adw.ShortcutsItem` children.
148
+
-`Adw.TabView`
149
+
-`Adw.ViewStack`
103
150
104
151
As with GTK 4, these constructors may be nested. Here is a more complex example involving the creation of a preferences page:
105
152
@@ -119,6 +166,33 @@ As with GTK 4, these constructors may be nested. Here is a more complex example
119
166
},
120
167
}
121
168
169
+
### `Adw.TabView` Constructor Children
170
+
171
+
Like with other container widgets, `Adw.TabView` can accept an arbitrary number of child widgets in the constructor table's array part. Additionally, it can also accept an arbitrary number of tables, each containing one widget in the array part and optionally also a value at `.pinned`, which will add the child widget as a pinned tab, and `.title` which is a string to be used as the tab's title. This example illustrates multiple ways to add children to a Tab View:
172
+
173
+
local tabview = Adw.TabView {
174
+
Gtk.TextView(), -- Title will be left blank
175
+
{ Gtk.TextView(), title = "Tab 2" },
176
+
{ Gtk.TextView(), title = "Tab 3", pinned = true },
177
+
}
178
+
179
+
### `Adw.ViewStack` Constructor Children
180
+
181
+
As with `Adw.TabView`, `Adw.ViewStack` children may be included in the constructor table directly, or wrapped in tables with certain additional members. These are `.name`, `.title`, and `.icon_name`. For `.title`, a `.name` must be set or it won't be used. For `.icon_name`, both a `.title` and a `.name` must be set as well. For a complete example of all ways to add children to `Adw.ViewStack` in the constructor:
182
+
183
+
local viewstack = Adw.ViewStack {
184
+
Gtk.TextView(),
185
+
{ Gtk.TextView() },
186
+
{ Gtk.TextView(), name = "Name" },
187
+
{ Gtk.TextView(), name = "Name", title = "Title" },
188
+
{
189
+
Gtk.TextView(),
190
+
name = "Name",
191
+
title = "Title",
192
+
icon_name = "icon-name",
193
+
},
194
+
}
195
+
122
196
## Constructing with Supplemental Widgets
123
197
124
198
Certain Adw classes have multiple different kinds of child widgets, preventing them from being arbitrarily added like with other container-type widgets. Widgets that work this way usually do so to distinguish between children coming before, and after, the main widget body. Each class supporting this pattern does so using class-specific methods. LuaGObject provides pseudo-properties for specific classes allowing these kinds of children to be added at construction time. Each pseudo-property is write-only and takes a value of either a single widget or a table array of widgets. Currently, these classes are:
0 commit comments