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
One of the most popular reasons to use actions are keyboard accelerators, so we added one here.
26
-
With [`set_accels_for_action`](../docs/gtk4/prelude/trait.GtkApplicationExt.html#tymethod.set_accels_for_action) one can assign one or more accelerators to a certain action.
27
-
Check the documentation of [`accelerator_parse`](../docs/gtk4/functions/fn.accelerator_parse.html) in order to learn more about its syntax.
26
+
With [`set_accels_for_action`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.GtkApplicationExt.html#tymethod.set_accels_for_action) one can assign one or more accelerators to a certain action.
27
+
Check the documentation of [`accelerator_parse`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/functions/fn.accelerator_parse.html) in order to learn more about its syntax.
28
28
29
29
Before we move on to other aspects of actions, let's appreciate a few things that are curious here.
30
30
The "win" part of "win.close" is the group of the action.
@@ -47,7 +47,7 @@ However, that also means that we actually define one action per window instance.
47
47
If we want to have a single globally accessible action instead, we call `add_action` on our application instead.
48
48
49
49
> Adding "win.close" was useful as a simple example.
50
-
> However, in the future we will use the pre-defined ["window.close"](../docs/gtk4/struct.Window.html#actions) action which does exactly the same thing.
50
+
> However, in the future we will use the pre-defined ["window.close"](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Window.html#actions) action which does exactly the same thing.
51
51
52
52
## Parameter and State
53
53
@@ -76,10 +76,10 @@ This is how our app works:
76
76
77
77
## Actionable
78
78
79
-
Connecting actions to the "clicked" signal of buttons is a typical use case, which is why all buttons implement the [`Actionable`](../docs/gtk4/struct.Actionable.html) interface.
79
+
Connecting actions to the "clicked" signal of buttons is a typical use case, which is why all buttons implement the [`Actionable`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Actionable.html) interface.
80
80
This way, the action can be specified by setting the "action-name" property.
81
81
If the action accepts a parameter, it can be set via the "action-target" property.
82
-
With [`ButtonBuilder`](../docs/gtk4/builders/struct.ButtonBuilder.html), we can set everything up by calling its methods.
82
+
With [`ButtonBuilder`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/builders/struct.ButtonBuilder.html), we can set everything up by calling its methods.
Since we connect the menu to the [`gtk::MenuButton`](../docs/gtk4/struct.MenuButton.html) via the [menu-model](../docs/gtk4/struct.MenuButton.html#menu-model) property, the `Menu` is expected to be a [`gtk::PopoverMenu`](../docs/gtk4/struct.PopoverMenu.html).
210
-
The [documentation](../docs/gtk4/struct.PopoverMenu.html) for `PopoverMenu` also explains its `xml` syntax for the interface builder.
209
+
Since we connect the menu to the [`gtk::MenuButton`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.MenuButton.html) via the [menu-model](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.MenuButton.html#menu-model) property, the `Menu` is expected to be a [`gtk::PopoverMenu`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.PopoverMenu.html).
210
+
The [documentation](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.PopoverMenu.html) for `PopoverMenu` also explains its `xml` syntax for the interface builder.
211
211
212
212
Also note how we specified the target:
213
213
@@ -234,7 +234,7 @@ This is how the app looks in action:
234
234
</div>
235
235
236
236
>We changed the icon of the `MenuButton` by setting its property "icon-name" to "open-menu-symbolic".
237
-
>You can find more icons with the [Icon Library](https://apps.gnome.org/app/org.gnome.design.IconLibrary/).
237
+
>You can find more icons with the [Icon Library](https://flathub.org/apps/org.gnome.design.IconLibrary).
238
238
>They can be embedded with [`gio::Resource`](https://gtk-rs.org/gtk-rs-core/stable/latest/docs/gio/struct.Resource.html) and then be referenced within the composite templates (or other places).
The most outer tag always has to be the `<interface>`.
28
28
Then you start listing the elements you want to describe.
29
-
In order to define a composite template, we specify the name `MyGtkAppWindow` of the custom widget we want to create and the parent [`gtk::ApplicationWindow`](../docs/gtk4/struct.ApplicationWindow.html) it derives of.
29
+
In order to define a composite template, we specify the name `MyGtkAppWindow` of the custom widget we want to create and the parent [`gtk::ApplicationWindow`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.ApplicationWindow.html) it derives of.
30
30
These `xml` files are independent of the programming language, which is why the classes have the original names.
31
31
Luckily, they all convert like this: `gtk::ApplicationWindow` → `GtkApplicationWindow`.
32
-
Then we can specify properties which are listed [here](../docs/gtk4/struct.ApplicationWindow.html#properties) for `ApplicationWindow`.
32
+
Then we can specify properties which are listed [here](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.ApplicationWindow.html#properties) for `ApplicationWindow`.
33
33
Since `ApplicationWindow` can contain other widgets we use the `<child>` tag to add a `gtk::Button`.
34
34
We want to be able to refer to the button later on so we also set its `id`.
In the implementation struct, we then add the derive macro [`gtk::CompositeTemplate`](../docs/gtk4_macros/derive.CompositeTemplate.html).
84
+
In the implementation struct, we then add the derive macro [`gtk::CompositeTemplate`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4_macros/derive.CompositeTemplate.html).
85
85
We also specify that the template information comes from a resource of prefix `/org/gtk-rs/example` containing a file `window.ui`.
86
86
87
87
One very convenient feature of templates is the template child.
88
88
You use it by adding a struct member with the same name as one `id` attribute in the template.
89
-
[`TemplateChild`](../docs/gtk4/subclass/widget/struct.TemplateChild.html) then stores a reference to the widget for later use.
89
+
[`TemplateChild`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/subclass/widget/struct.TemplateChild.html) then stores a reference to the widget for later use.
90
90
This will be useful later, when we want to add a callback to our button.
Then we define the `handle_button_clicked` with the [`template_callbacks`](../docs/gtk4_macros/attr.template_callbacks.html) macro applied to it.
157
+
Then we define the `handle_button_clicked` with the [`template_callbacks`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4_macros/attr.template_callbacks.html) macro applied to it.
158
158
We can determine the function signature by having a look at the `connect_*` method of the signal we want to handle.
159
-
In our case that would be [`connect_clicked`](../docs/gtk4/prelude/trait.ButtonExt.html#tymethod.connect_clicked).
159
+
In our case that would be [`connect_clicked`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.ButtonExt.html#tymethod.connect_clicked).
160
160
It takes a function of type `Fn(&Self)`.
161
161
`Self` refers to our button.
162
162
This means that `handle_button_clicked` has a single parameter of type `&CustomButton`.
Then we have to bind the template callbacks with [`bind_template_callbacks`](../docs/gtk4/subclass/widget/trait.CompositeTemplateCallbacksClass.html#tymethod.bind_template_callbacks).
169
+
Then we have to bind the template callbacks with [`bind_template_callbacks`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/subclass/widget/trait.CompositeTemplateCallbacksClass.html#tymethod.bind_template_callbacks).
170
170
We also need to remove the `button.connect_clicked` callback implemented in `window/imp.rs`.
@@ -240,7 +240,7 @@ Thanks to composite templates we can
240
240
- specify handler functions for signals.
241
241
242
242
The API involved here is extensive so especially at the beginning you will want to check out the documentation.
243
-
The basic syntax of the `ui` files is explained within [`Builder`](../docs/gtk4/struct.Builder.html#gtkbuilder-ui-definitions), syntax specific to widgets within [`Widget`](../docs/gtk4/struct.Widget.html#gtkwidget-as-gtkbuildable).
243
+
The basic syntax of the `ui` files is explained within [`Builder`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Builder.html#gtkbuilder-ui-definitions), syntax specific to widgets within [`Widget`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Widget.html#gtkwidget-as-gtkbuildable).
244
244
If a certain widget accepts additional element, then they are typically explained in the docs of the widget.
245
245
246
246
In the following chapter, we will see how composite templates help us to create slightly bigger apps such as a To-Do app.
Copy file name to clipboardExpand all lines: book/src/css.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ We did not specify for which button the rule should apply, so it was applied to
47
47
48
48
[Class selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors) are one way to choose which specific elements a CSS rule applies to.
49
49
GTK adds style classes to many of its widgets, often depending on their content.
50
-
A [`gtk::Button`](../docs/gtk4/struct.Button.html#css-nodes), for example, will get the `text-button` style class when its content is alabel.
50
+
A [`gtk::Button`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Button.html#css-nodes), for example, will get the `text-button` style class when its content is alabel.
51
51
That is why we create a new CSS rule which only applies to `button` nodes with the style class `text_button`.
52
52
53
53
@@ -63,7 +63,7 @@ Now only the font of our button becomes magenta.
63
63
64
64
## Adding Your Own Style Class
65
65
66
-
With [`add_css_class`](../docs/gtk4/prelude/trait.WidgetExt.html#tymethod.add_css_class) we can also add our own style classes to widgets.
66
+
With [`add_css_class`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.WidgetExt.html#tymethod.add_css_class) we can also add our own style classes to widgets.
67
67
One use-case for this is when you want a rule to apply to a hand-picked set of widgets.
68
68
For example if we have two buttons, but want only one of them to have magenta font.
69
69
Relying on one of the style classes which GTK adds will not help since both will get the same ones.
@@ -96,7 +96,7 @@ Ideally however, you would give the widget a name and match with that name inste
96
96
This way your intentions are more clear, compared to matching with style classes that can apply to multiple widgets.
97
97
98
98
Again, we have two buttons but want to color only one of them magenta.
99
-
We set the name of the first one with [`set_widget_name`](../docs/gtk4/prelude/trait.WidgetExt.html#tymethod.set_widget_name).
99
+
We set the name of the first one with [`set_widget_name`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.WidgetExt.html#tymethod.set_widget_name).
@@ -123,7 +123,7 @@ Again, the style rule only applies to the first button.
123
123
Certain styles are common enough that GTK provides CSS rules for them.
124
124
For example, if you want to indicate that your button leads to a destructive or suggested action you don't have to provide your own CSS rules.
125
125
All you have to do is to add "destructive-action" or "suggested-action" style class to your button.
126
-
Most widgets will document these rules in their documentation under [CSS nodes](../docs/gtk4/struct.Button.html#css-nodes).
126
+
Most widgets will document these rules in their documentation under [CSS nodes](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Button.html#css-nodes).
We can also add style classes with the interface builder.
139
139
Just add the `<style>` element to your widget.
140
-
The `<style>` element is documented together with [`gtk::Widget`](../docs/gtk4/struct.Widget.html#gtkwidget-as-gtkbuildable).
140
+
The `<style>` element is documented together with [`gtk::Widget`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Widget.html#gtkwidget-as-gtkbuildable).
141
141
Adding again destructive and suggested buttons, would then look like this:
You can make a `MenuButton` show an icon or a label.
196
196
If you choose to do neither of those, as we currently do, it shows an image displaying an arrow.
197
197
198
-
An inheritance tree of [CSS nodes](../docs/gtk4/struct.MenuButton.html#css-nodes) displays this situation:
198
+
An inheritance tree of [CSS nodes](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.MenuButton.html#css-nodes) displays this situation:
199
199
200
200
```
201
201
menubutton
@@ -227,7 +227,7 @@ Let's see how to deal with this situation by messing with our To-Do app once mor
227
227
The class `TaskRow` inherits from `gtk::Box`, so we could just match for the node `box`.
228
228
However, in that case we would also match with other instance of `gtk::Box`.
229
229
What we will want to do instead is to give `TaskRow` its own CSS name.
230
-
When calling [`set_css_name`](../docs/gtk4/subclass/widget/trait.WidgetClassSubclassExt.html#method.set_css_name), we change the name of the CSS node of the widget class.
230
+
When calling [`set_css_name`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/subclass/widget/trait.WidgetClassExt.html#method.set_css_name), we change the name of the CSS node of the widget class.
231
231
In our case, the widget `TaskRow` then corresponds to the node `task-row`.
Copy file name to clipboardExpand all lines: book/src/g_object_properties.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@
3
3
Properties provide a public API for accessing state of GObjects.
4
4
5
5
Let's see how this is done by experimenting with the [`Switch`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Switch.html) widget.
6
-
One of its properties is called [active](../docs/gtk4/struct.Switch.html#active).
6
+
One of its properties is called [active](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Switch.html#active).
7
7
According to the GTK docs, it can be read and be written to.
8
-
That is why `gtk-rs` provides corresponding [`is_active`](../docs/gtk4/struct.Switch.html#method.is_active) and [`set_active`](../docs/gtk4/struct.Switch.html#method.set_active) methods.
8
+
That is why `gtk-rs` provides corresponding [`is_active`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Switch.html#method.is_active) and [`set_active`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Switch.html#method.set_active) methods.
Copy file name to clipboardExpand all lines: book/src/g_object_signals.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ For example, if we press on a button, the "clicked" signal will be emitted.
5
5
The signal then takes care that all the registered callbacks will be executed.
6
6
7
7
`gtk-rs` provides convenience methods for registering callbacks.
8
-
In our "Hello World" example we [connected](../docs/gtk4/prelude/trait.ButtonExt.html#tymethod.connect_clicked) the "clicked" signal to a closure which sets the label of the button to "Hello World" as soon as it gets called.
8
+
In our "Hello World" example we [connected](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.ButtonExt.html#tymethod.connect_clicked) the "clicked" signal to a closure which sets the label of the button to "Hello World" as soon as it gets called.
Copy file name to clipboardExpand all lines: book/src/hello_world.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Now that we've got a working installation, let's get right into it!
4
4
5
-
At the very least, we need to create a [`gtk::Application`](../docs/gtk4/struct.Application.html) instance with an [application id](https://developer.gnome.org/documentation/tutorials/application-id.html).
5
+
At the very least, we need to create a [`gtk::Application`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Application.html) instance with an [application id](https://developer.gnome.org/documentation/tutorials/application-id.html).
6
6
For that we use the [builder pattern](https://rust-unofficial.github.io/patterns/patterns/creational/builder.html) which many `gtk-rs` objects support.
7
7
Note that we also import the prelude to bring the necessary traits into scope.
8
8
@@ -20,7 +20,7 @@ and has no handlers connected to the 'activate' signal. It should do one of thes
20
20
```
21
21
22
22
GTK tells us that something should be called in its `activate` step.
23
-
So let's create a [`gtk::ApplicationWindow`](../docs/gtk4/struct.ApplicationWindow.html) there.
23
+
So let's create a [`gtk::ApplicationWindow`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.ApplicationWindow.html) there.
0 commit comments